Class: WithModel::MiniTestLifeCycle

Inherits:
Module
  • Object
show all
Defined in:
lib/with_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ MiniTestLifeCycle

Returns a new instance of MiniTestLifeCycle.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/with_model.rb', line 14

def initialize(object)
  # Each with_model includes a fresh module, so the last one declared sits
  # earliest in the ancestor chain. Calling super() first means setup runs
  # in declaration order while teardown unwinds in reverse, which is what
  # lets one with_model refer to another declared above it.
  define_method :before_setup do
    super() if defined?(super)
    object.create
  end

  define_method :after_teardown do
    object.destroy
    super() if defined?(super)
  end
end

Class Method Details

.call(object) ⇒ Object



30
31
32
# File 'lib/with_model.rb', line 30

def self.call(object)
  new(object)
end