Skip to content

Commit 08182d3

Browse files
committed
Set capybara as the default host in system specs
See: rails/rails@ea77dbf#diff-ff5f366a442b8761d35f94807700fa77R162
1 parent a0099fc commit 08182d3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/rspec/rails/example/system_example_group.rb

+3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ def driven_by(driver, **driver_options, &blk)
101101

102102
before do
103103
@routes = ::Rails.application.routes
104+
@original_host = default_url_options[:host]
105+
default_url_options.merge!(host: Capybara.app_host)
104106
end
105107

106108
after do
109+
default_url_options.merge!(host: @original_host)
107110
orig_stdout = $stdout
108111
$stdout = StringIO.new
109112
begin

spec/rspec/rails/example/system_example_group_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,40 @@ module RSpec::Rails
2929
end
3030
end
3131

32+
describe 'rails url helpers' do
33+
it 'have the rails system test default host' do
34+
full_url = nil
35+
group = RSpec::Core::ExampleGroup.describe do
36+
include SystemExampleGroup
37+
38+
specify do
39+
@routes.draw { get "/" => "page#index", as: :root }
40+
full_url = root_url
41+
end
42+
end
43+
group.run(failure_reporter)
44+
expect(failure_reporter.exceptions).to eq []
45+
expect(full_url).to match a_string_including(ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown::DEFAULT_HOST)
46+
end
47+
end
48+
49+
describe '#url_options' do
50+
it 'has the rails system test default host' do
51+
rails_url_options = {}
52+
group = RSpec::Core::ExampleGroup.describe do
53+
include SystemExampleGroup
54+
55+
specify { rails_url_options.merge!(url_options) }
56+
end
57+
group.run(failure_reporter)
58+
expect(failure_reporter.exceptions).to eq []
59+
60+
expect(
61+
rails_url_options
62+
).to match hash_including(host: ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown::DEFAULT_HOST)
63+
end
64+
end
65+
3266
describe '#driver' do
3367
it 'uses :selenium driver by default' do
3468
group = RSpec::Core::ExampleGroup.describe do

0 commit comments

Comments
 (0)