Module: Assert::Context::SetupDSL

Included in:
Assert::Context
Defined in:
lib/assert/context/setup_dsl.rb

Instance Method Summary collapse

Instance Method Details

#around(&block) ⇒ Object



18
19
20
# File 'lib/assert/context/setup_dsl.rb', line 18

def around(&block)
  self.arounds << block
end

#aroundsObject



32
33
34
# File 'lib/assert/context/setup_dsl.rb', line 32

def arounds
  @arounds ||= []
end

#run_arounds(scope, &run_block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/assert/context/setup_dsl.rb', line 44

def run_arounds(scope, &run_block)
  context_block = self.arounds.compact.reverse.inject(run_block) do |run_b, around_b|
    Proc.new{ scope.instance_exec(run_b, &around_b) }
  end

  if self.superclass.respond_to?(:run_arounds)
    self.superclass.run_arounds(scope, &context_block)
  else
    context_block.call
  end
end

#run_setups(scope) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/assert/context/setup_dsl.rb', line 56

def run_setups(scope)
  # setup the parent...
  self.superclass.run_setups(scope) if self.superclass.respond_to?(:run_setups)
  # ... before you setup the child
  self.setups.compact.each do |setup|
    setup.kind_of?(::Proc) ? scope.instance_eval(&setup) : scope.send(setup)
  end
end

#run_teardowns(scope) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/assert/context/setup_dsl.rb', line 65

def run_teardowns(scope)
  # teardown the child...
  self.teardowns.compact.each do |teardown|
    teardown.kind_of?(::Proc) ? scope.instance_eval(&teardown) : scope.send(teardown)
  end
  # ... before the parent
  self.superclass.run_teardowns(scope) if self.superclass.respond_to?(:run_teardowns)
end

#setup(method_name = nil, &block) ⇒ Object Also known as: before



22
23
24
# File 'lib/assert/context/setup_dsl.rb', line 22

def setup(method_name = nil, &block)
  self.setups << (block || method_name)
end

#setup_once(&block) ⇒ Object Also known as: before_once, startup



6
7
8
# File 'lib/assert/context/setup_dsl.rb', line 6

def setup_once(&block)
  self.suite.setup(&block)
end

#setupsObject



36
37
38
# File 'lib/assert/context/setup_dsl.rb', line 36

def setups
  @setups ||= []
end

#teardown(method_name = nil, &block) ⇒ Object Also known as: after



27
28
29
# File 'lib/assert/context/setup_dsl.rb', line 27

def teardown(method_name = nil, &block)
  self.teardowns << (block || method_name)
end

#teardown_once(&block) ⇒ Object Also known as: after_once, shutdown



12
13
14
# File 'lib/assert/context/setup_dsl.rb', line 12

def teardown_once(&block)
  self.suite.teardown(&block)
end

#teardownsObject



40
41
42
# File 'lib/assert/context/setup_dsl.rb', line 40

def teardowns
  @teardowns ||= []
end