Class: Attest::Output::FailuresOnlyOutputWriter

Inherits:
OutputWriter show all
Defined in:
lib/attest/output/failures_only_output_writer.rb

Instance Method Summary collapse

Methods inherited from OutputWriter

#after_container, #an_error, #before_all_tests, #before_test, #ignore_container, #summary

Methods included from OutputWriterInterface

#after_container, #an_error, #before_all_tests, #before_test, #ignore_container, #summary

Constructor Details

#initializeFailuresOnlyOutputWriter

Returns a new instance of FailuresOnlyOutputWriter.



8
9
10
11
# File 'lib/attest/output/failures_only_output_writer.rb', line 8

def initialize
  super()
  @relevant_outputs = StringIO.new
end

Instance Method Details

#after_all_testsObject



13
14
15
16
17
18
# File 'lib/attest/output/failures_only_output_writer.rb', line 13

def after_all_tests
  super
  @relevant_outputs.rewind
  2.times {puts}
  puts @relevant_outputs.readlines
end

#after_test(test_object) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/attest/output/failures_only_output_writer.rb', line 25

def after_test(test_object)
  relevant_result = determine_relevant_result test_object
  if relevant_result && relevant_result.failure?
    @relevant_outputs.puts "#{@containers.last.file}"
    @relevant_outputs.puts " #{@containers.last.description}"
    @relevant_outputs.puts "  - #{test_object.description} [#{relevant_result.status.upcase}]"
    @relevant_outputs.puts "  #{relevant_result.source_location}"
    @relevant_outputs.puts
  elsif relevant_result && relevant_result.error?
    e = relevant_result.attributes[:unexpected_error]
    @relevant_outputs.puts "#{@containers.last.file}"
    @relevant_outputs.puts " #{@containers.last.description}"
    @relevant_outputs.puts "  - #{test_object.description} [#{relevant_result.status.upcase}]"
    @relevant_outputs.puts "  #{e.class}: #{e.message}"
    e.backtrace.each do |line|
      @relevant_outputs.puts "   #{line} "
    end
    @relevant_outputs.puts
  end
end

#before_container(container) ⇒ Object



20
21
22
23
# File 'lib/attest/output/failures_only_output_writer.rb', line 20

def before_container(container)
  previous_container = @containers.last
  @containers << container
end