Default URL Options Mismatch between Rails and Capybara
Description
Rails 8.0.2 has changed its default test environment URL to example.com, but Capybara still defaults to www.example.com. This causes issues when testing mailer URLs in system tests.
Current Behavior
- Rails default_url_options in test env:
example.com
- Capybara default host:
www.example.com
- This mismatch causes URL comparison failures in tests
Example
# config/environments/test.rb
config.action_mailer.default_url_options = { host: "example.com" }
# spec/system/some_mailer_spec.rb
expect(email.body.to_s).to include(some_url(...)) # generates www.example.com
# but email contains example.com
Expected Behavior
Both Rails and Capybara should use the same default host to ensure consistent URL generation in tests.
Proposed Solution
Either:
- Update Capybara's default host to match Rails'
example.com, or
- Add documentation about this mismatch and how to handle it ( I know it has been mentioned in the gotchas but I think that is incorrect, it assumes the default host in rails test environment is www.example.com )
Environment
- Rails version: 8.0.2
- Capybara version: 3.40.o
- Ruby version: 3.4.1
Additional Context
This issue particularly affects system tests that need to verify email content containing absolute URLs.
Default URL Options Mismatch between Rails and Capybara
Description
Rails 8.0.2 has changed its default test environment URL to
example.com, but Capybara still defaults towww.example.com. This causes issues when testing mailer URLs in system tests.Current Behavior
example.comwww.example.comExample
Expected Behavior
Both Rails and Capybara should use the same default host to ensure consistent URL generation in tests.
Proposed Solution
Either:
example.com, orEnvironment
Additional Context
This issue particularly affects system tests that need to verify email content containing absolute URLs.