Class: DTest::Test::Case
Instance Attribute Summary collapse
-
#after ⇒ Object
Returns the value of attribute after.
-
#afterCase ⇒ Object
Returns the value of attribute afterCase.
-
#before ⇒ Object
Returns the value of attribute before.
-
#beforeCase ⇒ Object
Returns the value of attribute beforeCase.
-
#name ⇒ Object
Returns the value of attribute name.
-
#test ⇒ Object
Returns the value of attribute test.
Instance Method Summary collapse
- #execute(global_result) ⇒ Object
- #execute_test(result, test) ⇒ Object
-
#initialize(name, beforeCase, afterCase, before, after, test) ⇒ Case
constructor
A new instance of Case.
Methods included from Hook
Constructor Details
#initialize(name, beforeCase, afterCase, before, after, test) ⇒ Case
Returns a new instance of Case.
14 15 16 17 18 19 20 21 22 |
# File 'lib/dtest/test.rb', line 14 def initialize(name, beforeCase, afterCase, before, after, test) @name = name @beforeCase = beforeCase @afterCase = afterCase @before = before @after = after @test = test @defined_values = Object.new end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
11 12 13 |
# File 'lib/dtest/test.rb', line 11 def after @after end |
#afterCase ⇒ Object
Returns the value of attribute afterCase.
10 11 12 |
# File 'lib/dtest/test.rb', line 10 def afterCase @afterCase end |
#before ⇒ Object
Returns the value of attribute before.
11 12 13 |
# File 'lib/dtest/test.rb', line 11 def before @before end |
#beforeCase ⇒ Object
Returns the value of attribute beforeCase.
10 11 12 |
# File 'lib/dtest/test.rb', line 10 def beforeCase @beforeCase end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/dtest/test.rb', line 9 def name @name end |
#test ⇒ Object
Returns the value of attribute test.
12 13 14 |
# File 'lib/dtest/test.rb', line 12 def test @test end |
Instance Method Details
#execute(global_result) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dtest/test.rb', line 43 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 = Context.new(@defined_values) 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 |
#execute_test(result, test) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 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 |
# File 'lib/dtest/test.rb', line 90 def execute_test(result, test) Progress.test(@name, test.name) context = Context.new(@defined_values) # set result @before.each {|b| b.result = result.before_failure } @after.each {|b| b.result = result.after_failure } begin # execute before blocks exec(@before, context) # exeucte test result.timer { test.result = result test.call(context, name) } rescue AbortTest # にぎりつぶす # 次のテストを実行する rescue AbortTestCase, AbortGlobal => e # スルー raise e rescue StandardError, Exception => e # にぎりつぶす ensure begin execute_after(@after, context) ensure if result.failure.empty? && result.ba_empty? result.result = Result::PASS Progress.test_success(@name, test.name) else Progress.test_fail(@name, test.name) end end end end |