Class: Ruber::RSpec::BaseFormatter
- Inherits:
-
Object
- Object
- Ruber::RSpec::BaseFormatter
- Defined in:
- plugins/rspec/ruber_rspec_formatter.rb
Overview
RSpec formatter used by the rspec plugin
It writes data as YAML-formatted hashes. The data relative to a single example, as well as the preamble and the summary, are separated from each other with special strings, stored in the STARTING_DELIMITER and ENDING_DELIMITER constants. This is made to avoid problems in case buffering breaks a string containing one of these strings in pieces.
Among keys specific to each of them, all the hashes contain the :type
key, which
tells which kind of information the hash contains.
$$$$%%%%$$$$KRUBY_BEGIN
and
$$$$%%%%$$$$KRUBY_END
The output is flushed after every writing
This is a base class used by both Version1Formatter and Version2Formatter which
defines all the methods which haven’t changed in from RSpec 1 to RSpec 2. In particular,
it doesn’t contain the example_failed
and example_pending
methods as their
signature has changed from one version to the ohter.
Direct Known Subclasses
Constant Summary
- STARTING_DELIMITER =
TODO:
(after first alpha) Change it to include the string
KRUBY
withRUBER
inside itThe starting delimiter used by the formatter
'####%%%%####KRUBY_BEGIN'
- ENDING_DELIMITER =
TODO:
(after first alpha) Change it to include the string
KRUBY
withRUBER
inside itThe ending delimiter used by the formatter
'####%%%%####KRUBY_END'
Instance Method Summary (collapse)
-
- (nil) dump_failure(counter, fail)
Override of
Spec::Runner::Formatter::BaseTextFormatter#dump_failure
which does nothing. - - (Object) dump_failures
-
- (nil) dump_pending
Override of
Spec::Runner::Formatter::BaseTextFormatter#dump_pending
which does nothing. -
- (nil) dump_summary(time, total, failure, pending)
Method called by RSpec after running all the examples.
-
- (nil) example_passed(ex)
Method called by RSpec after an example has been completed successfully.
-
- (nil) example_started(ex)
Method called by RSpec after starting an example.
-
- (nil) start(count)
Method called by RSpec after the examples have been collected.
-
- (nil) write_data(hash)
private
Writes data to the output stream.
Instance Method Details
- (nil) dump_failure(counter, fail)
Override of Spec::Runner::Formatter::BaseTextFormatter#dump_failure
which does nothing
131 132 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 131 def dump_failure counter, fail end |
- (Object) dump_failures
166 167 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 166 def dump_failures end |
- (nil) dump_pending
Override of Spec::Runner::Formatter::BaseTextFormatter#dump_pending
which does nothing
139 140 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 139 def dump_pending end |
- (nil) dump_summary(time, total, failure, pending)
Method called by RSpec after running all the examples
It writes a summary containing the number of run, failed, passed an pending examples
to the output as a YAML dumnp of a hash. The hash has the following entries:
The hash contains the following entries (the keys are all symbols)
:type
: :summary
total
: the number of run examples
failure
: the number of failed examples
pending
: the number of pending examples
passed
: the number of passed examples
155 156 157 158 159 160 161 162 163 164 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 155 def dump_summary time, total, failure, pending hash = { :type => :summary, :total => total, :failure => failure, :pending => pending, :passed => total - (failure + pending) } write_data hash end |
- (nil) example_passed(ex)
Method called by RSpec after an example has been completed successfully
It writes to the output a YAML dump of a hash with the following entries:
:type
::success
:description
: the name of the passed example, made of the name of the example group and the description of the example itself
119 120 121 122 123 124 125 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 119 def example_passed ex super hash = {} hash[:type] = :success hash[:description] = "#{example_group.description} #{ex.description}" write_data hash end |
- (nil) example_started(ex)
Method called by RSpec after starting an example
It writes to the output a YAML dump of a hash with the following entries:
:type
::new_example
:description
: the name of the example, made of the name of the example group and the description of the example itself
101 102 103 104 105 106 107 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 101 def example_started ex super hash = {} hash[:type] = :new_example hash[:description] = "#{example_group.description} #{ex.description}" write_data hash end |
- (nil) start(count)
Method called by RSpec after the examples have been collected
It writes to the output a YAML dump of a hash with the following entries:
:type
::start
:count
: the number of examples found by RSpec
85 86 87 88 89 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 85 def start count super hash = {:type => :start, :count => count} write_data hash end |
- (nil) write_data(hash) (private)
Writes data to the output stream
The data is passed in hashes and is written as a YAML dump between a starting and an end delimiter. The output stream is flueshed both before and after writing, so that the data is written alone on the string
181 182 183 184 185 186 187 188 189 190 191 |
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 181 def write_data hash # STDERR.puts hash.inspect @output.flush str = "#{STARTING_DELIMITER}\n#{YAML.dump(hash)}\n#{ENDING_DELIMITER}" @output.puts str # @output.puts STARTING_DELIMITER # @output.puts YAML.dump(hash) # @output.puts ENDING_DELIMITER @output.flush nil end |