Class: TestProf::BeforeAll::Minitest::Executor
- Inherits:
-
Object
- Object
- TestProf::BeforeAll::Minitest::Executor
- Defined in:
- lib/test_prof/recipes/minitest/before_all.rb
Overview
:nodoc: all
Instance Attribute Summary collapse
-
#active ⇒ Object
(also: #active?)
readonly
Returns the value of attribute active.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#captured_ivars ⇒ Object
readonly
Returns the value of attribute captured_ivars.
-
#current_test_object ⇒ Object
readonly
Returns the value of attribute current_test_object.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#setup_fixtures ⇒ Object
(also: #setup_fixtures?)
readonly
Returns the value of attribute setup_fixtures.
-
#teardown_block ⇒ Object
readonly
Returns the value of attribute teardown_block.
Instance Method Summary collapse
- #activate!(test_object) ⇒ Object
- #capture!(test_object) ⇒ Object
- #deactivate! ⇒ Object
-
#initialize(setup_fixtures: false, parent: nil, &block) ⇒ Executor
constructor
A new instance of Executor.
- #perform_setup(test_object) ⇒ Object
- #perform_teardown(test_object) ⇒ Object
- #restore_ivars(test_object) ⇒ Object
- #teardown(&block) ⇒ Object
Constructor Details
#initialize(setup_fixtures: false, parent: nil, &block) ⇒ Executor
Returns a new instance of Executor.
47 48 49 50 51 52 53 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 47 def initialize(setup_fixtures: false, parent: nil, &block) @parent = parent # Fixtures must be instantiated if any of the executors needs them @setup_fixtures = setup_fixtures || parent&.setup_fixtures @block = block @captured_ivars = [] end |
Instance Attribute Details
#active ⇒ Object (readonly) Also known as: active?
Returns the value of attribute active.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def active @active end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def block @block end |
#captured_ivars ⇒ Object (readonly)
Returns the value of attribute captured_ivars.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def captured_ivars @captured_ivars end |
#current_test_object ⇒ Object (readonly)
Returns the value of attribute current_test_object.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def current_test_object @current_test_object end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def parent @parent end |
#setup_fixtures ⇒ Object (readonly) Also known as: setup_fixtures?
Returns the value of attribute setup_fixtures.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def setup_fixtures @setup_fixtures end |
#teardown_block ⇒ Object (readonly)
Returns the value of attribute teardown_block.
41 42 43 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 41 def teardown_block @teardown_block end |
Instance Method Details
#activate!(test_object) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 59 def activate!(test_object) @current_test_object = test_object return restore_ivars(test_object) if active? @active = true BeforeAll.setup_fixtures(test_object) if setup_fixtures? BeforeAll.begin_transaction do capture!(test_object) end end |
#capture!(test_object) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 83 def capture!(test_object) before_ivars = test_object.instance_variables perform_setup(test_object) (test_object.instance_variables - before_ivars).each do |ivar| captured_ivars << [ivar, test_object.instance_variable_get(ivar)] end end |
#deactivate! ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 72 def deactivate! return unless active @active = false perform_teardown(current_test_object) @current_test_object = nil BeforeAll.rollback_transaction end |
#perform_setup(test_object) ⇒ Object
102 103 104 105 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 102 def perform_setup(test_object) parent&.perform_setup(test_object) test_object.instance_eval(&block) if block end |
#perform_teardown(test_object) ⇒ Object
107 108 109 110 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 107 def perform_teardown(test_object) current_test_object&.instance_eval(&teardown_block) if teardown_block parent&.perform_teardown(test_object) end |
#restore_ivars(test_object) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 93 def restore_ivars(test_object) captured_ivars.each do |(ivar, val)| test_object.instance_variable_set( ivar, val ) end end |
#teardown(&block) ⇒ Object
55 56 57 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 55 def teardown(&block) @teardown_block = block end |