Class: Spec::Runner::Formatter::BaseTextFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/vendor/plugins/rspec/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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFormatter

#add_example_group, #example_failed, #example_passed, #example_started, #start, #start_dump

Constructor Details

#initialize(options, output) ⇒ BaseTextFormatter

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



16
17
18
19
20
21
22
23
24
25
# File 'lib/vendor/plugins/rspec/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

Instance Attribute Details

#example_groupObject (readonly)

Returns the value of attribute example_group.



11
12
13
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb', line 11

def example_group
  @example_group
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb', line 11

def output
  @output
end

Instance Method Details

#closeObject



85
86
87
# File 'lib/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb', line 85

def close
  @output.close  if (IO === @output) & (@output != $stdout)
end

#colorize_failure(message, failure) ⇒ Object



43
44
45
# File 'lib/vendor/plugins/rspec/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) ⇒ Object



47
48
49
50
# File 'lib/vendor/plugins/rspec/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) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/vendor/plugins/rspec/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_pendingObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vendor/plugins/rspec/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) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vendor/plugins/rspec/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) ⇒ Object



27
28
29
# File 'lib/vendor/plugins/rspec/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) ⇒ Object



31
32
33
# File 'lib/vendor/plugins/rspec/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) ⇒ Object



89
90
91
92
# File 'lib/vendor/plugins/rspec/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