Skip to content

Instantly share code, notes, and snippets.

@n0nick
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0nick/594432eee7ccf7ee2a2c to your computer and use it in GitHub Desktop.
Save n0nick/594432eee7ccf7ee2a2c to your computer and use it in GitHub Desktop.
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
class ApplicationController < ActionController::Base
def redirect_to_index
redirect_to(:action => :index)
end
end
describe ApplicationController, :type => :controller do
controller do
before_filter :redirect_to_index, only: :show
def index; end
def show; end
end
describe "GET show(failed pattern)" do
it "redirect to index page" do
get :show, :id => 1
# failed! because no route match.
response.should redirect_to(:action => :index)
end
end
describe "GET show(success pattern)" do
before do
controller.stub(:_routes).and_return(@routes)
end
it "redirect to index page" do
get :show, :id => 1
response.should redirect_to(:action => :index)
end
end
end
$ ruby -v
ruby 2.0.0p594 (2014-10-27 revision 48167) [x86_64-linux]
$ bundle exec rspec -v
3.2.0
$ bundle exec rspec spec/anonymous_routes_spec.rb
Randomized with seed 57921
.F
Failures:
1) ApplicationController GET show(failed pattern) redirect to index page
Failure/Error: redirect_to(:action => :index)
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"anonymous", :id=>"1"}
# ./spec/anonymous_routes_spec.rb:6:in `redirect_to_index'
# ./lib/admanager/logging.rb:62:in `process_action'
# ./spec/anonymous_routes_spec.rb:20:in `block (3 levels) in <top (required)>'
...
2 deprecation warnings total
Finished in 0.10499 seconds (files took 7.11 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/anonymous_routes_spec.rb:19 # ApplicationController GET show(failed pattern) redirect to index page
Randomized with seed 57921
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment