Class: DTest::Test::Case

Inherits:
Object
  • Object
show all
Includes:
Hook
Defined in:
lib/dtest/test.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hook

#exec

Constructor Details

#initialize(name, beforeCase, afterCase, before, after, test, local_contexts) ⇒ Case

Returns a new instance of Case.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dtest/test.rb', line 17

def initialize(name, beforeCase, afterCase, before, after, test, local_contexts)
  @name = name
  @beforeCase = beforeCase
  @afterCase = afterCase
  @before = before
  @after = after
  @test = test
  @defined_values = Object.new
  @shared_contexts = []
  @local_contexts = local_contexts
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



12
13
14
# File 'lib/dtest/test.rb', line 12

def after
  @after
end

#afterCaseObject

Returns the value of attribute afterCase.



11
12
13
# File 'lib/dtest/test.rb', line 11

def afterCase
  @afterCase
end

#beforeObject

Returns the value of attribute before.



12
13
14
# File 'lib/dtest/test.rb', line 12

def before
  @before
end

#beforeCaseObject

Returns the value of attribute beforeCase.



11
12
13
# File 'lib/dtest/test.rb', line 11

def beforeCase
  @beforeCase
end

#defined_valuesObject

Returns the value of attribute defined_values.



14
15
16
# File 'lib/dtest/test.rb', line 14

def defined_values
  @defined_values
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/dtest/test.rb', line 10

def name
  @name
end

#shared_contextsObject

Returns the value of attribute shared_contexts.



15
16
17
# File 'lib/dtest/test.rb', line 15

def shared_contexts
  @shared_contexts
end

#testObject

Returns the value of attribute test.



13
14
15
# File 'lib/dtest/test.rb', line 13

def test
  @test
end

Instance Method Details

#execute(global_result) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/dtest/test.rb', line 102

def execute(global_result)
  # TestCase result
  caseresult = CaseResult.new(@name)
  global_result.add(caseresult)

  # set result
  @beforeCase.each {|b| b.result = caseresult.before_failure }
  @afterCase.each {|b| b.result = caseresult.after_failure }

  Progress.setUpTestCase(name, @test.size)
    executed = 0
    passed = 0
    context = create_context

    begin
      caseresult.timer {
        # execute beforeCase
        exec(@beforeCase, context)

        # execute each test
        @test.each do |test|
          executed += 1
          result = Result.new(test.name)
          caseresult.add(result)
          execute_test(result, test)
          passed += 1 if result.result == Result::PASS
        end
      } # Stopwatch::timer
    rescue AbortTestCase
      # にぎりつぶす
    ensure
      # report
      caseresult.passed = passed
      caseresult.failed = executed - passed
      caseresult.executed = executed
      caseresult.untested = @test.size - executed

      # execute afterCase
      begin
        execute_after_case(@afterCase, context)
      ensure
        # report testcase finished
        Progress.tearDownTestCase(name, executed, caseresult.elapsed)
      end
    end
end