Search code examples
ruby-on-railsrspeccapybarahostmailer

Rails, test mailer url


My application sends E-mails containing absolute urls.

I set host in config/environment/development.rb

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

Now I want to test if Email contains valid url. Using regular expression I take out full url from E-mail and want to visit this address using Capybara function.

mail = ActionMailer::Base.deliveries.last
address = mail.body.to_s[%r{http.+/edit}]
visit address;

But I don't know what host should be set in config/environment/test.rb

When I set localhost:3000 it tries to connect to my local server started by rails server command.

Do you have any ideas to solve this problem?


Solution

  • What worked for me:

    Capybara.server_port = 3005
    

    (see https://github.com/vangberg/capybara/commit/5784f03d6aa87e63e759abda794a43738e4f320f)

    and

    config.action_mailer.default_url_options = { :host => 'localhost:3005' }