Class: RSpec::Core::Formatters::BaseFormatter
- Inherits:
-
Object
- Object
- RSpec::Core::Formatters::BaseFormatter
- Includes:
- Helpers
- Defined in:
- lib/rspec/core/formatters/base_formatter.rb
Overview
RSpec's built-in formatters are all subclasses of RSpec::Core::Formatters::BaseTextFormatter, but the BaseTextFormatter documents all of the methods needed to be implemented by a formatter, as they are called from the reporter.
Direct Known Subclasses
Constant Summary
Constant Summary
Constants included from Helpers
Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION
Instance Attribute Summary (collapse)
-
- (Object) duration
readonly
Returns the value of attribute duration.
-
- (Object) example_count
readonly
Returns the value of attribute example_count.
-
- (Object) example_group
Returns the value of attribute example_group.
-
- (Object) examples
readonly
Returns the value of attribute examples.
-
- (Object) failed_examples
readonly
Returns the value of attribute failed_examples.
-
- (Object) failure_count
readonly
Returns the value of attribute failure_count.
-
- (Object) output
readonly
Returns the value of attribute output.
-
- (Object) pending_count
readonly
Returns the value of attribute pending_count.
-
- (Object) pending_examples
readonly
Returns the value of attribute pending_examples.
Instance Method Summary (collapse)
-
- (Object) close
Invoked at the very end,
close
allows the formatter to clean up resources, e.g. -
- (nil) dump_failures
Dumps detailed information about each example failure.
-
- (nil) dump_pending
Outputs a report of pending examples.
-
- (Object) dump_summary(duration, example_count, failure_count, pending_count)
This method is invoked after the dumping of examples and failures.
-
- (Array) example_failed(example)
Invoked when an example fails.
-
- (Object) example_group_finished(example_group)
Invoked at the end of the execution of each example group.
-
- (Object) example_group_started(example_group)
This method is invoked at the beginning of the execution of each example group.
-
- (Object) example_passed(example)
Invoked when an example passes.
-
- (Array) example_pending(example)
Invoked when an example is pending.
-
- (Array) example_started(example)
Invoked at the beginning of the execution of each example.
-
- (Object) format_backtrace(backtrace, example)
Formats the given backtrace based on configuration and the metadata of the given example.
-
- (BaseFormatter) initialize(output)
constructor
A new instance of BaseFormatter.
-
- (Object) message(message)
Used by the reporter to send messages to the output stream.
-
- (Object) start(example_count)
This method is invoked before any examples are run, right after they have all been collected.
-
- (nil) start_dump
This method is invoked after all of the examples have executed.
-
- (nil) stop
Invoked after all examples have executed, before dumping post-run reports.
Methods included from Helpers
#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes
Constructor Details
- (BaseFormatter) initialize(output)
A new instance of BaseFormatter
23 24 25 26 27 28 29 30 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 23 def initialize(output) @output = output || StringIO.new @example_count = @pending_count = @failure_count = 0 @examples = [] @failed_examples = [] @pending_examples = [] @example_group = nil end |
Instance Attribute Details
- (Object) duration (readonly)
Returns the value of attribute duration
16 17 18 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 16 def duration @duration end |
- (Object) example_count (readonly)
Returns the value of attribute example_count
17 18 19 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 17 def example_count @example_count end |
- (Object) example_group
Returns the value of attribute example_group
15 16 17 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 15 def example_group @example_group end |
- (Object) examples (readonly)
Returns the value of attribute examples
16 17 18 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 16 def examples @examples end |
- (Object) failed_examples (readonly)
Returns the value of attribute failed_examples
18 19 20 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 18 def failed_examples @failed_examples end |
- (Object) failure_count (readonly)
Returns the value of attribute failure_count
17 18 19 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 17 def failure_count @failure_count end |
- (Object) output (readonly)
Returns the value of attribute output
16 17 18 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 16 def output @output end |
- (Object) pending_count (readonly)
Returns the value of attribute pending_count
17 18 19 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 17 def pending_count @pending_count end |
- (Object) pending_examples (readonly)
Returns the value of attribute pending_examples
18 19 20 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 18 def pending_examples @pending_examples end |
Instance Method Details
- (Object) close
Invoked at the very end, close
allows the formatter to clean
up resources, e.g. open streams, etc.
172 173 174 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 172 def close restore_sync_output end |
- (nil) dump_failures
Dumps detailed information about each example failure.
136 137 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 136 def dump_failures end |
- (nil) dump_pending
Outputs a report of pending examples. This gets invoked after the summary if option is set to do so.
161 162 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 161 def dump_pending end |
- (Object) dump_summary(duration, example_count, failure_count, pending_count)
This method is invoked after the dumping of examples and failures. Each parameter is assigned to a corresponding attribute.
148 149 150 151 152 153 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 148 def dump_summary(duration, example_count, failure_count, pending_count) @duration = duration @example_count = example_count @failure_count = failure_count @pending_count = pending_count end |
- (Array) example_failed(example)
Invoked when an example fails.
101 102 103 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 101 def example_failed(example) @failed_examples << example end |
- (Object) example_group_finished(example_group)
Invoked at the end of the execution of each example group.
66 67 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 66 def example_group_finished(example_group) end |
- (Object) example_group_started(example_group)
This method is invoked at the beginning of the execution of each example group.
The next method to be invoked after this is #example<em>passed, #example</em>pending, or #example<em>group</em>finished.
57 58 59 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 57 def example_group_started(example_group) @example_group = example_group end |
- (Object) example_passed(example)
Invoked when an example passes.
84 85 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 84 def example_passed(example) end |
- (Array) example_pending(example)
Invoked when an example is pending.
91 92 93 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 91 def example_pending(example) @pending_examples << example end |
- (Array) example_started(example)
Invoked at the beginning of the execution of each example.
75 76 77 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 75 def example_started(example) examples << example end |
- (Object) format_backtrace(backtrace, example)
Formats the given backtrace based on configuration and the metadata of the given example.
180 181 182 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 180 def format_backtrace(backtrace, example) super(backtrace, example.) end |
- (Object) message(message)
Used by the reporter to send messages to the output stream.
110 111 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 110 def () end |
- (Object) start(example_count)
This method is invoked before any examples are run, right after they have all been collected. This can be useful for special formatters that need to provide progress on feedback (graphical ones).
This will only be invoked once, and the next one to be invoked is #example<em>group</em>started.
42 43 44 45 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 42 def start(example_count) start_sync_output @example_count = example_count end |
- (nil) start_dump
This method is invoked after all of the examples have executed. The next method to be invoked after this one is #dump<em>failures (BaseTextFormatter then calls #dump</em>failure once for each failed example.)
128 129 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 128 def start_dump end |
- (nil) stop
Invoked after all examples have executed, before dumping post-run reports.
118 119 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 118 def stop end |