'Rspec/Capybara: How to "expect to see Routing Error"?
How do I tell RSpec/Capybara to expect a RoutingError? The reason is I want users to click a link to "claim a plate" via PUT, not via GET/visiting the path.
Basically I want to expect ActionController::RoutingError: No route matches [GET] "/plates/claim/1".
scenario 'they have to click the claim link' do
create_plates
sign_in_as_doctor
visit claim_plate_path(@plates.first.id)
?????
end
Solution 1:[1]
Try this
scenario 'they have to click the claim link' do
create_plates
sign_in_as_doctor
expect{visit claim_plate_path(@plates.first.id)}.to raise_error( ActionController::RoutingError)
end
Solution 2:[2]
Accepted answer didn't work for me. What I had to do is:
create_plates
sign_in_as_doctor
expect do
visit claim_plate_path(@plates.first.id)
expect(page).to have_content("make sure visit is completed")
end.to raise_error(ActionController::RoutingError)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | usha |
| Solution 2 | Eero Lahdenperä |
