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

Holds dump of test output (optional depending on runner).



26
27
28
# File 'lib/turn/components/case.rb', line 26

def message
  @message
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_testsObject Also known as: size



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

def count_tests
  tests.size
end

#countsObject



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

def counts
  return count_tests, count_assertions, count_failures, count_errors
end

#each(&block) ⇒ Object



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

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