forked from rspec/rspec-rails
/
anonymous_controller.feature
78 lines (62 loc) · 2 KB
/
anonymous_controller.feature
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
Feature: anonymous controller
As a Rails developer using RSpec
In order to specify behaviour of ApplicationController
I want a simple DSL for generating anonymous subclasses
Scenario: specify error handling in ApplicationController
Given a file named "spec/controllers/application_controller_spec.rb" with:
"""
require "spec_helper"
class ApplicationController < ActionController::Base
class AccessDenied < StandardError; end
rescue_from AccessDenied, :with => :access_denied
private
def access_denied
redirect_to "/401.html"
end
end
describe ApplicationController do
controller do
def index
raise ApplicationController::AccessDenied
end
end
describe "handling AccessDenied exceptions" do
it "redirects to the /401.html page" do
get :index
response.should redirect_to("/401.html")
end
end
end
"""
When I run "rspec spec"
Then the examples should all pass
Scenario: specify error handling in subclass of ApplicationController
Given a file named "spec/controllers/application_controller_subclass_spec.rb" with:
"""
require "spec_helper"
class ApplicationController < ActionController::Base
class AccessDenied < StandardError; end
end
class ApplicationControllerSubclass < ApplicationController
rescue_from ApplicationController::AccessDenied, :with => :access_denied
private
def access_denied
redirect_to "/401.html"
end
end
describe ApplicationControllerSubclass do
controller(ApplicationControllerSubclass) do
def index
raise ApplicationController::AccessDenied
end
end
describe "handling AccessDenied exceptions" do
it "redirects to the /401.html page" do
get :index
response.should redirect_to("/401.html")
end
end
end
"""
When I run "rspec spec"
Then the examples should all pass