Class: Turn::TestCase

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/turn/components/case.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *files) ⇒ TestCase

Returns a new instance of TestCase.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/turn/components/case.rb', line 32

def initialize(name, *files)
  @name  = name
  @files = (files.empty? ? [name] : files)
  @tests = []

  @message = nil
  @count_assertions = 0

  #@count_tests      = 0
  #@count_failures   = 0
  #@count_errors     = 0

  #@command = command
end

Instance Attribute Details

#count_assertionsObject

This can’t be calculated, so it must be assigned by the runner.



23
24
25
# File 'lib/turn/components/case.rb', line 23

def count_assertions
  @count_assertions
end

#filesObject

Some runners marshal tests per file.



14
15
16
# File 'lib/turn/components/case.rb', line 14

def files
  @files
end

#messageObject



99
100
101
# File 'lib/turn/components/case.rb', line 99

def message
  tests.collect{ |t| t.message }.join("\n")
end

#nameObject

Name of test case.



8
9
10
# File 'lib/turn/components/case.rb', line 8

def name
  @name
end

#testsObject

Test methods.



11
12
13
# File 'lib/turn/components/case.rb', line 11

def tests
  @tests
end

Instance Method Details

#count_errorsObject



81
82
83
# File 'lib/turn/components/case.rb', line 81

def count_errors
  sum = 0; tests.each{ |t| sum += 1 if t.error? }; sum
end

#count_failuresObject



77
78
79
# File 'lib/turn/components/case.rb', line 77

def count_failures
  sum = 0; tests.each{ |t| sum += 1 if t.fail? }; sum
end

#count_passesObject



85
86
87
# File 'lib/turn/components/case.rb', line 85

def count_passes
  sum = 0; tests.each{ |t| sum += 1 if t.pass? }; sum
end

#count_skipsObject



89
90
91
92
# File 'lib/turn/components/case.rb', line 89

def count_skips
  # Why not use tests.select(&:skip?).size ?
  sum = 0; tests.each{ |t| sum += 1 if t.skip? }; sum
end

#count_testsObject Also known as: size



71
72
73
# File 'lib/turn/components/case.rb', line 71

def count_tests
  tests.size
end

#countsObject



95
96
97
# File 'lib/turn/components/case.rb', line 95

def counts
  return count_tests, count_assertions, count_failures, count_errors, count_skips
end

#each(&block) ⇒ Object



103
104
105
# File 'lib/turn/components/case.rb', line 103

def each(&block)
  tests.each(&block)
end

#error?Boolean

Were there any errors?

Returns:

  • (Boolean)


57
58
59
# File 'lib/turn/components/case.rb', line 57

def error?
  count_errors != 0
end

#fail?Boolean

Were there any failures?

Returns:

  • (Boolean)


62
63
64
# File 'lib/turn/components/case.rb', line 62

def fail?
  count_failures != 0
end

#new_test(name) ⇒ Object



47
48
49
50
51
# File 'lib/turn/components/case.rb', line 47

def new_test(name)
  c = TestMethod.new(name)
  @tests << c
  c
end

#pass?Boolean

Did all tests/assertion pass?

Returns:

  • (Boolean)


67
68
69
# File 'lib/turn/components/case.rb', line 67

def pass?
  not(fail? or error?)
end