13

我正在尝试测试未登录用户的行为方式

  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.

所以看起来正确的执行被提出了,但为什么规范没有通过?

4

1 回答 1

21

我已将我的规格更改为:

 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

它有效。向托马斯致敬!:-)

于 2013-05-06T22:53:39.733 回答