Class Spec::Runner::Formatter::BaseTextFormatter
In: lib/spec/runner/formatter/base_text_formatter.rb
Parent: Object

Baseclass for text-based formatters. Can in fact be used for non-text based ones too - just ignore the output constructor argument.

Methods

Public Class methods

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 8
 8:         def initialize(output, dry_run=false, colour=false)
 9:           @output = output
10:           @dry_run = dry_run
11:           @colour = colour
12:           begin ; require 'Win32/Console/ANSI' if @colour && PLATFORM =~ /win32/ ; rescue LoadError ; raise "You must gem install win32console to use colour on Windows" ; end
13:               end

Public Instance methods

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

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 29
29:         def add_context(name, first)
30:         end

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.

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 59
59:         def dump_failure(counter, failure)
60:           @output.puts
61:           @output.puts "#{counter.to_s})"
62:           if(failure.expectation_not_met?)
63:             @output.puts red(failure.header)
64:             @output.puts red(failure.exception.message)
65:           else
66:             @output.puts magenta(failure.header)
67:             @output.puts magenta(failure.exception.message)
68:           end
69:           @output.puts format_backtrace(failure.exception.backtrace)
70:           STDOUT.flush
71:         end

This method is invoked at the very end.

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 74
74:         def dump_summary(duration, spec_count, failure_count)
75:           return if @dry_run
76:           @output.puts
77:           @output.puts "Finished in #{duration} seconds"
78:           @output.puts
79:           summary = "#{spec_count} specification#{'s' unless spec_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
80:           if failure_count == 0
81:             @output.puts green(summary)
82:           else
83:             @output.puts red(summary)
84:           end
85:         end

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 87
87:         def format_backtrace(backtrace)
88:           return "" if backtrace.nil?
89:           backtrace.map { |line| backtrace_line(line) }.join("\n")
90:         end

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.

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 42
42:         def spec_failed(name, counter, failure)
43:         end

This method is invoked when a spec passes. name is the name of the specification.

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 47
47:         def spec_passed(name)
48:         end

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.

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 35
35:         def spec_started(name)
36:         end

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

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 21
21:         def start(spec_count)
22:         end

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),

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 52
52:         def start_dump
53:         end

Protected Instance methods

[Source]

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 94
94:         def backtrace_line(line)
95:           line.sub(/\A([^:]+:\d+)$/, '\\1:')
96:         end

[Source]

     # File lib/spec/runner/formatter/base_text_formatter.rb, line 98
 98:         def colour(text, colour_code)
 99:           return text unless @colour && @output == Kernel
100:           "#{colour_code}#{text}\e[0m"
101:         end

[Source]

     # File lib/spec/runner/formatter/base_text_formatter.rb, line 104
104:         def green(text); colour(text, "\e[32m"); end

[Source]

     # File lib/spec/runner/formatter/base_text_formatter.rb, line 105
105:         def magenta(text); colour(text, "\e[35m"); end

[Source]

     # File lib/spec/runner/formatter/base_text_formatter.rb, line 103
103:         def red(text); colour(text, "\e[31m"); end

[Validate]