Class: Moon::Test::SpecSuite::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/packages/test/spec/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.


32
33
34
35
36
37
38
39
40
41
# File 'lib/moon/packages/test/spec/stats.rb', line 32

def initialize
  @logger = Logger.new
  @fail_stack = []
  @result_stack = []
  @time_diff = 0
  @test_count = 0
  @assertions = 0
  @assertion_errors = 0
  @passed = 0
end

Instance Attribute Details

#assertion_errorsInteger

Returns:


27
28
29
# File 'lib/moon/packages/test/spec/stats.rb', line 27

def assertion_errors
  @assertion_errors
end

#assertionsInteger

Returns:


24
25
26
# File 'lib/moon/packages/test/spec/stats.rb', line 24

def assertions
  @assertions
end

#fail_stackArray<Array<[String, Exception]>>

Returns:


15
16
17
# File 'lib/moon/packages/test/spec/stats.rb', line 15

def fail_stack
  @fail_stack
end

#loggerMoon::Test::Logger

Returns:


9
10
11
# File 'lib/moon/packages/test/spec/stats.rb', line 9

def logger
  @logger
end

#passedInteger

Returns:


30
31
32
# File 'lib/moon/packages/test/spec/stats.rb', line 30

def passed
  @passed
end

#result_stackArray<Boolean>

Returns:


18
19
20
# File 'lib/moon/packages/test/spec/stats.rb', line 18

def result_stack
  @result_stack
end

#test_countInteger

Returns:


21
22
23
# File 'lib/moon/packages/test/spec/stats.rb', line 21

def test_count
  @test_count
end

#time_diffFloat

Returns:


12
13
14
# File 'lib/moon/packages/test/spec/stats.rb', line 12

def time_diff
  @time_diff
end

Instance Method Details

#add_failure(obj) ⇒ Object


58
59
60
61
# File 'lib/moon/packages/test/spec/stats.rb', line 58

def add_failure(obj)
  @result_stack << false
  @fail_stack << obj
end

#add_passObject


53
54
55
56
# File 'lib/moon/packages/test/spec/stats.rb', line 53

def add_pass
  @passed += 1
  @result_stack << true
end

#concat(stats) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'lib/moon/packages/test/spec/stats.rb', line 43

def concat(stats)
  @fail_stack.concat(stats.fail_stack)
  @result_stack.concat(stats.result_stack)
  @time_diff += stats.time_diff
  @test_count += stats.test_count
  @assertions += stats.assertions
  @assertion_errors += stats.assertion_errors
  @passed += stats.passed
end

#displayObject


113
114
115
116
117
118
119
# File 'lib/moon/packages/test/spec/stats.rb', line 113

def display
  display_result_stack
  display_backtraces
  display_test_count
  display_assertion_count
  display_time_diff
end

#display_assertion_countObject


100
101
102
103
104
105
106
107
# File 'lib/moon/packages/test/spec/stats.rb', line 100

def display_assertion_count
  if @assertions > 0
    @logger.puts 'Assertions:'
    @logger.puts '  Total: ' << @assertions.to_s
    @logger.puts '     OK: ' << (@assertions - @assertion_errors).to_s
    @logger.puts '   Fail: ' << @assertion_errors.to_s
  end
end

#display_backtracesObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/moon/packages/test/spec/stats.rb', line 70

def display_backtraces
  @logger.puts
  @fail_stack.each_with_index do |a, i|
    str, ex = *a
    @logger.puts "##{i} #{str}"
    @logger.puts ex.inspect
    @logger.puts 'Backtrace: >'
    ex.backtrace.each do |l|
      @logger.puts "  #{l}"
    end

    # suppress the test_stack
    #if ex.respond_to?(:test_stack)
    #  @logger.puts 'Test Stack: >'
    #  ex.test_stack.each do |l|
    #    @logger.puts "  #{l}"
    #  end
    #end
    @logger.puts
  end
end

#display_result_stackObject


63
64
65
66
67
68
# File 'lib/moon/packages/test/spec/stats.rb', line 63

def display_result_stack
  @logger.puts
  @result_stack.each do |status|
    @logger.print status ? '.' : 'F'
  end
end

#display_test_countObject


92
93
94
95
96
97
98
# File 'lib/moon/packages/test/spec/stats.rb', line 92

def display_test_count
  @logger.puts
  @logger.puts 'Tests: '
  @logger.puts '  Total: ' << @test_count.to_s
  @logger.puts '     OK: ' << @passed.to_s
  @logger.puts '   Fail: ' << (@test_count - @passed).to_s
end

#display_time_diffObject


109
110
111
# File 'lib/moon/packages/test/spec/stats.rb', line 109

def display_time_diff
  @logger.puts 'Time: ' << (@time_diff).round(6).to_s[0, 8] << ' seconds'
end