Class: RSpec::Core::Formatters::BaseFormatter
- Inherits:
-
Object
- Object
- RSpec::Core::Formatters::BaseFormatter
- Includes:
- Helpers
- Defined in:
- lib/rspec/legacy_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
Constants included from Helpers
Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION
Instance Attribute Summary collapse
-
#duration ⇒ void
readonly
Returns the value of attribute duration.
-
#example_count ⇒ void
readonly
Returns the value of attribute example_count.
-
#example_group ⇒ void
Returns the value of attribute example_group.
-
#examples ⇒ void
readonly
Returns the value of attribute examples.
-
#failed_examples ⇒ void
readonly
Returns the value of attribute failed_examples.
-
#failure_count ⇒ void
readonly
Returns the value of attribute failure_count.
-
#output ⇒ void
readonly
Returns the value of attribute output.
-
#pending_count ⇒ void
readonly
Returns the value of attribute pending_count.
-
#pending_examples ⇒ void
readonly
Returns the value of attribute pending_examples.
Instance Method Summary collapse
-
#close ⇒ void
Invoked at the very end,
close
allows the formatter to clean up resources, e.g. -
#dump_failures ⇒ nil
Dumps detailed information about each example failure.
-
#dump_pending ⇒ nil
Outputs a report of pending examples.
-
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ void
This method is invoked after the dumping of examples and failures.
-
#example_failed(example) ⇒ Array
Invoked when an example fails.
-
#example_group_finished(example_group) ⇒ void
Invoked at the end of the execution of each example group.
-
#example_group_started(example_group) ⇒ void
This method is invoked at the beginning of the execution of each example group.
-
#example_passed(example) ⇒ void
Invoked when an example passes.
-
#example_pending(example) ⇒ Array
Invoked when an example is pending.
-
#example_started(example) ⇒ Array
Invoked at the beginning of the execution of each example.
-
#format_backtrace(backtrace, example) ⇒ void
Formats the given backtrace based on configuration and the metadata of the given example.
-
#initialize(output) ⇒ BaseFormatter
constructor
A new instance of BaseFormatter.
-
#message(message) ⇒ void
Used by the reporter to send messages to the output stream.
-
#start(example_count) ⇒ void
This method is invoked before any examples are run, right after they have all been collected.
-
#start_dump ⇒ nil
This method is invoked after all of the examples have executed.
-
#stop ⇒ nil
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
#initialize(output) ⇒ BaseFormatter
Returns a new instance of BaseFormatter.
25 26 27 28 29 30 31 32 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 25 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
#duration ⇒ void (readonly)
Returns the value of attribute duration.
18 19 20 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 18 def duration @duration end |
#example_count ⇒ void (readonly)
Returns the value of attribute example_count.
19 20 21 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 19 def example_count @example_count end |
#example_group ⇒ void
Returns the value of attribute example_group.
17 18 19 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 17 def example_group @example_group end |
#examples ⇒ void (readonly)
Returns the value of attribute examples.
18 19 20 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 18 def examples @examples end |
#failed_examples ⇒ void (readonly)
Returns the value of attribute failed_examples.
20 21 22 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 20 def failed_examples @failed_examples end |
#failure_count ⇒ void (readonly)
Returns the value of attribute failure_count.
19 20 21 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 19 def failure_count @failure_count end |
#output ⇒ void (readonly)
Returns the value of attribute output.
18 19 20 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 18 def output @output end |
#pending_count ⇒ void (readonly)
Returns the value of attribute pending_count.
19 20 21 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 19 def pending_count @pending_count end |
#pending_examples ⇒ void (readonly)
Returns the value of attribute pending_examples.
20 21 22 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 20 def pending_examples @pending_examples end |
Instance Method Details
#close ⇒ void
Invoked at the very end, close
allows the formatter to clean
up resources, e.g. open streams, etc.
174 175 176 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 174 def close restore_sync_output end |
#dump_failures ⇒ nil
Dumps detailed information about each example failure.
138 139 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 138 def dump_failures end |
#dump_pending ⇒ nil
Outputs a report of pending examples. This gets invoked after the summary if option is set to do so.
163 164 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 163 def dump_pending end |
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ void
This method is invoked after the dumping of examples and failures. Each parameter is assigned to a corresponding attribute.
150 151 152 153 154 155 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 150 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 |
#example_failed(example) ⇒ Array
Invoked when an example fails.
103 104 105 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 103 def example_failed(example) @failed_examples << example end |
#example_group_finished(example_group) ⇒ void
Invoked at the end of the execution of each example group.
68 69 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 68 def example_group_finished(example_group) end |
#example_group_started(example_group) ⇒ void
This method is invoked at the beginning of the execution of each example group.
The next method to be invoked after this is #example_passed, #example_pending, or #example_group_finished.
59 60 61 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 59 def example_group_started(example_group) @example_group = example_group end |
#example_passed(example) ⇒ void
Invoked when an example passes.
86 87 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 86 def example_passed(example) end |
#example_pending(example) ⇒ Array
Invoked when an example is pending.
93 94 95 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 93 def example_pending(example) @pending_examples << example end |
#example_started(example) ⇒ Array
Invoked at the beginning of the execution of each example.
77 78 79 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 77 def example_started(example) examples << example end |
#format_backtrace(backtrace, example) ⇒ void
Formats the given backtrace based on configuration and the metadata of the given example.
182 183 184 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 182 def format_backtrace(backtrace, example) super(backtrace, example.) end |
#message(message) ⇒ void
Used by the reporter to send messages to the output stream.
112 113 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 112 def () end |
#start(example_count) ⇒ void
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_group_started.
44 45 46 47 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 44 def start(example_count) start_sync_output @example_count = example_count end |
#start_dump ⇒ nil
This method is invoked after all of the examples have executed. The next method to be invoked after this one is #dump_failures (BaseTextFormatter then calls #dump_failure once for each failed example.)
130 131 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 130 def start_dump end |
#stop ⇒ nil
Invoked after all examples have executed, before dumping post-run reports.
120 121 |
# File 'lib/rspec/legacy_formatters/base_formatter.rb', line 120 def stop end |