Class Index [+]

Quicksearch

Spec::Runner::Formatter::BaseTextFormatter

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

Attributes

output[R]
example_group[R]

Public Class Methods

new(options, output) click to toggle source

Creates a new instance that will write to output. If output is a String, output will be written to the File with that name, otherwise output is exected to be an IO (or an object that responds to # and #).

    # File lib/spec/runner/formatter/base_text_formatter.rb, line 16
16:         def initialize(options, output)
17:           @options = options
18:           if String === output
19:             FileUtils.mkdir_p(File.dirname(output))
20:             @output = File.open(output, 'w')
21:           else
22:             @output = output
23:           end
24:           @pending_examples = []
25:         end

Public Instance Methods

close() click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 85
85:         def close
86:           @output.close  if (IO === @output) & (@output != $stdout)
87:         end
colorize_failure(message, failure) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 43
43:         def colorize_failure(message, failure)
44:           failure.pending_fixed? ? blue(message) : red(message)
45:         end
colourise(message, failure) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 47
47:         def colourise(message, failure)
48:           Spec::deprecate("BaseTextFormatter#colourise", "colorize_failure")
49:           colorize_failure(message, failure)
50:         end
dump_failure(counter, failure) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 35
35:         def dump_failure(counter, failure)
36:           @output.puts
37:           @output.puts "#{counter.to_s})"
38:           @output.puts colorize_failure("#{failure.header}\n#{failure.exception.message}", failure)
39:           @output.puts format_backtrace(failure.exception.backtrace)
40:           @output.flush
41:         end
dump_pending() click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 73
73:         def dump_pending
74:           unless @pending_examples.empty?
75:             @output.puts
76:             @output.puts "Pending:"
77:             @pending_examples.each do |pending_example|
78:               @output.puts "\n#{pending_example[0]} (#{pending_example[1]})"
79:               @output.puts "#{pending_example[2]}\n"
80:             end
81:           end
82:           @output.flush
83:         end
dump_summary(duration, example_count, failure_count, pending_count) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 52
52:         def dump_summary(duration, example_count, failure_count, pending_count)
53:           return if dry_run?
54:           @output.puts
55:           @output.puts "Finished in #{duration} seconds"
56:           @output.puts
57: 
58:           summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}"
59:           summary << ", #{pending_count} pending" if pending_count > 0  
60: 
61:           if failure_count == 0
62:             if pending_count > 0
63:               @output.puts yellow(summary)
64:             else
65:               @output.puts green(summary)
66:             end
67:           else
68:             @output.puts red(summary)
69:           end
70:           @output.flush
71:         end
example_group_started(example_group_proxy) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 27
27:         def example_group_started(example_group_proxy)
28:           @example_group = example_group_proxy
29:         end
example_pending(example, message, deprecated_pending_location=nil) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 31
31:         def example_pending(example, message, deprecated_pending_location=nil)
32:           @pending_examples << ["#{@example_group.description} #{example.description}", message, example.location]
33:         end
format_backtrace(backtrace) click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 89
89:         def format_backtrace(backtrace)
90:           return "" if backtrace.nil?
91:           backtrace.map { |line| backtrace_line(line) }.join("\n")
92:         end

Protected Instance Methods

autospec?() click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 104
104:         def autospec?
105:           !!@options.autospec || ENV.has_key?("AUTOTEST")
106:         end
backtrace_line(line) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 108
108:         def backtrace_line(line)
109:           line.sub(/\A([^:]+:\d+)$/, '\1:')
110:         end
blue(text) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 133
133:         def blue(text); colour(text, "\e[34m"); end
colour(text, colour_code) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 112
112:         def colour(text, colour_code)
113:           return text if output_to_file?
114:           return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?)) 
115:           "#{colour_code}#{text}\e[0m"
116:         end
colour?() click to toggle source
    # File lib/spec/runner/formatter/base_text_formatter.rb, line 96
96:         def colour?
97:           !!@options.colour
98:         end
dry_run?() click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 100
100:         def dry_run?
101:           !!@options.dry_run
102:         end
green(text) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 130
130:         def green(text); colour(text, "\e[32m"); end
magenta(text) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 135
135:         def magenta(text)
136:           Spec::deprecate("BaseTextFormatter#magenta")
137:           red(text)
138:         end
output_to_file?() click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 118
118:         def output_to_file?
119:           File === @output
120:         end
output_to_tty?() click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 122
122:         def output_to_tty?
123:           begin
124:             @output.tty?
125:           rescue NoMethodError
126:             false
127:           end
128:         end
red(text) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 131
131:         def red(text); colour(text, "\e[31m"); end
yellow(text) click to toggle source
     # File lib/spec/runner/formatter/base_text_formatter.rb, line 132
132:         def yellow(text); colour(text, "\e[33m"); end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.