ruby on rails - RSpec authorization testing with raise_error not working -


i'm trying test how not logged in user behaves this

  describe "not logged in user"    user_no_rights      "can't access action index"       expect(get :index).to raise_error(cancan::accessdenied)     end   end 

the output when run rspec

  failure/error: expect(get :index).to raise_error("cancan::accessdenied:you not authorized access page.")      cancan::accessdenied:        not authorized access page. 

so looks correct execption raised, why spec not passing?

i've changed spec to:

 describe "not logged in user"    user_no_rights      "can't access action index"       expect{get :index}.to raise_error(cancan::accessdenied)     end  end 

and works. kudos thomas! :-)


Comments