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.
-
#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, &block) ⇒ Executor
constructor
A new instance of Executor.
- #restore_ivars(test_object) ⇒ Object
- #teardown(&block) ⇒ Object
Constructor Details
#initialize(setup_fixtures: false, &block) ⇒ Executor
Returns a new instance of Executor.
17 18 19 20 21 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 17 def initialize(setup_fixtures: false, &block) @setup_fixtures = setup_fixtures @block = block @captured_ivars = [] end |
Instance Attribute Details
#active ⇒ Object (readonly) Also known as: active?
Returns the value of attribute active.
11 12 13 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 11 def active @active end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
11 12 13 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 11 def block @block end |
#captured_ivars ⇒ Object (readonly)
Returns the value of attribute captured_ivars.
11 12 13 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 11 def captured_ivars @captured_ivars end |
#current_test_object ⇒ Object (readonly)
Returns the value of attribute current_test_object.
11 12 13 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 11 def current_test_object @current_test_object end |
#setup_fixtures ⇒ Object (readonly) Also known as: setup_fixtures?
Returns the value of attribute setup_fixtures.
11 12 13 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 11 def setup_fixtures @setup_fixtures end |
#teardown_block ⇒ Object (readonly)
Returns the value of attribute teardown_block.
11 12 13 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 11 def teardown_block @teardown_block end |
Instance Method Details
#activate!(test_object) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 27 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
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 47 def capture!(test_object) return unless block before_ivars = test_object.instance_variables test_object.instance_eval(&block) (test_object.instance_variables - before_ivars).each do |ivar| captured_ivars << [ivar, test_object.instance_variable_get(ivar)] end end |
#deactivate! ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 38 def deactivate! @active = false current_test_object&.instance_eval(&teardown_block) if teardown_block @current_test_object = nil BeforeAll.rollback_transaction end |
#restore_ivars(test_object) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 59 def restore_ivars(test_object) captured_ivars.each do |(ivar, val)| test_object.instance_variable_set( ivar, val ) end end |
#teardown(&block) ⇒ Object
23 24 25 |
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 23 def teardown(&block) @teardown_block = block end |