Given I have a rails app
And I'm using cucumber
And I'm using capybara
And I have an action that results in a redirect_to "http://some.other.domain.com/some_path"
When I test this action
Then the in-app portion of the test works fine
But I see this error: No route matches "/some_path" with {:method=>:get} (ActionController::RoutingError)
So capybara is properly redirected to "http://some.other.domain.com/some_path" but for some reason it thinks it should handle the path portion of the url inside my app. NOTE capybara has no problem at all with "http://some.other.domain.com/" -- my tests pass if I redirect to a url without a path portion.
Is this a bug?
I think I had the same problem as you: I just wanted to confirm, that my code redirects to that given URL with the correct status code, but I don't want to do anything on that URL.
The problem is, that the site returns the redirect as expected, but Rack::Test interprets everything to the application under test, and that URL probably doesn't exist. But we can just catch the error and see what the response looked like. This will probably not work with anything else than capybara's default driver.
begin
click_button('Pay with Paypal')
rescue ActionController::RoutingError
end
expect(page.status_code).to eq(302)
expect(page.response_headers['Location']).to include('paypal.com/cgi-bin/websrc')
Here's an example I wrote up about using capybara-mechanize and VCR to test an external redirect.
http://blog.tddium.com/2011/10/04/testing-external-redirects-vcr-capybara-mechanize/
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