Following links in emails with Capybara
by Trevor Turk
Although this just got added to the Capybara README, I thought it worth a quick note here.
When using Rack::Test, beware if attempting to visit absolute URLs. For example, a session might not be shared between visits to posts_path and posts_url. If testing an absolute URL in an Action Mailer email, set default_url_options to match the Rails default of www.example.com.
So, for a Rails app, you’d add this to your config/environments/test.rb file:
config.action_mailer.default_url_options = {:host => 'www.example.com'}
Otherwise, you’ll find yourself losing your user session between requests (steps) in your test.
Advertisement
Just got bitten by this, so thanks for the explanation.
Do you know if there is any way we could overwrite the http://www.example.com default instead, so we can use our own hostname for testing absolute URLs?