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
public instance
- close
- colorize_failure
- colourise
- dump_failure
- dump_pending
- dump_summary
- example_pending
- format_backtrace
protected instance
Attributes
| output | [R] | |
| pending_examples | [R] |
Public class methods
new
(options, where)
Creates a new instance that will write to where. If where is a String, output will be written to the File with that name, otherwise where is exected to be an IO (or an object that responds to puts and write).
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 15 def initialize(options, where) super if where.is_a?(String) FileUtils.mkdir_p(File.dirname(where)) @output = File.open(where, 'w') else @output = where end @pending_examples = [] end
Public instance methods
close
()
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 86 def close @output.close if (IO === @output) & (@output != $stdout) end
colorize_failure
(message, failure)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 38 def colorize_failure(message, failure) failure.pending_fixed? ? blue(message) : red(message) end
colourise
(message, failure)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 42 def colourise(message, failure) Kernel.warn "DEPRECATED: BaseTextFormatter#colourise is deprecated and will be\nremoved from a future version of RSpec.\n\nPlease use colorize_failure instead.\n" colorize_failure(message, failure) end
dump_failure
(counter, failure)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 30 def dump_failure(counter, failure) @output.puts @output.puts "#{counter.to_s})" @output.puts colorize_failure("#{failure.header}\n#{failure.exception.message}", failure) @output.puts format_backtrace(failure.exception.backtrace) @output.flush end
dump_pending
()
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 74 def dump_pending unless @pending_examples.empty? @output.puts @output.puts "Pending:" @pending_examples.each do |pending_example| @output.puts "\n#{pending_example[0]} (#{pending_example[1]})" @output.puts "#{pending_example[2]}\n" end end @output.flush end
dump_summary
(duration, example_count, failure_count, pending_count)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 53 def dump_summary(duration, example_count, failure_count, pending_count) return if dry_run? @output.puts @output.puts "Finished in #{duration} seconds" @output.puts summary = "#{example_count} example#{'s' unless example_count == 1}, #{failure_count} failure#{'s' unless failure_count == 1}" summary << ", #{pending_count} pending" if pending_count > 0 if failure_count == 0 if pending_count > 0 @output.puts yellow(summary) else @output.puts green(summary) end else @output.puts red(summary) end @output.flush end
example_pending
(example, message, pending_caller)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 26 def example_pending(example, message, pending_caller) @pending_examples << ["#{@example_group.description} #{example.description}", message, pending_caller] end
format_backtrace
(backtrace)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 90 def format_backtrace(backtrace) return "" if backtrace.nil? backtrace.map { |line| backtrace_line(line) }.join("\n") end
Protected instance methods
autospec?
()
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 105 def autospec? !!@options.autospec end
backtrace_line
(line)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 109 def backtrace_line(line) line.sub(/\A([^:]+:\d+)$/, '\\1:') end
blue
(text)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 129 def blue(text); colour(text, "\e[34m"); end
colour
(text, colour_code)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 113 def colour(text, colour_code) return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?)) "#{colour_code}#{text}\e[0m" end
colour?
()
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 97 def colour? !!@options.colour end
dry_run?
()
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 101 def dry_run? !!@options.dry_run end
green
(text)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 126 def green(text); colour(text, "\e[32m"); end
magenta
(text)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 131 def magenta(text) Kernel.warn "DEPRECATED: BaseTextFormatter#magenta is deprecated and will be\nremoved from a future version of RSpec.\n\nPlease use red instead (it is red/green/refactor after all).\n" red(text) end
output_to_tty?
()
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 118 def output_to_tty? begin @output.tty? || ENV.has_key?("AUTOTEST") rescue NoMethodError false end end
red
(text)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 127 def red(text); colour(text, "\e[31m"); end
yellow
(text)
[show source]
# File lib/spec/runner/formatter/base_text_formatter.rb, line 128 def yellow(text); colour(text, "\e[33m"); end