public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Revert ExampleGroup changes as they were causing failing specs

  Revert "Added render(template_path) feature to view specs."
  This reverts commit cb956ab7bb2de23752b600116e12f5c4cd63dd80.

  Revert "RSpec ExampleGroups for Merb controllers, views, helpers, 
  models and
  routes."
  This reverts commit 15abc4e56f1675c04414a5dce902baeee8453cd7.
ivey (author)
Tue Mar 25 23:00:21 -0700 2008
commit  6867c0b8c4f8a985b7e75c571be9aea9e077861e
tree    8a0a0b1e92fbb6b56ab040841967eaa651d3ab09
parent  cb956ab7bb2de23752b600116e12f5c4cd63dd80
...
8
9
10
11
12
...
8
9
10
 
 
0
@@ -8,6 +8,4 @@
0
 require 'merb-core/test/helpers'
0
 
0
 require 'merb-core/test/matchers'
0
-
0
-require 'merb-core/test/example_groups'
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,30 +1 @@
0
-# Based on Spec::Rails::Example from RSpec
0
-
0
-# Merb::Test::Rspec::Example extends Spec::Example (RSpec's core Example module)
0
-# to provide Merb-specific contexts for describing Merb Models, Views,
0
-# Controllers and Helpers.
0
-#
0
-# === Model Examples
0
-# See Merb::Test::Rspec::ModelExampleGroup.
0
-#
0
-# === Controller Examples
0
-# See Merb::Test::Rspec::ControllerExampleGroup.
0
-#
0
-# === View Examples
0
-# See Merb::Test::Rspec::ViewExampleGroup.
0
-#
0
-# === Helper Examples
0
-# See Merb::Test::Rspec::HelperExampleGroup.
0
-#
0
-# === Route Examples
0
-# See Merb::Test::Rspec::RouteExampleGroup.
0
-#
0
-module Merb::Test::Rspec::Example; end
0
-
0
-require "merb-core/test/example_groups/merb_example_group"
0
-require "merb-core/test/example_groups/model_example_group"
0
-require "merb-core/test/example_groups/controller_example_group"
0
-require "merb-core/test/example_groups/helper_example_group"
0
-require "merb-core/test/example_groups/view_example_group"
0
-require "merb-core/test/example_groups/route_example_group"
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,100 +1 @@
0
-# Based on Spec::Rails::Example::ControllerExampleGroup from RSpec
0
-
0
-module Merb::Test::Rspec::Example
0
- # Controller Specs live in spec/controllers/.
0
- #
0
- # Controller Specs use Merb::Test::Rspec::Example::ControllerExampleGroup.
0
- #
0
- # You MUST provide your controller's name within the context of your
0
- # controller specs. You can either do this by directly passing the
0
- # controller name to #describe:
0
- #
0
- # describe Accounts do
0
- # ...
0
- #
0
- # Or you can use #controller_name to declare the controller name
0
- # explicitly:
0
- #
0
- # describe "The Accounts Controller" do
0
- # controller_name 'accounts'
0
- # ...
0
- #
0
- # It is recommended to spec the controller completely independent of the
0
- # view. To do this you simply stub/mock the render method::
0
- #
0
- # describe Accounts, "show action" do
0
- # before(:each) do
0
- # dispatch(:show, :id => 42) do |controller|
0
- # controller.stub!(:render)
0
- # end
0
- # ...
0
- #
0
- # Combined w/ separate view specs, this also provides better fault
0
- # isolation.
0
- #
0
- class ControllerExampleGroup < MerbExampleGroup
0
- class << self
0
- def controller_name(name)
0
- @controller_class_name = "#{name}".camel_case
0
- end
0
- attr_accessor :controller_class_name # :nodoc:
0
- end
0
-
0
- include Merb::Test::Rspec::ControllerMatchers
0
-
0
- before(:each) do
0
- @controller_class = @controller_class_name.split('::').inject(Object) { |k,n| k.const_get n } rescue nil
0
- raise "Can't determine controller class for #{@controller_class_name}" if @controller_class.nil?
0
-
0
- unless @controller_class.ancestors.include?(::Merb::Controller)
0
- Spec::Expectations.fail_with <<-EOE
0
-You have to declare the controller name in controller specs. For example:
0
- describe "The Accounts Controller" do
0
- controller_name "accounts" #invokes the controller Accounts
0
- ...
0
- end
0
-EOE
0
- end
0
- end
0
-
0
- def initialize(defined_description, &implementation) #:nodoc:
0
- super
0
- if controller_class_name = self.class.controller_class_name
0
- @controller_class_name = controller_class_name.to_s
0
- elsif controller_class_name = self.class.superclass.controller_class_name
0
- self.class.controller_class_name = controller_class_name
0
- @controller_class_name = controller_class_name.to_s
0
- else
0
- @controller_class_name = self.class.described_type.to_s
0
- end
0
- end
0
-
0
- # Dispatches an action to the current class. This bypasses the router and is
0
- # suitable for unit testing of controllers.
0
- #
0
- # ==== Parameters
0
- # action<Symbol>:: The action name, as a symbol.
0
- # params<Hash>::
0
- # An optional hash that will end up as params in the controller instance.
0
- # env<Hash>::
0
- # An optional hash that is passed to the fake request. Any request options
0
- # should go here (see +fake_request+).
0
- # &blk::
0
- # The controller is yielded to the block provided for actions *prior* to
0
- # the action being dispatched.
0
- #
0
- # ==== Example
0
- # dispatch_to(:create, :name => 'Homer' ) do |controller|
0
- # controller.stub!(:current_user).and_return(@user)
0
- # end
0
- #
0
- #---
0
- # @public
0
- def dispatch(action = :index, params = {}, env = {}, &block)
0
- dispatch_to(@controller_class, action, params, env, &block)
0
- end
0
-
0
- Spec::Example::ExampleGroupFactory.register(:controller, self)
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,35 +1 @@
0
-# Based on Spec::Rails::Example::HelperExampleGroup from RSpec
0
-
0
-module Merb::Test::Rspec::Example
0
- # Helper Specs live in spec/helpers/.
0
- #
0
- # Helper Specs use Merb::Test::Rspec::Example::HelperExampleGroup, which
0
- # allows you to include your Helper directly in the context and write specs
0
- # directly against its methods.
0
- #
0
- # To automatically include a helper module into your spec, you pass the helper
0
- # name to #describe:
0
- #
0
- # describe Merb::ThingHelper do
0
- # ...
0
- #
0
- # ==== Example
0
- #
0
- # module Merb
0
- # module DeepThought
0
- # def ultimate_answer
0
- # 42
0
- # end
0
- # end
0
- # end
0
- #
0
- # describe Merb::DeepThought do
0
- # it "should tell you the answer to the ultimate question" do
0
- # ultimate_answer.should == 42
0
- # end
0
- # end
0
- class HelperExampleGroup < MerbExampleGroup
0
- Spec::Example::ExampleGroupFactory.register(:helper, self)
0
- end
0
-end
...
1
2
3
4
5
6
7
...
 
 
 
 
 
 
 
