我试图测试一个没有登录的用户行为如何
describe "not logged in user" do user_no_rights it "can't access action index" do expect(get :index).to raise_error(CanCan::AccessDenied) end end
输出时我运行rspec
Failure/Error: expect(get :index).to raise_error("CanCan::AccessDenied:You are not authorized to access this page.") CanCan::AccessDenied: You are not authorized to access this page.
所以看起来正确的提示,但为什么规范不通过?
解决方法
我已将我的规格改为:
describe "not logged in user" do user_no_rights it "can't access action index" do expect{get :index}.to raise_error(CanCan::AccessDenied) end end
它的工作原理托马斯! 原文链接:https://www.f2er.com/ruby/271845.html