Class: Spec::Runner::Formatter::BaseTextFormatter
- Defined in:
- lib/spec/runner/formatter/base_text_formatter.rb
Overview
Baseclass for text-based formatters. Can in fact be used for non-text based ones too - just ignore the output
constructor argument.
Direct Known Subclasses
HtmlFormatter, ProgressBarFormatter, RdocFormatter, SpecdocFormatter
Instance Method Summary collapse
-
#add_context(name, first) ⇒ Object
This method is invoked at the beginning of the execution of each context.
-
#dump_failure(counter, failure) ⇒ Object
Dumps detailed information about a spec failure.
-
#dump_summary(duration, spec_count, failure_count) ⇒ Object
This method is invoked at the very end.
-
#initialize(output, dry_run = false) ⇒ BaseTextFormatter
constructor
A new instance of BaseTextFormatter.
-
#spec_failed(name, counter, failure) ⇒ Object
This method is invoked when a spec fails, i.e.
-
#spec_passed(name) ⇒ Object
This method is invoked when a spec passes.
-
#spec_started(name) ⇒ Object
This method is invoked right before a spec is executed.
-
#start(spec_count) ⇒ Object
This method is invoked before any specs are run, right after they have all been collected.
-
#start_dump ⇒ Object
This method is invoked after all of the specs have executed.
Constructor Details
#initialize(output, dry_run = false) ⇒ BaseTextFormatter
Returns a new instance of BaseTextFormatter.
8 9 10 11 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 8 def initialize(output, dry_run=false) @dry_run = dry_run @output = output end |
Instance Method Details
#add_context(name, first) ⇒ Object
This method is invoked at the beginning of the execution of each context. name
is the name of the context and first
is true if it is the first context - otherwise it’s false.
The next method to be invoked after this is #spec_started
27 28 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 27 def add_context(name, first) end |
#dump_failure(counter, failure) ⇒ Object
Dumps detailed information about a spec failure. This method is invoked for each failed spec after all specs have run. counter
is the sequence number of the associated spec. failure
is a Failure object, which contains detailed information about the failure.
57 58 59 60 61 62 63 64 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 57 def dump_failure(counter, failure) @output << "\n" @output << counter.to_s << ")\n" @output << "#{failure.header}\n" @output << "#{failure.}\n" @output << "#{failure.backtrace}\n" @output.flush end |
#dump_summary(duration, spec_count, failure_count) ⇒ Object
This method is invoked at the very end.
67 68 69 70 71 72 73 74 75 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 67 def dump_summary(duration, spec_count, failure_count) return if @dry_run @output << "\n" @output << "Finished in " << (duration).to_s << " seconds\n\n" @output << "#{spec_count} specification#{'s' unless spec_count == 1}, " @output << "#{failure_count} failure#{'s' unless failure_count == 1}" @output << "\n" @output.flush end |
#spec_failed(name, counter, failure) ⇒ Object
This method is invoked when a spec fails, i.e. an exception occurred inside it (such as a failed should or other exception). name
is the name of the specification. counter
is the sequence number of the failure (starting at 1) and failure
is the associated Failure object.
40 41 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 40 def spec_failed(name, counter, failure) end |
#spec_passed(name) ⇒ Object
This method is invoked when a spec passes. name
is the name of the specification.
45 46 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 45 def spec_passed(name) end |
#spec_started(name) ⇒ Object
This method is invoked right before a spec is executed. The next method to be invoked after this one is one of #spec_failed or #spec_passed.
33 34 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 33 def spec_started(name) end |
#start(spec_count) ⇒ Object
This method is invoked before any specs 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 method will only be invoked once, and the next one to be invoked is #add_context
19 20 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 19 def start(spec_count) end |
#start_dump ⇒ Object
This method is invoked after all of the specs have executed. The next method to be invoked after this one is #dump_failure (once for each failed spec),
50 51 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 50 def start_dump end |