title: Capybara changes my action_mailer.default_url_options
body: <p>I ran into a problem, I'm using ruby on rails with devise and want to test the flow of my application with capybara.</p>
  
  <p>When i click links in my e-mails </p>
  
  <pre><code>current_email.click_link 'text'
  </code></pre>
  
  <p>it' gives an protocol error, debugging this it seems capybara changes the host that devise uses to make the e-mail.</p>
  
  <p>So i wrote this test:</p>
  
  <pre><code>ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'capybara/rspec'
  require 'capybara-webkit'
  require 'capybara/email/rspec'
  require 'headless'
  
  describe 'capybara and devise are broken', type: :request do
    it 'action_mailer default url should change when visiting a page' do  
      initialValue = X::Application.config.action_mailer.default_url_options[:host]
  
      visit "/"
  
      initialValue.should_not equal X::Application.config.action_mailer.default_url_options[:host]
    end
  
    it 'action_mailer default url should change when clicking a link' do  
      initialValue = X::Application.config.action_mailer.default_url_options[:host]
      visit "/"
      X::Application.config.action_mailer.default_url_options[:host] = initialValue
  
      click_link "Can't access?"
  
      initialValue.should_not equal X::Application.config.action_mailer.default_url_options[:host]
    end
  
    it 'action_mailer default url should change when clicking a button' do
      initialValue = X::Application.config.action_mailer.default_url_options[:host]
      visit "/"
      X::Application.config.action_mailer.default_url_options[:host] = initialValue
  
      click_button "Sign in"
  
      initialValue.should_not equal X::Application.config.action_mailer.default_url_options[:host]
    end
  
  end
  </code></pre>
  
  <p>All these tests succeed and i can't figure out what I'm doing wrong.</p>
  
  <p>It's my third week with RoR, so maybe it's something obvious i'm missing?</p>
  
  <p>Gem versions:
  gem 'rails', '3.2.7'
  gem 'capybara', require: false
  gem 'capybara-webkit', '= 0.10.1', require: false
  gem 'capybara-screenshot'
  gem 'capybara-email'
  gem 'devise', '~> 2.0.0'
  gem 'devise_invitable', '~> 1.0.0'</p>