Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define url_options as per system test case does #2329

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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 @@ -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
Expand Down