Module: NanoContexts

Extended by:
NanoContexts
Included in:
NanoContexts
Defined in:
lib/nanocontexts.rb

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Instance Method Details

#context(&block) ⇒ Object



6
7
8
9
10
11
# File 'lib/nanocontexts.rb', line 6

def context(&block)
  @contexts ||= []
  @contexts << Context.new
  instance_eval(&block)
  @contexts.pop
end

#setup(&block) ⇒ Object



13
14
15
# File 'lib/nanocontexts.rb', line 13

def setup(&block)
  @contexts.last.setup = block
end

#teardown(&block) ⇒ Object



17
18
19
# File 'lib/nanocontexts.rb', line 17

def teardown(&block)
  @contexts.last.teardown = block
end

#test(&block) ⇒ Object



21
22
23
24
25
# File 'lib/nanocontexts.rb', line 21

def test(&block)
  @contexts.map {|c| c.setup }.compact.each {|s| s.call }
  block.call
  @contexts.map {|c| c.teardown }.compact.each {|s| s.call }
end