Class/Module 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

example_group[R]
output[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 puts and write).

# File lib/spec/runner/formatter/base_text_formatter.rb, line 16
def initialize(options, output)
  @options = options
  if String === output
    FileUtils.mkdir_p(File.dirname(output))
    @output = File.open(output, 'w')
  else
    @output = output
  end
  @pending_examples = []
end

Public Instance Methods

close() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 85
def close
  @output.close  if (IO === @output) & (@output != $stdout)
end
colorize_failure(message, failure) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 43
def colorize_failure(message, failure)
  failure.pending_fixed? ? blue(message) : red(message)
end
colourise(message, failure) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 47
def colourise(message, failure)
  Spec::deprecate("BaseTextFormatter#colourise", "colorize_failure")
  colorize_failure(message, failure)
end
dump_failure(counter, failure) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 35
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() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 73
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) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 52
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_group_started(example_group_proxy) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 27
def example_group_started(example_group_proxy)
  @example_group = example_group_proxy
end
example_pending(example, message, deprecated_pending_location=nil) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 31
def example_pending(example, message, deprecated_pending_location=nil)
  @pending_examples << ["#{@example_group.description} #{example.description}", message, example.location]
end
format_backtrace(backtrace) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 89
def format_backtrace(backtrace)
  return "" if backtrace.nil?
  backtrace.map { |line| backtrace_line(line) }.join("\n")
end

Protected Instance Methods

autospec?() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 104
def autospec?
  !!@options.autospec || ENV.has_key?("AUTOTEST")
end
backtrace_line(line) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 108
def backtrace_line(line)
  line.sub(/\A([^:]+:\d+)$/, '\1:')
end
blue(text) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 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
def colour(text, colour_code)
  return text if output_to_file?
  return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?)) 
  "#{colour_code}#{text}\e[0m"
end
colour?() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 96
def colour?
  !!@options.colour
end
dry_run?() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 100
def dry_run?
  !!@options.dry_run
end
green(text) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 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
def magenta(text)
  Spec::deprecate("BaseTextFormatter#magenta")
  red(text)
end
output_to_file?() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 118
def output_to_file?
  File === @output
end
output_to_tty?() click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 122
def output_to_tty?
  begin
    @output.tty?
  rescue NoMethodError
    false
  end
end
red(text) click to toggle source
# File lib/spec/runner/formatter/base_text_formatter.rb, line 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
def yellow(text); colour(text, "\e[33m"); end

[Validate]

Generated with the Darkfish Rdoc Generator 2.