1 require File.dirname(__FILE__) + '/story_helper'
7 @step_group = StepGroup.new
10 it "should not find a matcher if empty" do
11 @step_group.find(:given, "this and that").should be_nil
14 it "should create a given_scenario matcher" do
15 step = @step_group.given_scenario("this and that") {}
16 @step_group.find(:given_scenario, "this and that").should_not be_nil
17 @step_group.find(:given_scenario, "this and that").should equal(step)
20 it "should create a given matcher" do
21 step = @step_group.given("this and that") {}
22 @step_group.find(:given, "this and that").should equal(step)
25 it "should create a when matcher" do
26 step = @step_group.when("this and that") {}
27 @step_group.find(:when, "this and that").should equal(step)
30 it "should create a them matcher" do
31 step = @step_group.then("this and that") {}
32 @step_group.find(:then, "this and that").should equal(step)
35 it "should add a matcher object" do
36 step = Step.new("this and that") {}
37 @step_group.add(:given, step)
38 @step_group.find(:given, "this and that").should equal(step)
41 it "should add it matchers to another StepGroup (with one given)" do
42 source = StepGroup.new
43 target = StepGroup.new
44 step = source.given("this and that") {}
46 target.find(:given, "this and that").should equal(step)
49 it "should add it matchers to another StepGroup (with some of each type)" do
50 source = StepGroup.new
51 target = StepGroup.new
52 given_scenario = source.given_scenario("1") {}
53 given = source.given("1") {}
54 when1 = source.when("1") {}
55 when2 = source.when("2") {}
56 then1 = source.then("1") {}
57 then2 = source.then("2") {}
58 then3 = source.then("3") {}
60 target.find(:given_scenario, "1").should equal(given_scenario)
61 target.find(:given, "1").should equal(given)
62 target.find(:when, "1").should equal(when1)
63 target.find(:when, "2").should equal(when2)
64 target.find(:then, "1").should equal(then1)
65 target.find(:then, "2").should equal(then2)
66 target.find(:then, "3").should equal(then3)
69 it "should append another collection" do
70 matchers_to_append = StepGroup.new
71 step = matchers_to_append.given("this and that") {}
72 @step_group << matchers_to_append
73 @step_group.find(:given, "this and that").should equal(step)
76 it "should append several other collections" do
77 matchers_to_append = StepGroup.new
78 more_matchers_to_append = StepGroup.new
79 first_matcher = matchers_to_append.given("this and that") {}
80 second_matcher = more_matchers_to_append.given("and the other") {}
81 @step_group << matchers_to_append
82 @step_group << more_matchers_to_append
83 @step_group.find(:given, "this and that").should equal(first_matcher)
84 @step_group.find(:given, "and the other").should equal(second_matcher)
87 it "should yield itself on initialization" do
89 $step_group_spec_step = nil
90 matchers = StepGroup.new do |matchers|
91 $step_group_spec_step = matchers.given("foo") {}
93 $step_group_spec_step.matches?("foo").should be_true
95 $step_group_spec_step = nil
99 it "should support defaults" do
100 class StepGroupSubclass < StepGroup
105 StepGroupSubclass.new.find(:given, "foo").should_not be_nil
108 it "should create a Given" do
109 sub = Class.new(StepGroup).new
110 step = sub.Given("foo") {}
111 sub.find(:given, "foo").should == step
114 it "should create a When" do
115 sub = Class.new(StepGroup).new
116 step = sub.When("foo") {}
117 sub.find(:when, "foo").should == step
120 it "should create a Then" do
121 sub = Class.new(StepGroup).new
122 step = sub.Then("foo") {}
123 sub.find(:then, "foo").should == step
126 it "should create steps in a block" do
127 sub = Class.new(StepGroup).new do
132 sub.find(:given, "a given").should_not be_nil
133 sub.find(:when, "a when").should_not be_nil
134 sub.find(:then, "a then").should_not be_nil
137 it "should clear itself" do
138 step = @step_group.given("this and that") {}
140 @step_group.find(:given, "this and that").should be_nil
143 it "should tell you when it is empty" do
144 @step_group.should be_empty
147 it "should tell you when it is not empty" do
148 @step_group.given("this and that") {}
149 @step_group.should_not be_empty
152 it "should handle << nil" do