0

I've seen a lot of questions about errors concerning action_mailer.default_url_options and default_url_options[:host] during system tests.

Below I share a good solution I found.

1 Answer 1

0

In the file test/application_system_test_case.rb, append the following inside the setup block:

setup do
    host = Capybara.current_session.server.host
    port = Capybara.current_session.server.port
    Rails.application.config.action_mailer.default_url_options = { host: host, port: port }
    Rails.application.routes.default_url_options[:host] = host
end

This will make action_mailer.default_url_options and routes.default_url_options equal to whatever host and ports the tests had generated.

I think it's a better solution than hardcoding the values inside the environment files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.