Class: Attest::Output::OutputWriter

Inherits:
Object
  • Object
show all
Includes:
OutputWriterInterface
Defined in:
lib/attest/output/output_writer.rb

Instance Method Summary collapse

Constructor Details

#initializeOutputWriter

Returns a new instance of OutputWriter.



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

def initialize
  self.instance_variable_set("@containers", [])
  self.instance_variable_set("@start_time", nil)
  self.instance_variable_set("@end_time", nil)
end

Instance Method Details

#after_all_testsObject



17
18
19
# File 'lib/attest/output/output_writer.rb', line 17

def after_all_tests
  @end_time = Time.now
end

#after_container(container) ⇒ Object



22
23
# File 'lib/attest/output/output_writer.rb', line 22

def after_container(container)
end

#after_test(test_object) ⇒ Object



26
27
# File 'lib/attest/output/output_writer.rb', line 26

def after_test(test_object)
end

#an_error(error_object) ⇒ Object



54
55
56
57
58
59
# File 'lib/attest/output/output_writer.rb', line 54

def an_error(error_object)
  puts "#{error_object.class}: #{error_object.message}"
  error_object.backtrace.each do |line|
    puts " #{line} "
  end
end

#before_all_testsObject



14
15
16
# File 'lib/attest/output/output_writer.rb', line 14

def before_all_tests
  @start_time = Time.now
end

#before_container(container) ⇒ Object



20
21
# File 'lib/attest/output/output_writer.rb', line 20

def before_container(container)
end

#before_test(test_object) ⇒ Object



24
25
# File 'lib/attest/output/output_writer.rb', line 24

def before_test(test_object)
end

#ignore_container(container) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/attest/output/output_writer.rb', line 47

def ignore_container(container)
  if @containers.last.object_id == container.object_id
    @containers.delete @containers.last 
  else 
    @containers.delete_if {|current_container| current_container.object_id == container.object_id}
  end
end

#summaryObject



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

def summary
  return unless @containers.size >= 1
  expectation_status_hash = blank_status_hash
  overall_test_status_hash = blank_status_hash
  test_count = 0
  @containers.each do |container|
    container.test_objects.each do |test_object|
      test_count += 1
      current_test_statuses = determine_test_status test_object
      overall_test_status_hash = merge_counting_hashes(overall_test_status_hash, current_test_statuses[0])
      expectation_status_hash = merge_counting_hashes(expectation_status_hash, current_test_statuses[1])
    end
  end
  puts
  print "#{test_count} tests #{expectation_status_hash.inject(0){|sum, tuple| sum + tuple[1]}} expectations"
  Attest::ExpectationResult.status_weights.sort{|a, b| a[1] <=> b[1]}.each {|status, weight| print " #{expectation_status_hash[status]} #{status.to_s}"}
  puts
  puts "Finished in #{elapsed_time(@end_time, @start_time)}"
end