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.



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

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

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#close(_notification = nil) ⇒ Object



50
51
52
53
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 50

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

#failures(notification) ⇒ Object



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

def failures(notification)
  if !notification.nil?
    notification.examples.select { |e| e.execution_result.status == :failed }
  else
    examples.select { |e| e.execution_result[:status] == "failed" }
  end
end

#message(_notification) ⇒ Object



19
20
# File 'lib/gorgon/gorgon_rspec_formatter.rb', line 19

def message(_notification)
end

#stop(notification = nil) ⇒ Object



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 22

def stop(notification=nil)
  @failures += failures(notification).map do |failure|
    {
      test_name: "#{failure.full_description}: line #{failure.[:line_number]}",
      description: failure.description,
      full_description: failure.full_description,
      status: :failed,
      file_path: failure.[:file_path],
      line_number: failure.[:line_number],
    }.tap do |hash|
      exception = failure.exception
      unless exception.nil?
        hash[:class] = exception.class.name
        hash[:message] = exception.message
        hash[:location] = exception.backtrace
      end
    end
  end
end