diff --git a/README.md b/README.md index f3cffb81c..78f108f20 100644 --- a/README.md +++ b/README.md @@ -178,17 +178,10 @@ bin/rails g suspenders:email ### Testing -Set up the project for an in-depth test-driven development workflow. - -Installs and configures [rspec-rails][], -[action_dispatch-testing-integration-capybara][], [shoulda-matchers][], -[webdrivers][] and [webmock][]. +Set up the project for an in-depth test-driven development workflow via +[rspec-rails][] and friends. [rspec-rails]: https://github.com/rspec/rspec-rails -[action_dispatch-testing-integration-capybara]: https://github.com/thoughtbot/action_dispatch-testing-integration-capybara -[shoulda-matchers]: https://github.com/thoughtbot/shoulda-matchers -[webdrivers]: https://github.com/titusfortner/webdrivers -[webmock]: https://github.com/bblimke/webmock ## Contributing diff --git a/lib/generators/suspenders/testing_generator.rb b/lib/generators/suspenders/testing_generator.rb index 73d7e909b..c762f0cb2 100644 --- a/lib/generators/suspenders/testing_generator.rb +++ b/lib/generators/suspenders/testing_generator.rb @@ -10,11 +10,12 @@ def add_gems end gem_group :test do + gem "capybara" gem "action_dispatch-testing-integration-capybara", - github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.0", + github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.1", require: "action_dispatch/testing/integration/capybara/rspec" + gem "selenium-webdriver" gem "shoulda-matchers", "~> 6.0" - gem "webdrivers" gem "webmock" end @@ -29,6 +30,8 @@ def modify_rails_helper insert_into_file "spec/rails_helper.rb", "\s\sconfig.infer_base_class_for_anonymous_controllers = false\n", after: "RSpec.configure do |config|\n" + + uncomment_lines "spec/rails_helper.rb", /Rails\.root\.glob/ end def modify_spec_helper @@ -59,7 +62,7 @@ def create_system_spec_dir end def configure_chromedriver - copy_file "chromedriver.rb", "spec/support/chromedriver.rb" + copy_file "driver.rb", "spec/support/driver.rb" end def configure_i18n_helper diff --git a/lib/generators/templates/testing/chromedriver.rb b/lib/generators/templates/testing/chromedriver.rb deleted file mode 100644 index 4091d1531..000000000 --- a/lib/generators/templates/testing/chromedriver.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "selenium/webdriver" - -Capybara.register_driver :chrome do |app| - Capybara::Selenium::Driver.new(app, browser: :chrome) -end - -Capybara.register_driver :headless_chrome do |app| - options = ::Selenium::WebDriver::Chrome::Options.new - options.headless! - options.add_argument "--window-size=1680,1050" - - Capybara::Selenium::Driver.new app, - browser: :chrome, - options: options -end - -Capybara.javascript_driver = :headless_chrome - -RSpec.configure do |config| - config.before(:each, type: :system) do - driven_by :rack_test - end - - config.before(:each, type: :system, js: true) do - driven_by Capybara.javascript_driver - end -end diff --git a/lib/generators/templates/testing/driver.rb b/lib/generators/templates/testing/driver.rb new file mode 100644 index 000000000..91e275b49 --- /dev/null +++ b/lib/generators/templates/testing/driver.rb @@ -0,0 +1,5 @@ +RSpec.configure do |config| + config.before(:each, type: :system) do + driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] + end +end diff --git a/test/generators/suspenders/testing_generator_test.rb b/test/generators/suspenders/testing_generator_test.rb index ff901cd7e..33e4d301e 100644 --- a/test/generators/suspenders/testing_generator_test.rb +++ b/test/generators/suspenders/testing_generator_test.rb @@ -18,9 +18,10 @@ class TestingGeneratorTest < Rails::Generators::TestCase end group :test do - gem "action_dispatch-testing-integration-capybara", github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.0", require: "action_dispatch/testing/integration/capybara/rspec" + gem "capybara" + gem "action_dispatch-testing-integration-capybara", github: "thoughtbot/action_dispatch-testing-integration-capybara", tag: "v0.1.1", require: "action_dispatch/testing/integration/capybara/rspec" + gem "selenium-webdriver" gem "shoulda-matchers", "~> 6.0" - gem "webdrivers" gem "webmock" end RUBY @@ -52,6 +53,7 @@ class TestingGeneratorTest < Rails::Generators::TestCase assert_file "spec/rails_helper.rb" do |file| assert_match(/RSpec\.configure do \|config\|\s{3}config\.infer_base_class_for_anonymous_controllers\s*=\s*false/m, file) + assert_match(/^\#{0}\s*Rails\.root\.glob\(\"spec\/support\/\*\*\/\*\.rb\"\)\.sort\.each { \|f\| require f }/, file) end end @@ -90,40 +92,18 @@ class TestingGeneratorTest < Rails::Generators::TestCase end end - test "configures Chromedriver" do + test "configures driver" do expected = <<~RUBY - require "selenium/webdriver" - - Capybara.register_driver :chrome do |app| - Capybara::Selenium::Driver.new(app, browser: :chrome) - end - - Capybara.register_driver :headless_chrome do |app| - options = ::Selenium::WebDriver::Chrome::Options.new - options.headless! - options.add_argument "--window-size=1680,1050" - - Capybara::Selenium::Driver.new app, - browser: :chrome, - options: options - end - - Capybara.javascript_driver = :headless_chrome - RSpec.configure do |config| config.before(:each, type: :system) do - driven_by :rack_test - end - - config.before(:each, type: :system, js: true) do - driven_by Capybara.javascript_driver + driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] end end RUBY run_generator - assert_file app_root("spec/support/chromedriver.rb") do |file| + assert_file app_root("spec/support/driver.rb") do |file| assert_equal expected, file end end @@ -210,6 +190,8 @@ def rails_helper abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' + # Rails.root.glob("spec/support/**/*.rb").sort.each { |f| require f } + begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e