Skip to content

Commit

Permalink
Allow nested contexts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred committed Jul 8, 2013
1 parent 19fdd9c commit 7712547
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
65 changes: 65 additions & 0 deletions examples/008_nested_context_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# encoding: utf-8

require 'preamble'



describe "The" do
before do
@order = ['1']
end

it "has order" do
@order.should == %w(1)
end

describe "test" do
before do
@order << '2'
end

it "has order" do
@order.should == %w(1 2)
end

describe "framework" do
before do
@order << '3'
end

it "has order" do
@order.should == %w(1 2 3)
end

it "has order" do
@order.should == %w(1 2 3)
end
end

it "has order" do
@order.should == %w(1 2)
end
end
end

# We need to specs to run now, not at exit because we want to inspect
# the outcomes.

Peck.run

require 'assert'

assert(Peck.counter.ran == 5,
"Expected five specification to have been run")

assert(Peck.counter.passed == 5,
"Expected five specification to have passed")

assert(Peck.contexts[0].label == "The",
"Expected the title to be ‘The’")

assert(Peck.contexts[1].label == "The test",
"Expected the title to be ‘The test’")

assert(Peck.contexts[2].label == "The test framework",
"Expected the title to be ‘The test framework’")
4 changes: 2 additions & 2 deletions lib/peck/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def label
end

def describe(*description, &block)
if Peck.context_selector.match(Peck.join_description(*description))
init(@before, @after, *description, &block)
if Peck.context_selector.match(Peck.join_description(@description + description))
init(@before, @after, *(@description + description), &block)
end
end

Expand Down

1 comment on commit 7712547

@alloy
Copy link

@alloy alloy commented on 7712547 Jul 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo!

:shipit:

Please sign in to comment.