如何测试rescue_from is RSpec?我希望确保如果引发其中一个异常,控制器将正确设置闪存并执行重定向。有没有办法模拟异常?
rescue_from PageAccessDenied do
flash[:alert] = "You do not have the necessary roles to access this page"
redirect_to root_url
end
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = exception.message
redirect_to root_url
end发布于 2010-12-17 12:58:38
假设您有一个引发异常的authorize!方法,您应该能够执行以下操作:
describe "rescue_from exceptions" do
it "rescues from PageAccessDenied" do
controller.stub(:authorize!) { raise PageAccessDenied }
get :index
response.should redirect_to("/")
flash[:alert].should == "You do not have the necessary roles to access this page"
end
endhttps://stackoverflow.com/questions/4466399
复制相似问题