I'm trying to test how a not logged in user behaves like this
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
The output when i run 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.
So it looks like the correct execption is raised, but why is the spec not passing?
I've changed my spec to:
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
and it works. Kudos to Thomas! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With