rspec-rails 2.14.1 → 2.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +9 -0
- data/lib/autotest/rails_rspec2.rb +1 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +6 -1
- data/lib/rspec/rails/adapters.rb +1 -0
- data/lib/rspec/rails/example/controller_example_group.rb +2 -1
- data/lib/rspec/rails/matchers/have_extension.rb +1 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +4 -0
- data/lib/rspec/rails/mocks.rb +6 -0
- data/lib/rspec/rails/tasks/rspec.rake +12 -5
- data/lib/rspec/rails/version.rb +1 -1
- metadata +38 -214
- data/features/Autotest.md +0 -24
- data/features/Generators.md +0 -24
- data/features/GettingStarted.md +0 -84
- data/features/README.md +0 -56
- data/features/RailsVersions.md +0 -4
- data/features/Transactions.md +0 -84
- data/features/Upgrade.md +0 -121
- data/features/controller_specs/Cookies.md +0 -57
- data/features/controller_specs/README.md +0 -45
- data/features/controller_specs/anonymous_controller.feature +0 -378
- data/features/controller_specs/bypass_rescue.feature +0 -75
- data/features/controller_specs/controller_spec.feature +0 -58
- data/features/controller_specs/engine_routes.feature +0 -51
- data/features/controller_specs/isolation_from_views.feature +0 -87
- data/features/controller_specs/render_views.feature +0 -114
- data/features/feature_specs/feature_spec.feature +0 -34
- data/features/helper_specs/helper_spec.feature +0 -122
- data/features/mailer_specs/url_helpers.feature +0 -38
- data/features/matchers/README.md +0 -18
- data/features/matchers/new_record_matcher.feature +0 -41
- data/features/matchers/redirect_to_matcher.feature +0 -40
- data/features/matchers/relation_match_array.feature +0 -27
- data/features/matchers/render_template_matcher.feature +0 -49
- data/features/mocks/mock_model.feature +0 -147
- data/features/mocks/stub_model.feature +0 -58
- data/features/model_specs/README.md +0 -21
- data/features/model_specs/errors_on.feature +0 -51
- data/features/model_specs/records.feature +0 -27
- data/features/model_specs/transactional_examples.feature +0 -109
- data/features/request_specs/request_spec.feature +0 -49
- data/features/routing_specs/README.md +0 -16
- data/features/routing_specs/be_routable_matcher.feature +0 -80
- data/features/routing_specs/engine_routes.feature +0 -38
- data/features/routing_specs/named_routes.feature +0 -18
- data/features/routing_specs/route_to_matcher.feature +0 -90
- data/features/step_definitions/additional_cli_steps.rb +0 -4
- data/features/step_definitions/model_steps.rb +0 -3
- data/features/support/env.rb +0 -53
- data/features/support/rails_versions.rb +0 -4
- data/features/support/rubinius.rb +0 -6
- data/features/view_specs/inferred_controller_path.feature +0 -45
- data/features/view_specs/stub_template.feature +0 -51
- data/features/view_specs/view_spec.feature +0 -206
- data/spec/autotest/rails_rspec2_spec.rb +0 -36
- data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
- data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
- data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
- data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -44
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
- data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
- data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
- data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
- data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
- data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
- data/spec/rspec/rails/configuration_spec.rb +0 -26
- data/spec/rspec/rails/deprecations_spec.rb +0 -18
- data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -100
- data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
- data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -64
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
- data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
- data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
- data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
- data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
- data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
- data/spec/rspec/rails/fixture_support_spec.rb +0 -17
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
- data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
- data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -44
- data/spec/rspec/rails/matchers/errors_on_spec.rb +0 -38
- data/spec/rspec/rails/matchers/has_spec.rb +0 -29
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -80
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
- data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
- data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -401
- data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
- data/spec/rspec/rails/view_rendering_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -32
- data/spec/support/ar_classes.rb +0 -42
- data/spec/support/helpers.rb +0 -34
- data/spec/support/matchers.rb +0 -9
- data/spec/support/null_object.rb +0 -6
@@ -1,45 +0,0 @@
|
|
1
|
-
Controller specs live in `spec/controllers` or any example group with
|
2
|
-
`:type => :controller`.
|
3
|
-
|
4
|
-
A controller spec is an RSpec wrapper for a Rails functional test
|
5
|
-
([ActionController::TestCase::Behavior](https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb)).
|
6
|
-
It allows you to simulate a single http request in each example, and then
|
7
|
-
specify expected outcomes such as:
|
8
|
-
|
9
|
-
* rendered templates
|
10
|
-
* redirects
|
11
|
-
* instance variables assigned in the controller to be shared with the view
|
12
|
-
* cookies sent back with the response
|
13
|
-
|
14
|
-
To specify outcomes, you can use:
|
15
|
-
|
16
|
-
* standard rspec matchers (`expect(response.status).to eq(200)`)
|
17
|
-
* standard test/unit assertions (`assert_equal 200, response.status`)
|
18
|
-
* rails assertions (`assert_response 200`)
|
19
|
-
* rails-specific matchers:
|
20
|
-
* `expect(response).to render_template(wraps assert_template)`
|
21
|
-
* `expect(response).to redirect_to(wraps assert_redirected_to)`
|
22
|
-
* `expect(assigns(:widget)).to be_a_new(Widget)`
|
23
|
-
|
24
|
-
## Examples
|
25
|
-
|
26
|
-
describe TeamsController do
|
27
|
-
describe "GET index" do
|
28
|
-
it "assigns @teams" do
|
29
|
-
team = Team.create
|
30
|
-
get :index
|
31
|
-
expect(assigns(:teams)).to eq([team])
|
32
|
-
end
|
33
|
-
|
34
|
-
it "renders the index template" do
|
35
|
-
get :index
|
36
|
-
expect(response).to render_template("index")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
## Views
|
42
|
-
|
43
|
-
* by default, views are not rendered. See
|
44
|
-
[views are stubbed by default](controller-specs/views-are-stubbed-by-default) and
|
45
|
-
[render_views](controller-specs/render-views) for details.
|
@@ -1,378 +0,0 @@
|
|
1
|
-
Feature: anonymous controller
|
2
|
-
|
3
|
-
Use the `controller` method to define an anonymous controller derived from
|
4
|
-
`ApplicationController`. This is useful for specifying behavior like global
|
5
|
-
error handling.
|
6
|
-
|
7
|
-
To specify a different base class, you can pass the class explicitly to the
|
8
|
-
controller method:
|
9
|
-
|
10
|
-
controller(BaseController)
|
11
|
-
|
12
|
-
You can also configure RSpec to use the described class:
|
13
|
-
|
14
|
-
RSpec.configure do |c|
|
15
|
-
c.infer_base_class_for_anonymous_controllers = true
|
16
|
-
end
|
17
|
-
|
18
|
-
describe BaseController do
|
19
|
-
controller { ... }
|
20
|
-
# ^^ creates an anonymous subclass of `BaseController`
|
21
|
-
|
22
|
-
Scenario: specify error handling in ApplicationController
|
23
|
-
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
24
|
-
"""ruby
|
25
|
-
require "spec_helper"
|
26
|
-
|
27
|
-
class ApplicationController < ActionController::Base
|
28
|
-
class AccessDenied < StandardError; end
|
29
|
-
|
30
|
-
rescue_from AccessDenied, :with => :access_denied
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def access_denied
|
35
|
-
redirect_to "/401.html"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe ApplicationController do
|
40
|
-
controller do
|
41
|
-
def index
|
42
|
-
raise ApplicationController::AccessDenied
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "handling AccessDenied exceptions" do
|
47
|
-
it "redirects to the /401.html page" do
|
48
|
-
get :index
|
49
|
-
expect(response).to redirect_to("/401.html")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
"""
|
54
|
-
When I run `rspec spec`
|
55
|
-
Then the examples should all pass
|
56
|
-
|
57
|
-
Scenario: specify error handling in subclass of ApplicationController
|
58
|
-
Given a file named "spec/controllers/application_controller_subclass_spec.rb" with:
|
59
|
-
"""ruby
|
60
|
-
require "spec_helper"
|
61
|
-
|
62
|
-
class ApplicationController < ActionController::Base
|
63
|
-
class AccessDenied < StandardError; end
|
64
|
-
end
|
65
|
-
|
66
|
-
class ApplicationControllerSubclass < ApplicationController
|
67
|
-
|
68
|
-
rescue_from ApplicationController::AccessDenied, :with => :access_denied
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def access_denied
|
73
|
-
redirect_to "/401.html"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe ApplicationControllerSubclass do
|
78
|
-
controller(ApplicationControllerSubclass) do
|
79
|
-
def index
|
80
|
-
raise ApplicationController::AccessDenied
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "handling AccessDenied exceptions" do
|
85
|
-
it "redirects to the /401.html page" do
|
86
|
-
get :index
|
87
|
-
expect(response).to redirect_to("/401.html")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
"""
|
92
|
-
When I run `rspec spec`
|
93
|
-
Then the examples should all pass
|
94
|
-
|
95
|
-
Scenario: infer base class from the described class
|
96
|
-
Given a file named "spec/controllers/base_class_can_be_inferred_spec.rb" with:
|
97
|
-
"""ruby
|
98
|
-
require "spec_helper"
|
99
|
-
|
100
|
-
RSpec.configure do |c|
|
101
|
-
c.infer_base_class_for_anonymous_controllers = true
|
102
|
-
end
|
103
|
-
|
104
|
-
class ApplicationController < ActionController::Base; end
|
105
|
-
|
106
|
-
class ApplicationControllerSubclass < ApplicationController; end
|
107
|
-
|
108
|
-
describe ApplicationControllerSubclass do
|
109
|
-
controller do
|
110
|
-
def index
|
111
|
-
render :text => "Hello World"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "creates an anonymous controller derived from ApplicationControllerSubclass" do
|
116
|
-
expect(controller).to be_a_kind_of(ApplicationControllerSubclass)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
"""
|
120
|
-
When I run `rspec spec`
|
121
|
-
Then the examples should all pass
|
122
|
-
|
123
|
-
Scenario: invoke around filter in base class
|
124
|
-
Given a file named "spec/controllers/application_controller_around_filter_spec.rb" with:
|
125
|
-
"""ruby
|
126
|
-
require "spec_helper"
|
127
|
-
|
128
|
-
class ApplicationController < ActionController::Base
|
129
|
-
around_filter :an_around_filter
|
130
|
-
|
131
|
-
def an_around_filter
|
132
|
-
@callback_invoked = true
|
133
|
-
yield
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe ApplicationController do
|
138
|
-
controller do
|
139
|
-
def index
|
140
|
-
render :nothing => true
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
it "invokes the callback" do
|
145
|
-
get :index
|
146
|
-
|
147
|
-
expect(assigns[:callback_invoked]).to be_true
|
148
|
-
end
|
149
|
-
end
|
150
|
-
"""
|
151
|
-
When I run `rspec spec`
|
152
|
-
Then the examples should all pass
|
153
|
-
|
154
|
-
Scenario: anonymous controllers only create resource routes
|
155
|
-
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
156
|
-
"""ruby
|
157
|
-
require "spec_helper"
|
158
|
-
|
159
|
-
describe ApplicationController do
|
160
|
-
controller do
|
161
|
-
def index
|
162
|
-
render :text => "index called"
|
163
|
-
end
|
164
|
-
|
165
|
-
def create
|
166
|
-
render :text => "create called"
|
167
|
-
end
|
168
|
-
|
169
|
-
def new
|
170
|
-
render :text => "new called"
|
171
|
-
end
|
172
|
-
|
173
|
-
def show
|
174
|
-
render :text => "show called"
|
175
|
-
end
|
176
|
-
|
177
|
-
def edit
|
178
|
-
render :text => "edit called"
|
179
|
-
end
|
180
|
-
|
181
|
-
def update
|
182
|
-
render :text => "update called"
|
183
|
-
end
|
184
|
-
|
185
|
-
def destroy
|
186
|
-
render :text => "destroy called"
|
187
|
-
end
|
188
|
-
|
189
|
-
def willerror
|
190
|
-
render :text => "will not render"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe "#index" do
|
195
|
-
it "responds to GET" do
|
196
|
-
get :index
|
197
|
-
expect(response.body).to eq "index called"
|
198
|
-
end
|
199
|
-
|
200
|
-
it "also responds to POST" do
|
201
|
-
post :index
|
202
|
-
expect(response.body).to eq "index called"
|
203
|
-
end
|
204
|
-
|
205
|
-
it "also responds to PUT" do
|
206
|
-
put :index
|
207
|
-
expect(response.body).to eq "index called"
|
208
|
-
end
|
209
|
-
|
210
|
-
it "also responds to DELETE" do
|
211
|
-
delete :index
|
212
|
-
expect(response.body).to eq "index called"
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "#create" do
|
217
|
-
it "responds to POST" do
|
218
|
-
post :create
|
219
|
-
expect(response.body).to eq "create called"
|
220
|
-
end
|
221
|
-
|
222
|
-
# And the rest...
|
223
|
-
%w{get post put delete}.each do |calltype|
|
224
|
-
it "responds to #{calltype}" do
|
225
|
-
send(calltype, :create)
|
226
|
-
expect(response.body).to eq "create called"
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe "#new" do
|
232
|
-
it "responds to GET" do
|
233
|
-
get :new
|
234
|
-
expect(response.body).to eq "new called"
|
235
|
-
end
|
236
|
-
|
237
|
-
# And the rest...
|
238
|
-
%w{get post put delete}.each do |calltype|
|
239
|
-
it "responds to #{calltype}" do
|
240
|
-
send(calltype, :new)
|
241
|
-
expect(response.body).to eq "new called"
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "#edit" do
|
247
|
-
it "responds to GET" do
|
248
|
-
get :edit, :id => "anyid"
|
249
|
-
expect(response.body).to eq "edit called"
|
250
|
-
end
|
251
|
-
|
252
|
-
it "requires the :id parameter" do
|
253
|
-
expect { get :edit }.to raise_error(ActionController::RoutingError)
|
254
|
-
end
|
255
|
-
|
256
|
-
# And the rest...
|
257
|
-
%w{get post put delete}.each do |calltype|
|
258
|
-
it "responds to #{calltype}" do
|
259
|
-
send(calltype, :edit, {:id => "anyid"})
|
260
|
-
expect(response.body).to eq "edit called"
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe "#show" do
|
266
|
-
it "responds to GET" do
|
267
|
-
get :show, :id => "anyid"
|
268
|
-
expect(response.body).to eq "show called"
|
269
|
-
end
|
270
|
-
|
271
|
-
it "requires the :id parameter" do
|
272
|
-
expect { get :show }.to raise_error(ActionController::RoutingError)
|
273
|
-
end
|
274
|
-
|
275
|
-
# And the rest...
|
276
|
-
%w{get post put delete}.each do |calltype|
|
277
|
-
it "responds to #{calltype}" do
|
278
|
-
send(calltype, :show, {:id => "anyid"})
|
279
|
-
expect(response.body).to eq "show called"
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
describe "#update" do
|
285
|
-
it "responds to PUT" do
|
286
|
-
put :update, :id => "anyid"
|
287
|
-
expect(response.body).to eq "update called"
|
288
|
-
end
|
289
|
-
|
290
|
-
it "requires the :id parameter" do
|
291
|
-
expect { put :update }.to raise_error(ActionController::RoutingError)
|
292
|
-
end
|
293
|
-
|
294
|
-
# And the rest...
|
295
|
-
%w{get post put delete}.each do |calltype|
|
296
|
-
it "responds to #{calltype}" do
|
297
|
-
send(calltype, :update, {:id => "anyid"})
|
298
|
-
expect(response.body).to eq "update called"
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
describe "#destroy" do
|
304
|
-
it "responds to DELETE" do
|
305
|
-
delete :destroy, :id => "anyid"
|
306
|
-
expect(response.body).to eq "destroy called"
|
307
|
-
end
|
308
|
-
|
309
|
-
it "requires the :id parameter" do
|
310
|
-
expect { delete :destroy }.to raise_error(ActionController::RoutingError)
|
311
|
-
end
|
312
|
-
|
313
|
-
# And the rest...
|
314
|
-
%w{get post put delete}.each do |calltype|
|
315
|
-
it "responds to #{calltype}" do
|
316
|
-
send(calltype, :destroy, {:id => "anyid"})
|
317
|
-
expect(response.body).to eq "destroy called"
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
describe "#willerror" do
|
323
|
-
it "cannot be called" do
|
324
|
-
expect { get :willerror }.to raise_error(ActionController::RoutingError)
|
325
|
-
end
|
326
|
-
end
|
327
|
-
end
|
328
|
-
"""
|
329
|
-
When I run `rspec spec`
|
330
|
-
Then the examples should all pass
|
331
|
-
|
332
|
-
Scenario: draw custom routes for anonymous controllers
|
333
|
-
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
334
|
-
"""ruby
|
335
|
-
require "spec_helper"
|
336
|
-
|
337
|
-
describe ApplicationController do
|
338
|
-
controller do
|
339
|
-
def custom
|
340
|
-
render :text => "custom called"
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
specify "a custom action can be requested if routes are drawn manually" do
|
345
|
-
routes.draw { get "custom" => "anonymous#custom" }
|
346
|
-
|
347
|
-
get :custom
|
348
|
-
expect(response.body).to eq "custom called"
|
349
|
-
end
|
350
|
-
end
|
351
|
-
"""
|
352
|
-
When I run `rspec spec`
|
353
|
-
Then the examples should all pass
|
354
|
-
|
355
|
-
Scenario: refer to application routes in the controller under test
|
356
|
-
Given a file named "spec/controllers/application_controller_spec.rb" with:
|
357
|
-
"""ruby
|
358
|
-
require "spec_helper"
|
359
|
-
|
360
|
-
Rails.application.routes.draw do
|
361
|
-
match "/login" => "sessions#new", :as => "login", :via => "get"
|
362
|
-
end
|
363
|
-
|
364
|
-
describe ApplicationController do
|
365
|
-
controller do
|
366
|
-
def index
|
367
|
-
redirect_to login_url
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
it "redirects to the login page" do
|
372
|
-
get :index
|
373
|
-
expect(response).to redirect_to("/login")
|
374
|
-
end
|
375
|
-
end
|
376
|
-
"""
|
377
|
-
When I run `rspec spec`
|
378
|
-
Then the examples should all pass
|
@@ -1,75 +0,0 @@
|
|
1
|
-
Feature: bypass rescue
|
2
|
-
|
3
|
-
Use `bypass_rescue` to bypass both Rails' default handling of errors in
|
4
|
-
controller actions, and any custom handling declared with a `rescue_from`
|
5
|
-
statement.
|
6
|
-
|
7
|
-
This lets you specify details of the exception being raised, regardless of
|
8
|
-
how it might be handled upstream.
|
9
|
-
|
10
|
-
Background:
|
11
|
-
Given a file named "spec/controllers/gadgets_controller_spec_context.rb" with:
|
12
|
-
"""ruby
|
13
|
-
class AccessDenied < StandardError; end
|
14
|
-
|
15
|
-
class ApplicationController < ActionController::Base
|
16
|
-
rescue_from AccessDenied, :with => :access_denied
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def access_denied
|
21
|
-
redirect_to "/401.html"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
"""
|
25
|
-
|
26
|
-
Scenario: standard exception handling using `rescue_from`
|
27
|
-
Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
|
28
|
-
"""ruby
|
29
|
-
require "spec_helper"
|
30
|
-
|
31
|
-
require 'controllers/gadgets_controller_spec_context'
|
32
|
-
|
33
|
-
describe GadgetsController do
|
34
|
-
before do
|
35
|
-
def controller.index
|
36
|
-
raise AccessDenied
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "index" do
|
41
|
-
it "redirects to the /401.html page" do
|
42
|
-
get :index
|
43
|
-
expect(response).to redirect_to("/401.html")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
"""
|
48
|
-
When I run `rspec spec/controllers/gadgets_controller_spec.rb`
|
49
|
-
Then the examples should all pass
|
50
|
-
|
51
|
-
Scenario: bypass `rescue_from` handling with `bypass_rescue`
|
52
|
-
Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
|
53
|
-
"""ruby
|
54
|
-
require "spec_helper"
|
55
|
-
|
56
|
-
require 'controllers/gadgets_controller_spec_context'
|
57
|
-
|
58
|
-
describe GadgetsController do
|
59
|
-
before do
|
60
|
-
def controller.index
|
61
|
-
raise AccessDenied
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "index" do
|
66
|
-
it "raises AccessDenied" do
|
67
|
-
bypass_rescue
|
68
|
-
expect { get :index }.to raise_error(AccessDenied)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
"""
|
73
|
-
When I run `rspec spec/controllers/gadgets_controller_spec.rb`
|
74
|
-
Then the examples should all pass
|
75
|
-
|