0
@@ -1,8 +1 @@
0
-module Merb::Test::Rspec::Example
0
- class MerbExampleGroup < Spec::ExampleGroup
0
- # include Merb::Test::Rspec::MerbMatchers
0
-
0
- Spec::Example::ExampleGroupFactory.default(self)
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
...
 
 
 
 
 
 
 
 
 
 
0
@@ -1,11 +1 @@
0
-# Based on Spec::Rails::Example::ModelExampleGroup from RSpec
0
-
0
-module Merb::Test::Rspec::Example
0
- # Model Specs live in spec/models/.
0
- #
0
- # Model Specs use Merb::Test::Rspec::Example::ModelExampleGroup.
0
- class ModelExampleGroup < MerbExampleGroup
0
- Spec::Example::ExampleGroupFactory.register(:model, self)
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
...
 
 
 
 
 
 
 
 
 
 
0
@@ -1,11 +1 @@
0
-module Merb::Test::Rspec::Example
0
- # Model Specs live in spec/route/.
0
- #
0
- # Model Specs use Merb::Test::Rspec::Example::RouteExampleGroup.
0
- class RouteExampleGroup < MerbExampleGroup
0
- include Merb::Test::Rspec::RouteMatchers
0
-
0
- Spec::Example::ExampleGroupFactory.register(:route, self)
0
- end
0
-end
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,53 +1 @@
0
-# Based on Spec::Rails::Example::ViewExampleGroup from RSpec
0
-
0
-module Merb::Test::Rspec::Example
0
- # View Specs live in spec/views/.
0
- #
0
- # View Specs use Merb::Test::Rspec::Example::ViewExampleGroup, which provides
0
- # access to views without invoking any of your controllers.
0
- #
0
- # ==== Example
0
- #
0
- # describe "articles/show.html" do
0
- # before do
0
- # article = mock('article')
0
- # article.stub!(:title) = "FooBar"
0
- # article.stub!(:body) = "Lorem Ipsum..."
0
- # assign[:article] = article
0
- # render 'articles/index.html', :helper => Merb::ArticlesHelper
0
- # end
0
- #
0
- # it "should display the title" do
0
- # body.should include('<h1>FooBar</h1>')
0
- # end
0
- #
0
- # ...
0
- # end
0
- #
0
- class ViewExampleGroup < MerbExampleGroup
0
- include Merb::Test::Rspec::ViewMatchers
0
-
0
- def render(template_path, opts={})
0
- klass = Class.new(Merb::Controller)
0
- controller = klass.new(FakeRequest.new)
0
- assigns.each do |key, value|
0
- controller.instance_variable_set("@#{key.to_s}", value)
0
- end
0
- opts[:helpers] ||= [opts[:helper]].compact
0
- opts[:helpers].each { |helper| klass.send(:include, helper) }
0
- method, location = controller._template_for(nil, nil, nil, :template => template_path)
0
- @_body = controller.send(method)
0
- end
0
-
0
- def body; @_body; end
0
-
0
- def assigns; @_assigns ||= Mash.new; end
0
-
0
- Spec::Example::ExampleGroupFactory.register(:view, self)
0
- end
0
-
0
- class Merb::Controller
0
- def self.to_s; "ViewExampleController"; end
0
- end
0
-end
...
3
4
5
 
 
 
 
...
3
4
5
6
7
8
9
0
@@ -3,4 +3,8 @@
0
 require "merb-core/test/matchers/controller_matchers"
0
 require "merb-core/test/matchers/route_matchers"
0
 require "merb-core/test/matchers/view_matchers"
0
+
0
+Merb::Test::ControllerHelper.send(:include, Merb::Test::Rspec::ControllerMatchers)
0
+Merb::Test::RouteHelper.send(:include, Merb::Test::Rspec::RouteMatchers)
0
+Merb::Test::ViewHelper.send(:include, Merb::Test::Rspec::ViewMatchers)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
0
@@ -1 +1,379 @@
0
+require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
0
+
0
+Merb.start :environment => 'test', :log_level => :fatal
0
+
0
+class TestController < Merb::Controller
0
+ attr_accessor :redirect_to
0
+ def redirect_action; redirect(@redirect_to || "/"); end
0
+ def success_action; end
0
+ def missing_action; render("i can has errorz", :status => 404); end
0
+end
0
+
0
+describe Merb::Test::Rspec::ControllerMatchers do
0
+ include Merb::Test::ControllerHelper
0
+ before(:each) do
0
+ Merb::Router.prepare do |r|
0
+ r.match("/redirect").to(:controller => "test_controller", :action => "redirect_action")
0
+ r.match("/success").to(:controller => "test_controller", :action => "success_action")
0
+ r.match("/missing").to(:controller => "test_controller", :action => "missing_action")
0
+ end
0
+ end
0
+
0
+ describe "#redirect" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :redirect_action).should redirect
0
+ end
0
+
0
+ it "should work with the result of a get helper call" do
0
+ get("/redirect").should redirect
0
+ end
0
+
0
+ it "should work with a redirection code" do
0
+ dispatch_to(TestController, :redirect_action).status.should redirect
0
+ end
0
+ end
0
+
0
+ describe "#redirect_to" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :redirect_action).should redirect_to("/")
0
+ dispatch_to(TestController, :redirect_action){ |controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
0
+ end
0
+
0
+ it "should work with the result of a get helper call" do
0
+ get("/redirect"){|controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
0
+ end
0
+ end
0
+
0
+ describe "#respond_successfully" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :success_action).should respond_successfully
0
+ end
0
+
0
+ it "should work with the result of a get helper call" do
0
+ get("/success").should respond_successfully
0
+ end
0
+
0
+ it "should work with a redirection code" do
0
+ dispatch_to(TestController, :success_action).status.should be_successful
0
+ end
0
+ end
0
+
0
+ describe "#be_missing" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :missing_action).should be_missing
0
+ end
0
+
0
+ it "should work with the result of a get helper call" do
0
+ get("/missing").should be_client_error
0
+ end
0
+
0
+ it "should work with a redirection code" do
0
+ dispatch_to(TestController, :missing_action).status.should be_missing
0
+ end
0
+ end
0
+end
0
+
0
+module Merb::Test::Rspec
0
+ module ControllerMatchers
0
+ class RedirectableTarget
0
+ attr_accessor :status, :headers
0
+ def initialize; @headers = {}; end
0
+ end
0
+
0
+ describe BeRedirect do
0
+ before(:each) do
0
+ @target = RedirectableTarget.new
0
+ end
0
+
0
+ it "should match a 301 'Moved Permanently' redirect code" do
0
+ BeRedirect.new.matches?(301).should be_true
0
+ end
0
+
0
+ it "should match a 302 'Found' redirect code" do
0
+ BeRedirect.new.matches?(302).should be_true
0
+ end
0
+
0
+ it "should match a 303 'See Other' redirect code" do
0
+ BeRedirect.new.matches?(303).should be_true
0
+ end
0
+
0
+ it "should match a 304 'Not Modified' redirect code" do
0
+ BeRedirect.new.matches?(304).should be_true
0
+ end
0
+
0
+ it "should match a 307 'Temporary Redirect' redirect code" do
0
+ BeRedirect.new.matches?(307).should be_true
0
+ end
0
+
0
+ it "should match a target with a valid redirect code" do
0
+ @target.status = 301
0
+
0
+ BeRedirect.new.matches?(@target).should be_true
0
+ end
0
+
0
+ it "should not match a target with an unused redirect code" do
0
+ @target.status = 399
0
+
0
+ BeRedirect.new.matches?(@target).should_not be_true
0
+ end
0
+
0
+ it "should not match a target with a non redirect code" do
0
+ @target.status = 200
0
+
0
+ BeRedirect.new.matches?(@target).should_not be_true
0
+ end
0
+
0
+ describe "#failure_message" do
0
+ it "should be 'expected to redirect' when the target is a status code" do
0
+ matcher = BeRedirect.new
0
+ matcher.matches?(200)
0
+ matcher.failure_message.should == "expected to redirect"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar to redirect' when the target's controller is Foo and action is bar" do
0
+ matcher = BeRedirect.new
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to redirect"
0
+ end
0
+ end
0
+
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected not to redirect' when the target is a status code" do
0
+ matcher = BeRedirect.new
0
+ matcher.matches?(200)
0
+ matcher.negative_failure_message.should == "expected not to redirect"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar to redirect' when the target's controller is Foo and action is bar" do
0
+ matcher = BeRedirect.new
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to redirect"
0
+ end
0
+ end
0
+ end
0
+
0
+ describe RedirectTo do
0
+ before(:each) do
0
+ @target = RedirectableTarget.new
0
+ end
0
+
0
+ it "should match a target if the status code is 300 level and the locations match" do
0
+ @target.status = 301
0
+ @target.headers['Location'] = "http://example.com/"
0
+
0
+ RedirectTo.new("http://example.com/").matches?(@target).should be_true
0
+ end
0
+
0
+ it "should not match a target if the status code is not 300 level but the locations match" do
0
+ @target.status = 404
0
+ @target.headers['Location'] = "http://example.com/"
0
+
0
+ RedirectTo.new("http://example.com/").matches?(@target).should_not be_true
0
+ end
0
+
0
+ it "should not match a target if the status code is 300 level but the locations do not match" do
0
+ @target.status = 301
0
+ @target.headers['Location'] = "http://merbivore.com/"
0
+
0
+ RedirectTo.new("http://example.com/").matches?(@target).should_not be_true
0
+ end
0
+
0
+ describe "#failure_message" do
0
+ it "should be 'expected Foo#bar to redirect to <http://expected.com/>, but was <http://target.com/>' when the expected url is http://expected.com/ and the target url is http://target.com/" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 301
0
+ @target.headers['Location'] = "http://target.com/"
0
+ matcher = RedirectTo.new("http://expected.com/")
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to redirect to <http://expected.com/>, but was <http://target.com/>"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar to redirect, but there was no redirection' when the target is not redirected" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 200
0
+ @target.headers['Location'] = "http://target.com/"
0
+ matcher = RedirectTo.new("http://expected.com/")
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to redirect to <http://expected.com/>, but there was no redirection"
0
+ end
0
+ end
0
+
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected Foo#bar not to redirect to <http://expected.com/>, but it did anyways" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 200
0
+ @target.headers['Location'] = "http://target.com/"
0
+ matcher = RedirectTo.new("http://expected.com/")
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to redirect to <http://expected.com/>, but did anyway"
0
+ end
0
+ end
0
+ end
0
+
0
+ describe BeSuccess do
0
+ before(:each) do
0
+ @target = RedirectableTarget.new
0
+ end
0
+
0
+ it "should match a target with a 200 'OK' status code" do
0
+ BeSuccess.new.matches?(200).should be_true
0
+ end
0
+
0
+ it "should match a target with a 201 'Created' status code" do
0
+ BeSuccess.new.matches?(201).should be_true
0
+ end
0
+
0
+ it "should match a target with a 202 'Accepted' status code" do
0
+ BeSuccess.new.matches?(202).should be_true
0
+ end
0
+
0
+ it "should match a target with a 203 'Non-Authoritative Information' status code" do
0
+ BeSuccess.new.matches?(203).should be_true
0
+ end
0
+
0
+ it "should match a target with a 204 'No Content' status code" do
0
+ BeSuccess.new.matches?(204).should be_true
0
+ end
0
+
0
+ it "should match a target with a 205 'Reset Content' status code" do
0
+ BeSuccess.new.matches?(205).should be_true
0
+ end
0
+
0
+ it "should match a target with a 206 'Partial Content' status code" do
0
+ BeSuccess.new.matches?(206).should be_true
0
+ end
0
+
0
+ it "should match a target with a 207 'Multi-Status' status code" do
0
+ BeSuccess.new.matches?(207).should be_true
0
+ end
0
+
0
+ it "should not match a target with an unused 200 level status code" do
0
+ BeSuccess.new.matches?(299).should_not be_true
0
+ end
0
+
0
+ it "should not match a target with a non 200 level status code" do
0
+ BeSuccess.new.matches?(301).should_not be_true
0
+ end
0
+
0
+ describe "#failure_message" do
0
+ it "should be 'expected to be successful but was 300' when the target is status code 300" do
0
+ matcher = BeSuccess.new
0
+ matcher.matches?(300)
0
+ matcher.failure_message.should == "expected to be successful but was 300"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar to be successful but was 404' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 404
0
+ matcher = BeSuccess.new
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to be successful but was 404"
0
+ end
0
+ end
0
+
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected not to be successful but it was' when the target is a 200 status code" do
0
+ matcher = BeSuccess.new
0
+ matcher.matches?(200)
0
+ matcher.negative_failure_message.should == "expected not to be successful but it was 200"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar not to be successful but it was 200' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 200
0
+ matcher = BeSuccess.new
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to be successful but it was 200"
0
+ end
0
+ end
0
+ end
0
+
0
+ describe BeMissing do
0
+ before(:each) do
0
+ @target = RedirectableTarget.new
0
+ end
0
+
0
+ it "should match a 400 'Bad Request'" do
0
+ BeMissing.new.matches?(400).should be_true
0
+ end
0
+
0
+ it "should match a 401 'Unauthorized'" do
0
+ BeMissing.new.matches?(401).should be_true
0
+ end
0
+
0
+ it "should match a 403 'Forbidden'" do
0
+ BeMissing.new.matches?(403).should be_true
0
+ end
0
+
0
+ it "should match a 404 'Not Found'" do
0
+ BeMissing.new.matches?(404).should be_true
0
+ end
0
+
0
+ it "should match a 409 'Conflict'" do
0
+ BeMissing.new.matches?(409).should be_true
0
+ end
0
+
0
+ it "should match a target with a valid client side error code" do
0
+ @target.status = 404
0
+
0
+ BeMissing.new.matches?(@target).should be_true
0
+ end
0
+
0
+ it "should not match a target with an unused client side error code" do
0
+ @target.status = 499
0
+
0
+ BeMissing.new.matches?(@target).should_not be_true
0
+ end
0
+
0
+ it "should not match a target with a non client side error code" do
0
+ @target.status = 200
0
+
0
+ BeMissing.new.matches?(@target).should_not be_true
0
+ end
0
+
0
+ describe "#failure_message" do
0
+ it "should be 'expected to be missing but was 300' when the target is status code 300" do
0
+ matcher = BeMissing.new
0
+ matcher.matches?(300)
0
+ matcher.failure_message.should == "expected to be missing but was 300"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar to be successful but was 301' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 301
0
+ matcher = BeMissing.new
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to be missing but was 301"
0
+ end
0
+ end
0
+
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected not to be successful but it was' when the target is a 400 status code" do
0
+ matcher = BeMissing.new
0
+ matcher.matches?(400)
0
+ matcher.negative_failure_message.should == "expected not to be missing but it was 400"
0
+ end
0
+
0
+ it "should be 'expected Foo#bar not to be missing but it was 404' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.status = 404
0
+ matcher = BeMissing.new
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to be missing but it was 404"
0
+ end
0
+ end
0
+ end
0
+ end
0
+end