[rspec-users] Anonymous controller not working

Federico Gonzalez fedegl at gmail.com
Tue Aug 30 22:23:17 EDT 2011


I have the following files.

# application_controller_spec.rb

require 'spec_helper'

describe ApplicationController do
  controller do
    def index       
      raise CanCan::AccessDenied.new("Not authorized!", :read, Order)
    end
  end

  describe "rescue from AccessDenied" do
    it "should rescue from CanCan::AccessDenied" do
      get :index
      response.should redirect_to("/")
    end
  end

end

# application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end
end

But when I run the spec get the following error:

Failure/Error: response.should redirect_to("/")
 Expected response to be a <:redirect>, but was <200>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110830/3c9d25b7/attachment-0001.html>


More information about the rspec-users mailing list