jnicklas/capybara — pull request #560 by brianjlandau (2011-12-07 04:04:57+00:00)
Title: Don't follow external redirects for the rack-test driver.

Previously the `Capybara::RackTest::Driver` would follow all redirects even those to external URLs. This would cause exceptions to be raised if the path of the URL didn't match a route in the application being tested. This is because rack-test can't hit external URLs. The expected usage here is that the developer just wants to test that the redirect went to the correct external location not test anything about it. If they actually want to make assertion about the content at the external URL or interact with the external page in some way they should use an alternate driver. So what this now does is just not continue to process requests after we reach a redirect to an external URL.

This new behavior can be changed back to the old behavior by passing `false` to the `:follow_external_redirects` option to the `Capybara::RackTest::Driver`:

```ruby
Capybara.register_driver :rack_test do |app|
Capybara::RackTest::Driver.new(app, :follow_external_redirects => true)
end
```

This also adds the `#redirect_url` method to the `Capybara::Session` object. This way the developer can test that the app redirected to the correct location:

```ruby
visit('/redirect_to_external_location')
redirect_url.should == 'http://www.google.com'
```