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

Fix an issue where driven_by(:selenium) is always called #2188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/rspec/rails/example/system_example_group.rb
Expand Up @@ -78,16 +78,19 @@ def app
def initialize(*args, &blk)
JonRowe marked this conversation as resolved.
Show resolved Hide resolved
super(*args, &blk)
@driver = nil

self.class.before do
# A user may have already set the driver, so only default if driver
# is not set
driven_by(:selenium) unless @driver
end
end

JonRowe marked this conversation as resolved.
Show resolved Hide resolved
def driven_by(*args, &blk)
@driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use)
sinsoku marked this conversation as resolved.
Show resolved Hide resolved
end

before do
# A user may have already set the driver, so only default if driver
# is not set
driven_by(:selenium) unless @driver
@routes = ::Rails.application.routes
end

Expand Down
41 changes: 41 additions & 0 deletions spec/rspec/rails/example/system_example_group_spec.rb
Expand Up @@ -18,6 +18,47 @@ module RSpec::Rails
end
end
end

describe '#driver' do
it 'uses :selenium driver by default' do
group = RSpec::Core::ExampleGroup.describe do
include SystemExampleGroup
end
example = group.new
group.hooks.run(:before, :example, example)

expect(Capybara.current_driver).to eq :selenium
end

it 'sets :rack_test driver using by before_action' do
group = RSpec::Core::ExampleGroup.describe do
include SystemExampleGroup

before do
driven_by(:rack_test)
end
end
example = group.new
group.hooks.run(:before, :example, example)

expect(Capybara.current_driver).to eq :rack_test
end

it 'calls :driven_by method only once' do
group = RSpec::Core::ExampleGroup.describe do
include SystemExampleGroup

before do
driven_by(:rack_test)
end
end
example = group.new
allow(example).to receive(:driven_by).and_call_original
group.hooks.run(:before, :example, example)

expect(example).to have_received(:driven_by).once
pirj marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
end