Class: RSpec::Core::Formatters::GorgonRspecFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/gorgon/gorgon_rspec_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ GorgonRspecFormatter

Returns a new instance of GorgonRspecFormatter.



10
11
12
13
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 10

def initialize(output)
  super
  @failures = []
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 8

def output
  @output
end

Instance Method Details

#closeObject



42
43
44
45
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 42

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

#message(message) ⇒ Object



15
16
17
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 15

def message(message)
  @failures += message unless @failures.empty?
end

#stopObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 19

def stop
  super
  failures = examples.select { |e| e.execution_result[:status] == "failed" }

  @failures += failures.map do |failure|
    {
      :test_name => "#{failure.full_description}: " \
      "line #{failure.[:line_number]}",
      :description => failure.description,
      :full_description => failure.full_description,
      :status => failure.execution_result[:status],
      :file_path => failure.[:file_path],
      :line_number  => failure.[:line_number],
    }.tap do |hash|
      if e=failure.exception
        hash[:class] = e.class.name
        hash[:message] = e.message
        hash[:location] = e.backtrace
      end
    end
  end
end