forked from rspec/rspec-rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add controller DSL for spec'ing behaviour of subclasses of
ApplicationController.
- Loading branch information
1 parent
67dfdde
commit d4fa068
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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 output should contain "1 example, 0 failures" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters