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

Inherits:
BaseFormatter show all
Defined in:
lib/gems/rspec-1.1.12/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

Attributes inherited from BaseFormatter

#example_group, #options, #where

Instance Method Summary collapse

Methods inherited from BaseFormatter

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

Constructor Details

#initialize(options, where) ⇒ BaseTextFormatter

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



14
15
16
17
18
19
20
21
22
23
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 14

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

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 10

def output
  @output
end

#pending_examplesObject (readonly)

Returns the value of attribute pending_examples.



10
11
12
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 10

def pending_examples
  @pending_examples
end

Instance Method Details

#closeObject



80
81
82
83
84
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 80

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

#colourise(s, failure) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 37

def colourise(s, failure)
  if(failure.expectation_not_met?)
    red(s)
  elsif(failure.pending_fixed?)
    blue(s)
  else
    magenta(s)
  end
end

#dump_failure(counter, failure) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 29

def dump_failure(counter, failure)
  @output.puts
  @output.puts "#{counter.to_s})"
  @output.puts colourise("#{failure.header}\n#{failure.exception.message}", failure)
  @output.puts format_backtrace(failure.exception.backtrace)
  @output.flush
end

#dump_pendingObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 68

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 47

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) ⇒ Object



25
26
27
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 25

def example_pending(example, message, pending_caller)
  @pending_examples << [example.full_description, message, pending_caller]
end

#format_backtrace(backtrace) ⇒ Object



86
87
88
89
# File 'lib/gems/rspec-1.1.12/lib/spec/runner/formatter/base_text_formatter.rb', line 86

def format_backtrace(backtrace)
  return "" if backtrace.nil?
  backtrace.map { |line| backtrace_line(line) }.join("\n")
end