Class: TestProf::BeforeAll::Minitest::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/recipes/minitest/before_all.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Executor

Returns a new instance of Executor.



15
16
17
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 15

def initialize(&block)
  @block = block
end

Instance Attribute Details

#activeObject (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

Instance Method Details

#activate!(test_class) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 19

def activate!(test_class)
  return if active?
  @active = true
  @examples_left = test_class.runnable_methods.size
  BeforeAll.begin_transaction
  capture!
end

#capture!Object



35
36
37
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 35

def capture!
  instance_eval(&@block)
end

#restore_to(test_object) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 39

def restore_to(test_object)
  instance_variables.each do |ivar|
    next if ivar == :@block
    test_object.instance_variable_set(
      ivar,
      instance_variable_get(ivar)
    )
  end
end

#try_deactivate!Object



27
28
29
30
31
32
33
# File 'lib/test_prof/recipes/minitest/before_all.rb', line 27

def try_deactivate!
  @examples_left -= 1
  return unless @examples_left.zero?

  @active = false
  BeforeAll.rollback_transaction
end