Skip to content

Commit e8ac2a5

Browse files
Testing Generator: Improvements
Follow-up to #1156 Creates parity with Rails' decision to [use a headless driver by default][headless]. This will be fixed in an [upcoming release][rspec] of rspec-rails, but I felt it was important to capture here. Additionally, it ensures the `screen_size` is the same as what is set in Rails. Removes `webdrivers` dependency in favor of `selenium-webdriver`. This generator assumes the app was generated with the `--skip-test`, which means we need to add the `selenium-webdriver` and `capybara` gems. Updates `action_dispatch-testing-integration-capybara` dependency to the most recent tagged release in an effort to suppress Dependabot notifications. [headless]:drive://github.com/rails/rails/pull/50512 [rspec]: rspec/rspec-rails#2746
1 parent 39efb28 commit e8ac2a5

File tree

4 files changed

+15
-57
lines changed

4 files changed

+15
-57
lines changed

lib/generators/suspenders/testing_generator.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ def add_gems
1010
end
1111

1212
gem_group :test do
13+
gem "capybara"
1314
gem "action_dispatch-testing-integration-capybara",
14-
github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.0",
15+
github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.1",
1516
require: "action_dispatch/testing/integration/capybara/rspec"
17+
gem "selenium-webdriver"
1618
gem "shoulda-matchers", "~> 6.0"
17-
gem "webdrivers"
1819
gem "webmock"
1920
end
2021

@@ -59,7 +60,7 @@ def create_system_spec_dir
5960
end
6061

6162
def configure_chromedriver
62-
copy_file "chromedriver.rb", "spec/support/chromedriver.rb"
63+
copy_file "driver.rb", "spec/support/driver.rb"
6364
end
6465

6566
def configure_i18n_helper

lib/generators/templates/testing/chromedriver.rb

-27
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RSpec.configure do |config|
2+
config.before(:each, type: :system) do
3+
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
4+
end
5+
end

test/generators/suspenders/testing_generator_test.rb

+6-27
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class TestingGeneratorTest < Rails::Generators::TestCase
1818
end
1919
2020
group :test do
21-
gem "action_dispatch-testing-integration-capybara", github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.0", require: "action_dispatch/testing/integration/capybara/rspec"
21+
gem "capybara"
22+
gem "action_dispatch-testing-integration-capybara", github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.1", require: "action_dispatch/testing/integration/capybara/rspec"
23+
gem "selenium-webdriver"
2224
gem "shoulda-matchers", "~> 6.0"
23-
gem "webdrivers"
2425
gem "webmock"
2526
end
2627
RUBY
@@ -90,40 +91,18 @@ class TestingGeneratorTest < Rails::Generators::TestCase
9091
end
9192
end
9293

93-
test "configures Chromedriver" do
94+
test "configures driver" do
9495
expected = <<~RUBY
95-
require "selenium/webdriver"
96-
97-
Capybara.register_driver :chrome do |app|
98-
Capybara::Selenium::Driver.new(app, browser: :chrome)
99-
end
100-
101-
Capybara.register_driver :headless_chrome do |app|
102-
options = ::Selenium::WebDriver::Chrome::Options.new
103-
options.headless!
104-
options.add_argument "--window-size=1680,1050"
105-
106-
Capybara::Selenium::Driver.new app,
107-
browser: :chrome,
108-
options: options
109-
end
110-
111-
Capybara.javascript_driver = :headless_chrome
112-
11396
RSpec.configure do |config|
11497
config.before(:each, type: :system) do
115-
driven_by :rack_test
116-
end
117-
118-
config.before(:each, type: :system, js: true) do
119-
driven_by Capybara.javascript_driver
98+
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
12099
end
121100
end
122101
RUBY
123102

124103
run_generator
125104

126-
assert_file app_root("spec/support/chromedriver.rb") do |file|
105+
assert_file app_root("spec/support/driver.rb") do |file|
127106
assert_equal expected, file
128107
end
129108
end

0 commit comments

Comments
 (0)