Class: Test::Unit::TestCase::Context
- Inherits:
-
Object
- Object
- Test::Unit::TestCase::Context
- Defined in:
- lib/nest-unit.rb
Instance Attribute Summary collapse
-
#parent_context ⇒ Object
readonly
Returns the value of attribute parent_context.
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #context(name = nil, &block) ⇒ Object
-
#initialize(test_case, name, parent_context = nil) ⇒ Context
constructor
A new instance of Context.
- #name ⇒ Object
- #run_callback(position, kase) ⇒ Object
- #test(test_name, &block) ⇒ Object
Constructor Details
#initialize(test_case, name, parent_context = nil) ⇒ Context
Returns a new instance of Context.
11 12 13 |
# File 'lib/nest-unit.rb', line 11 def initialize(test_case, name, parent_context=nil) @test_case, @name, @parent_context = test_case, name, parent_context end |
Instance Attribute Details
#parent_context ⇒ Object (readonly)
Returns the value of attribute parent_context.
9 10 11 |
# File 'lib/nest-unit.rb', line 9 def parent_context @parent_context end |
Instance Method Details
#after(&block) ⇒ Object
19 20 21 |
# File 'lib/nest-unit.rb', line 19 def after(&block) block_given? ? (@after = block) : @after end |
#before(&block) ⇒ Object
15 16 17 |
# File 'lib/nest-unit.rb', line 15 def before(&block) block_given? ? (@before = block) : @before end |
#context(name = nil, &block) ⇒ Object
23 24 25 |
# File 'lib/nest-unit.rb', line 23 def context(name=nil, &block) Context.new(@test_case, name, self).instance_eval(&block) end |
#name ⇒ Object
35 36 37 |
# File 'lib/nest-unit.rb', line 35 def name [parent_name, @name].compact.join('_') end |
#run_callback(position, kase) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/nest-unit.rb', line 27 def run_callback(position, kase) parent_context.run_callback(position, kase) if has_parent? if callback = send(position) kase.instance_eval(&callback) end end |
#test(test_name, &block) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/nest-unit.rb', line 39 def test(test_name, &block) context = self @test_case.test [name, test_name].compact.join('_') do context.run_callback(:before, self) instance_eval(&block) context.run_callback(:after, self) end end |