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

Testing Generator: Improvements #1168

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +181 to +182
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt it was easier to keep this simple.


[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

Expand Down
9 changes: 6 additions & 3 deletions lib/generators/suspenders/testing_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions lib/generators/templates/testing/chromedriver.rb

This file was deleted.

5 changes: 5 additions & 0 deletions lib/generators/templates/testing/driver.rb
Original file line number Diff line number Diff line change
@@ -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
36 changes: 9 additions & 27 deletions test/generators/suspenders/testing_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down