Module: Minitest::Set::TestHelper

Defined in:
lib/minitest/set/test_helper.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
# File 'lib/minitest/set/test_helper.rb', line 2

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#before_setupObject



14
15
16
17
18
# File 'lib/minitest/set/test_helper.rb', line 14

def before_setup
  super
  @minitest_sets = self.class.minitest_sets&.dup
  @minitest_sets&.each(&:setup)
end

#before_teardownObject



20
21
22
23
# File 'lib/minitest/set/test_helper.rb', line 20

def before_teardown
  super
  @minitest_sets&.reverse_each(&:teardown)
end

#set(object, **attributes, &block) ⇒ Object



25
26
27
28
29
30
# File 'lib/minitest/set/test_helper.rb', line 25

def set(object, **attributes, &block)
  (@minitest_sets ||= []) << Minitest::Set::Change.new(object, **attributes).tap(&:setup)
  block&.call
ensure
  @minitest_sets.pop.teardown if block
end