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?
expect
might need to be passed a block:expect{ get :index }.to raise_error(CanCan::AccessDenied)
. – Illimani