pat*_*ler 12 rspec ruby-on-rails cancan rspec-rails
我正在尝试测试未登录用户的行为如何
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
Run Code Online (Sandbox Code Playgroud)
我运行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.
Run Code Online (Sandbox Code Playgroud)
所以它看起来像是正确的execption,但为什么规范不通过?
pat*_*ler 19
我把规格改为:
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
Run Code Online (Sandbox Code Playgroud)
它的工作原理.感谢托马斯!:-)