【发布时间】:2013-05-05 21:39:22
【问题描述】:
我正在尝试测试未登录用户的行为方式
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.
所以看起来提出了正确的执行,但为什么规范没有通过?
【问题讨论】:
-
在引发错误
expect的情况下可能需要传递一个块:expect{ get :index }.to raise_error(CanCan::AccessDenied)。 -
谢谢@ThomasKlemm!
标签: ruby-on-rails rspec cancan rspec-rails