diff --git a/lib/rspec/rails/example/system_example_group.rb b/lib/rspec/rails/example/system_example_group.rb index 8e0bb5ffe..d31d7e716 100644 --- a/lib/rspec/rails/example/system_example_group.rb +++ b/lib/rspec/rails/example/system_example_group.rb @@ -101,9 +101,12 @@ def driven_by(driver, **driver_options, &blk) before do @routes = ::Rails.application.routes + @original_host = default_url_options[:host] + default_url_options.merge!(host: Capybara.app_host || "https://example.com") end after do + default_url_options.merge!(host: @original_host) orig_stdout = $stdout $stdout = StringIO.new begin diff --git a/spec/rspec/rails/example/system_example_group_spec.rb b/spec/rspec/rails/example/system_example_group_spec.rb index 620fe13b7..fa8a4631c 100644 --- a/spec/rspec/rails/example/system_example_group_spec.rb +++ b/spec/rspec/rails/example/system_example_group_spec.rb @@ -29,6 +29,40 @@ module RSpec::Rails end end + describe 'rails url helpers' do + it 'have the rails system test default host' do + full_url = nil + group = RSpec::Core::ExampleGroup.describe do + include SystemExampleGroup + + specify do + @routes.draw { get "/" => "page#index", as: :root } + full_url = root_url + end + end + group.run(failure_reporter) + expect(failure_reporter.exceptions).to eq [] + expect(full_url).to match a_string_including(ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown::DEFAULT_HOST) + end + end + + describe '#url_options' do + it 'has the rails system test default host' do + rails_url_options = {} + group = RSpec::Core::ExampleGroup.describe do + include SystemExampleGroup + + specify { rails_url_options.merge!(url_options) } + end + group.run(failure_reporter) + expect(failure_reporter.exceptions).to eq [] + + expect( + rails_url_options + ).to match hash_including(host: ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown::DEFAULT_HOST) + end + end + describe '#driver' do it 'uses :selenium driver by default' do group = RSpec::Core::ExampleGroup.describe do