Skip to content

The default url host for testing is not same as mentioned in the doc. #2807

@aditya-vishwakarma-lab

Description

@aditya-vishwakarma-lab

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:

  1. Update Capybara's default host to match Rails' example.com, or
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions