ruby-on-rails – RSPec授权测试,raise_error不工作
发布时间:2020-12-16 19:45:03 所属栏目:百科 来源:网络整理
导读:我试图测试一个没有登录的用户行为如何 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 r
我试图测试一个没有登录的用户行为如何
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 它的工作原理托马斯! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |