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



16
17
18
# File 'lib/assert/context/setup_dsl.rb', line 16

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

#aroundsObject



30
31
32
# File 'lib/assert/context/setup_dsl.rb', line 30

def arounds
  @arounds ||= []
end

#run_arounds(scope, &run_block) ⇒ Object



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

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



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

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



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

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



20
21
22
# File 'lib/assert/context/setup_dsl.rb', line 20

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

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



4
5
6
# File 'lib/assert/context/setup_dsl.rb', line 4

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

#setupsObject



34
35
36
# File 'lib/assert/context/setup_dsl.rb', line 34

def setups
  @setups ||= []
end

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



25
26
27
# File 'lib/assert/context/setup_dsl.rb', line 25

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

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



10
11
12
# File 'lib/assert/context/setup_dsl.rb', line 10

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

#teardownsObject



38
39
40
# File 'lib/assert/context/setup_dsl.rb', line 38

def teardowns
  @teardowns ||= []
end