changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/story/step_group_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/story_helper'
2
3module Spec
4 module Story
5 describe StepGroup do
6 before(:each) do
7 @step_group = StepGroup.new
8 end
9
10 it "should not find a matcher if empty" do
11 @step_group.find(:given, "this and that").should be_nil
12 end
13
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)
18 end
19
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)
23 end
24
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)
28 end
29
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)
33 end
34
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)
39 end
40
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") {}
45 source.add_to target
46 target.find(:given, "this and that").should equal(step)
47 end
48
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") {}
59 source.add_to target
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)
67 end
68
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)
74 end
75
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)
85 end
86
87 it "should yield itself on initialization" do
88 begin
89 $step_group_spec_step = nil
90 matchers = StepGroup.new do |matchers|
91 $step_group_spec_step = matchers.given("foo") {}
92 end
93 $step_group_spec_step.matches?("foo").should be_true
94 ensure
95 $step_group_spec_step = nil
96 end
97 end
98
99 it "should support defaults" do
100 class StepGroupSubclass < StepGroup
101 steps do |add|
102 add.given("foo") {}
103 end
104 end
105 StepGroupSubclass.new.find(:given, "foo").should_not be_nil
106 end
107
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
112 end
113
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
118 end
119
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
124 end
125
126 it "should create steps in a block" do
127 sub = Class.new(StepGroup).new do
128 Given("a given") {}
129 When("a when") {}
130 Then("a then") {}
131 end
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
135 end
136
137 it "should clear itself" do
138 step = @step_group.given("this and that") {}
139 @step_group.clear
140 @step_group.find(:given, "this and that").should be_nil
141 end
142
143 it "should tell you when it is empty" do
144 @step_group.should be_empty
145 end
146
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
150 end
151
152 it "should handle << nil" do
153 @step_group << nil
154 end
155 end
156 end
157end