changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/example/configuration_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__) + '/../../spec_helper.rb'
2
3module Spec
4 module Example
5
6 describe Configuration do
7 before(:each) do
8 @config = Configuration.new
9 @example_group = mock("example_group")
10 end
11
12 describe "#mock_with" do
13
14 it "should default mock framework to rspec" do
15 @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rspec$/
16 end
17
18 it "should let you set rspec mocking explicitly" do
19 @config.mock_with(:rspec)
20 @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rspec$/
21 end
22
23 it "should let you set mocha" do
24 @config.mock_with(:mocha)
25 @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/mocha$/
26 end
27
28 it "should let you set flexmock" do
29 @config.mock_with(:flexmock)
30 @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/flexmock$/
31 end
32
33 it "should let you set rr" do
34 @config.mock_with(:rr)
35 @config.mock_framework.should =~ /\/plugins\/mock_frameworks\/rr$/
36 end
37
38 it "should let you set an arbitrary adapter module" do
39 adapter = Module.new
40 @config.mock_with(adapter)
41 @config.mock_framework.should == adapter
42 end
43 end
44
45 describe "#include" do
46
47 before do
48 @original_configuration = Spec::Runner.configuration
49 spec_configuration = @config
50 Spec::Runner.instance_eval {@configuration = spec_configuration}
51 @example_group_class = Class.new(ExampleGroup) do
52 class << self
53 def this_class_has_special_methods
54 end
55 end
56 end
57 ExampleGroupFactory.register(:foobar, @example_group_class)
58 end
59
60 after do
61 original_configuration = @original_configuration
62 Spec::Runner.instance_eval {@configuration = original_configuration}
63 ExampleGroupFactory.reset
64 end
65
66 it "should include the submitted module in ExampleGroup subclasses" do
67 mod = Module.new
68 @config.include mod
69 Class.new(@example_group_class).included_modules.should include(mod)
70 end
71
72 it "should let you define modules to be included for a specific type" do
73 mod = Module.new
74 @config.include mod, :type => :foobar
75 Class.new(@example_group_class).included_modules.should include(mod)
76 end
77
78 it "should not include modules in a type they are not intended for" do
79 mod = Module.new
80 @other_example_group_class = Class.new(ExampleGroup)
81 ExampleGroupFactory.register(:baz, @other_example_group_class)
82
83 @config.include mod, :type => :foobar
84
85 Class.new(@other_example_group_class).included_modules.should_not include(mod)
86 end
87
88 end
89
90 end
91
92 describe Configuration do
93
94 before(:each) do
95 @config = Configuration.new
96 @special_example_group = Class.new(ExampleGroup)
97 @special_child_example_group = Class.new(@special_example_group)
98 @nonspecial_example_group = Class.new(ExampleGroup)
99 ExampleGroupFactory.register(:special, @special_example_group)
100 ExampleGroupFactory.register(:special_child, @special_child_example_group)
101 ExampleGroupFactory.register(:non_special, @nonspecial_example_group)
102 @example_group = @special_child_example_group.describe "Special Example Group"
103 @unselected_example_group = Class.new(@nonspecial_example_group).describe "Non Special Example Group"
104 end
105
106 after(:each) do
107 ExampleGroupFactory.reset
108 end
109
110 describe "#prepend_before" do
111 it "prepends the before block on all instances of the passed in type" do
112 order = []
113 @config.prepend_before(:all) do
114 order << :prepend__before_all
115 end
116 @config.prepend_before(:all, :type => :special) do
117 order << :special_prepend__before_all
118 end
119 @config.prepend_before(:all, :type => :special_child) do
120 order << :special_child_prepend__before_all
121 end
122 @config.prepend_before(:each) do
123 order << :prepend__before_each
124 end
125 @config.prepend_before(:each, :type => :special) do
126 order << :special_prepend__before_each
127 end
128 @config.prepend_before(:each, :type => :special_child) do
129 order << :special_child_prepend__before_each
130 end
131 @config.prepend_before(:all, :type => :non_special) do
132 order << :special_prepend__before_all
133 end
134 @config.prepend_before(:each, :type => :non_special) do
135 order << :special_prepend__before_each
136 end
137 @example_group.it "calls prepend_before" do
138 end
139
140 @example_group.run
141 order.should == [
142 :prepend__before_all,
143 :special_prepend__before_all,
144 :special_child_prepend__before_all,
145 :prepend__before_each,
146 :special_prepend__before_each,
147 :special_child_prepend__before_each
148 ]
149 end
150 end
151
152 describe "#append_before" do
153
154 it "calls append_before on the type" do
155 order = []
156 @config.append_before(:all) do
157 order << :append_before_all
158 end
159 @config.append_before(:all, :type => :special) do
160 order << :special_append_before_all
161 end
162 @config.append_before(:all, :type => :special_child) do
163 order << :special_child_append_before_all
164 end
165 @config.append_before(:each) do
166 order << :append_before_each
167 end
168 @config.append_before(:each, :type => :special) do
169 order << :special_append_before_each
170 end
171 @config.append_before(:each, :type => :special_child) do
172 order << :special_child_append_before_each
173 end
174 @config.append_before(:all, :type => :non_special) do
175 order << :special_append_before_all
176 end
177 @config.append_before(:each, :type => :non_special) do
178 order << :special_append_before_each
179 end
180 @example_group.it "calls append_before" do
181 end
182
183 @example_group.run
184 order.should == [
185 :append_before_all,
186 :special_append_before_all,
187 :special_child_append_before_all,
188 :append_before_each,
189 :special_append_before_each,
190 :special_child_append_before_each
191 ]
192 end
193 end
194
195 describe "#prepend_after" do
196
197 it "prepends the after block on all instances of the passed in type" do
198 order = []
199 @config.prepend_after(:all) do
200 order << :prepend__after_all
201 end
202 @config.prepend_after(:all, :type => :special) do
203 order << :special_prepend__after_all
204 end
205 @config.prepend_after(:all, :type => :special) do
206 order << :special_child_prepend__after_all
207 end
208 @config.prepend_after(:each) do
209 order << :prepend__after_each
210 end
211 @config.prepend_after(:each, :type => :special) do
212 order << :special_prepend__after_each
213 end
214 @config.prepend_after(:each, :type => :special) do
215 order << :special_child_prepend__after_each
216 end
217 @config.prepend_after(:all, :type => :non_special) do
218 order << :special_prepend__after_all
219 end
220 @config.prepend_after(:each, :type => :non_special) do
221 order << :special_prepend__after_each
222 end
223 @example_group.it "calls prepend_after" do
224 end
225
226 @example_group.run
227 order.should == [
228 :special_child_prepend__after_each,
229 :special_prepend__after_each,
230 :prepend__after_each,
231 :special_child_prepend__after_all,
232 :special_prepend__after_all,
233 :prepend__after_all
234 ]
235 end
236 end
237
238 describe "#append_after" do
239
240 it "calls append_after on the type" do
241 order = []
242 @config.append_after(:all) do
243 order << :append__after_all
244 end
245 @config.append_after(:all, :type => :special) do
246 order << :special_append__after_all
247 end
248 @config.append_after(:all, :type => :special_child) do
249 order << :special_child_append__after_all
250 end
251 @config.append_after(:each) do
252 order << :append__after_each
253 end
254 @config.append_after(:each, :type => :special) do
255 order << :special_append__after_each
256 end
257 @config.append_after(:each, :type => :special_child) do
258 order << :special_child_append__after_each
259 end
260 @config.append_after(:all, :type => :non_special) do
261 order << :non_special_append_after_all
262 end
263 @config.append_after(:each, :type => :non_special) do
264 order << :non_special_append_after_each
265 end
266 @example_group.it "calls append_after" do
267 end
268
269 @example_group.run
270 order.should == [
271 :special_child_append__after_each,
272 :special_append__after_each,
273 :append__after_each,
274 :special_child_append__after_all,
275 :special_append__after_all,
276 :append__after_all
277 ]
278 end
279 end
280 end
281 end
282end