Skip to content

Commit

Permalink
Set capybara as the default host in system specs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed May 25, 2020
1 parent 1e8d7df commit 0623e8a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rspec/rails/example/system_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,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)
end

after do
default_url_options.merge!(host: @original_host)
orig_stdout = $stdout
$stdout = StringIO.new
begin
Expand Down
34 changes: 34 additions & 0 deletions spec/rspec/rails/example/system_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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
Expand Down

0 comments on commit 0623e8a

Please sign in to comment.