Class: Scope::Context
- Inherits:
-
Object
- Object
- Scope::Context
- Defined in:
- lib/scope.rb
Overview
A context keeps track of the tests defined inside of it as well as its setup and teardown blocks.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_context ⇒ Object
readonly
Returns the value of attribute parent_context.
-
#setup ⇒ Object
Returns the value of attribute setup.
-
#setup_once ⇒ Object
Returns the value of attribute setup_once.
-
#teardown ⇒ Object
Returns the value of attribute teardown.
-
#teardown_once ⇒ Object
Returns the value of attribute teardown_once.
-
#tests_and_subcontexts ⇒ Object
We keep both tests and subcontexts in the same array because we need to know what the very last thing to execute inside of this context is, for the purpose of calling teardown_once at the correct time.
Instance Method Summary collapse
-
#initialize(name, parent_context = nil) ⇒ Context
constructor
A new instance of Context.
-
#run_setup_and_teardown(test_case_instance, test_name, &runner_proc) ⇒ Object
Runs the setup work for this context and any parent contexts, yields to the block (which should invoke the actual test method), and then completes the teardown work.
Constructor Details
#initialize(name, parent_context = nil) ⇒ Context
Returns a new instance of Context.
111 112 113 114 115 |
# File 'lib/scope.rb', line 111 def initialize(name, parent_context = nil) @name = name @parent_context = parent_context self.tests_and_subcontexts = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
105 106 107 |
# File 'lib/scope.rb', line 105 def name @name end |
#parent_context ⇒ Object (readonly)
Returns the value of attribute parent_context.
105 106 107 |
# File 'lib/scope.rb', line 105 def parent_context @parent_context end |
#setup ⇒ Object
Returns the value of attribute setup.
109 110 111 |
# File 'lib/scope.rb', line 109 def setup @setup end |
#setup_once ⇒ Object
Returns the value of attribute setup_once.
109 110 111 |
# File 'lib/scope.rb', line 109 def setup_once @setup_once end |
#teardown ⇒ Object
Returns the value of attribute teardown.
109 110 111 |
# File 'lib/scope.rb', line 109 def teardown @teardown end |
#teardown_once ⇒ Object
Returns the value of attribute teardown_once.
109 110 111 |
# File 'lib/scope.rb', line 109 def teardown_once @teardown_once end |
#tests_and_subcontexts ⇒ Object
We keep both tests and subcontexts in the same array because we need to know what the very last thing to execute inside of this context is, for the purpose of calling teardown_once at the correct time.
108 109 110 |
# File 'lib/scope.rb', line 108 def tests_and_subcontexts @tests_and_subcontexts end |
Instance Method Details
#run_setup_and_teardown(test_case_instance, test_name, &runner_proc) ⇒ Object
Runs the setup work for this context and any parent contexts, yields to the block (which should invoke the actual test method), and then completes the teardown work.
119 120 121 122 |
# File 'lib/scope.rb', line 119 def run_setup_and_teardown(test_case_instance, test_name, &runner_proc) contexts = ([self] + ancestor_contexts).reverse recursively_run_setup_and_teardown(test_case_instance, test_name, contexts, runner_proc) end |