Class: RSpec::Core::Formatters::BaseFormatter
- Inherits:
-
Object
- Object
- RSpec::Core::Formatters::BaseFormatter
- Includes:
- Helpers
- Defined in:
- lib/rspec/core/formatters/base_formatter.rb
Direct Known Subclasses
Constant Summary
Constants included from Helpers
Helpers::DEFAULT_PRECISION, Helpers::SUB_SECOND_PRECISION
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#example_count ⇒ Object
readonly
Returns the value of attribute example_count.
-
#example_group ⇒ Object
Returns the value of attribute example_group.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#failed_examples ⇒ Object
readonly
Returns the value of attribute failed_examples.
-
#failure_count ⇒ Object
readonly
Returns the value of attribute failure_count.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#pending_count ⇒ Object
readonly
Returns the value of attribute pending_count.
-
#pending_examples ⇒ Object
readonly
Returns the value of attribute pending_examples.
Instance Method Summary collapse
-
#close ⇒ Object
This method is invoked at the very end.
-
#dump_failures ⇒ Object
Dumps detailed information about each example failure.
-
#dump_pending ⇒ Object
This gets invoked after the summary if option is set to do so.
-
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
This method is invoked after the dumping of examples and failures.
- #example_failed(example) ⇒ Object
-
#example_group_finished(example_group) ⇒ Object
This method is invoked at the end of the execution of each example group.
-
#example_group_started(example_group) ⇒ Object
This method is invoked at the beginning of the execution of each example group.
- #example_passed(example) ⇒ Object
- #example_pending(example) ⇒ Object
- #example_started(example) ⇒ Object
- #format_backtrace(backtrace, example) ⇒ Object
-
#initialize(output) ⇒ BaseFormatter
constructor
A new instance of BaseFormatter.
- #message(message) ⇒ Object
- #seed(number) ⇒ Object
-
#start(example_count) ⇒ Object
This method is invoked before any examples are run, right after they have all been collected.
-
#start_dump ⇒ Object
This method is invoked after all of the examples have executed.
- #stop ⇒ Object
Methods included from Helpers
#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes
Constructor Details
#initialize(output) ⇒ BaseFormatter
Returns a new instance of BaseFormatter.
15 16 17 18 19 20 21 22 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 15 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 ⇒ Object (readonly)
Returns the value of attribute duration.
11 12 13 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 11 def duration @duration end |
#example_count ⇒ Object (readonly)
Returns the value of attribute example_count.
12 13 14 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 12 def example_count @example_count end |
#example_group ⇒ Object
Returns the value of attribute example_group.
10 11 12 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 10 def example_group @example_group end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
11 12 13 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 11 def examples @examples end |
#failed_examples ⇒ Object (readonly)
Returns the value of attribute failed_examples.
13 14 15 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 13 def failed_examples @failed_examples end |
#failure_count ⇒ Object (readonly)
Returns the value of attribute failure_count.
12 13 14 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 12 def failure_count @failure_count end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
11 12 13 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 11 def output @output end |
#pending_count ⇒ Object (readonly)
Returns the value of attribute pending_count.
12 13 14 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 12 def pending_count @pending_count end |
#pending_examples ⇒ Object (readonly)
Returns the value of attribute pending_examples.
13 14 15 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 13 def pending_examples @pending_examples end |
Instance Method Details
#close ⇒ Object
This method is invoked at the very end. Allows the formatter to clean up, like closing open streams.
95 96 97 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 95 def close restore_sync_output end |
#dump_failures ⇒ Object
Dumps detailed information about each example failure.
76 77 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 76 def dump_failures end |
#dump_pending ⇒ Object
This gets invoked after the summary if option is set to do so.
88 89 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 88 def dump_pending end |
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
This method is invoked after the dumping of examples and failures.
80 81 82 83 84 85 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 80 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) ⇒ Object
60 61 62 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 60 def example_failed(example) @failed_examples << example end |
#example_group_finished(example_group) ⇒ Object
This method is invoked at the end of the execution of each example group. +example_group+ is the example_group.
46 47 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 46 def example_group_finished(example_group) end |
#example_group_started(example_group) ⇒ Object
This method is invoked at the beginning of the execution of each example group. +example_group+ is the example_group.
The next method to be invoked after this is +example_passed+, +example_pending+, or +example_finished+
40 41 42 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 40 def example_group_started(example_group) @example_group = example_group end |
#example_passed(example) ⇒ Object
53 54 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 53 def example_passed(example) end |
#example_pending(example) ⇒ Object
56 57 58 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 56 def example_pending(example) @pending_examples << example end |
#example_started(example) ⇒ Object
49 50 51 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 49 def example_started(example) examples << example end |
#format_backtrace(backtrace, example) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 99 def format_backtrace(backtrace, example) return "" unless backtrace return backtrace if example.[:full_backtrace] == true if at_exit_index = backtrace.index(RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE) backtrace = backtrace[0, at_exit_index] end cleansed = backtrace.map { |line| backtrace_line(line) }.compact cleansed.empty? ? backtrace : cleansed end |
#message(message) ⇒ Object
64 65 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 64 def () end |
#seed(number) ⇒ Object
91 92 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 91 def seed(number) end |
#start(example_count) ⇒ Object
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
30 31 32 33 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 30 def start(example_count) start_sync_output @example_count = example_count end |
#start_dump ⇒ Object
This method is invoked after all of the examples have executed. The next method to be invoked after this one is #dump_failure (once for each failed example),
72 73 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 72 def start_dump end |
#stop ⇒ Object
67 68 |
# File 'lib/rspec/core/formatters/base_formatter.rb', line 67 def stop end |