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


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

def around(&block)
  arounds << block
end

#aroundsObject


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

def arounds
  @arounds ||= []
end

#run_arounds(scope, &run_block) ⇒ Object


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

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

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

#run_setups(scope) ⇒ Object


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

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

#run_teardowns(scope) ⇒ Object


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/assert/context/setup_dsl.rb', line 67

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

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


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

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

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


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

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

#setupsObject


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

def setups
  @setups ||= []
end

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


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

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

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


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

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

#teardownsObject


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

def teardowns
  @teardowns ||= []
end