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.
- #format_backtrace(backtrace) ⇒ Object
-
#initialize(output, dry_run = false, colour = 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, colour = false) ⇒ BaseTextFormatter
Returns a new instance of BaseTextFormatter.
8 9 10 11 12 13 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 8 def initialize(output, dry_run=false, colour=false) @output = output @dry_run = dry_run @colour = colour begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ ; rescue LoadError ; raise "You must gem install win32console to use colour on Windows" ; end 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
29 30 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 29 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 59 def dump_failure(counter, failure) @output.puts @output.puts "#{counter.to_s})" if(failure.expectation_not_met?) @output.puts red(failure.header) @output.puts red(failure.exception.) else @output.puts magenta(failure.header) @output.puts magenta(failure.exception.) end @output.puts format_backtrace(failure.exception.backtrace) STDOUT.flush end |
#dump_summary(duration, spec_count, failure_count) ⇒ Object
This method is invoked at the very end.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 74 def dump_summary(duration, spec_count, failure_count) return if @dry_run @output.puts @output.puts "Finished in #{duration} seconds" @output.puts summary = "#{spec_count} specification#{'s' unless spec_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}" if failure_count == 0 @output.puts green(summary) else @output.puts red(summary) end end |
#format_backtrace(backtrace) ⇒ Object
87 88 89 90 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 87 def format_backtrace(backtrace) return "" if backtrace.nil? backtrace.map { |line| backtrace_line(line) }.join("\n") 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.
42 43 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 42 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.
47 48 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 47 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.
35 36 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 35 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
21 22 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 21 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),
52 53 |
# File 'lib/spec/runner/formatter/base_text_formatter.rb', line 52 def start_dump end |