-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Introduce suspenders:testing
generator
#1156
Merged
stevepolitodesign
merged 12 commits into
suspenders-3-0-0
from
suspenders-3-0-0-testing-generator
Mar 8, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ed625b7
Introduce `suspenders:testing` generator
stevepolitodesign 9742372
Introduce `suspenders:testing:minitest` and `suspenders:testing:rspec`
stevepolitodesign 379c63a
Drop support for Minitest
stevepolitodesign 0f2505e
Keep `test` directory
stevepolitodesign 9cb7765
Require webmock in spec_helper
stevepolitodesign 1ad8e3e
Install action_dispatch-testing-integration-capybara
stevepolitodesign 336eeb9
Allow additional Chrome hosts
stevepolitodesign a4c9d36
Fix linting violations
stevepolitodesign 820c87a
Remove obsolete test
stevepolitodesign 1675ea1
Update README and description
stevepolitodesign b468f32
Fix linting violation
stevepolitodesign 2b7c5c7
Restore file
stevepolitodesign File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module Suspenders | ||
module Generators | ||
class TestingGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../../templates/testing", __FILE__) | ||
desc "Set up the project for an in-depth test-driven development workflow." | ||
|
||
def add_gems | ||
gem_group :development, :test do | ||
gem "rspec-rails", "~> 6.1.0" | ||
end | ||
|
||
gem_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 "shoulda-matchers", "~> 6.0" | ||
gem "webdrivers" | ||
gem "webmock" | ||
end | ||
|
||
Bundler.with_unbundled_env { run "bundle install" } | ||
end | ||
|
||
def run_rspec_installation_script | ||
rails_command "generate rspec:install" | ||
end | ||
|
||
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" | ||
end | ||
|
||
def modify_spec_helper | ||
persistence_file_path = "\s\sconfig.example_status_persistence_file_path = \"tmp/rspec_examples.txt\"\n" | ||
order = "\s\sconfig.order = :random\n\n" | ||
webmock_config = <<~RUBY | ||
|
||
WebMock.disable_net_connect!( | ||
allow_localhost: true, | ||
allow: [ | ||
/(chromedriver|storage).googleapis.com/, | ||
"googlechromelabs.github.io", | ||
] | ||
) | ||
RUBY | ||
|
||
insert_into_file "spec/spec_helper.rb", | ||
persistence_file_path + order, | ||
after: "RSpec.configure do |config|\n" | ||
|
||
insert_into_file "spec/spec_helper.rb", "require \"webmock/rspec\"\n\n", before: "RSpec.configure do |config|" | ||
insert_into_file "spec/spec_helper.rb", webmock_config | ||
end | ||
|
||
def create_system_spec_dir | ||
empty_directory "spec/system" | ||
create_file "spec/system/.gitkeep" | ||
end | ||
|
||
def configure_chromedriver | ||
copy_file "chromedriver.rb", "spec/support/chromedriver.rb" | ||
end | ||
|
||
def configure_i18n_helper | ||
copy_file "i18n.rb", "spec/support/i18n.rb" | ||
end | ||
|
||
def configure_shoulda_matchers | ||
copy_file "shoulda_matchers.rb", "spec/support/shoulda_matchers.rb" | ||
end | ||
|
||
def configure_action_mailer_helpers | ||
# https://guides.rubyonrails.org/testing.html#the-basic-test-case | ||
# | ||
# The ActionMailer::Base.deliveries array is only reset automatically in | ||
# ActionMailer::TestCase and ActionDispatch::IntegrationTest tests. If | ||
# you want to have a clean slate outside these test cases, you can reset | ||
# it manually with: ActionMailer::Base.deliveries.clear | ||
copy_file "action_mailer.rb", "spec/support/action_mailer.rb" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RSpec.configure do |config| | ||
config.before(:each) do | ||
ActionMailer::Base.deliveries.clear | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RSpec.configure do |config| | ||
config.include ActionView::Helpers::TranslationHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Shoulda::Matchers.configure do |config| | ||
config.integrate do |with| | ||
with.test_framework :rspec | ||
with.library :rails | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found I needed to add
googlechromelabs.github.io
and adjust the original host when I tested this on a fresh Rails app. Otherwise, we would raiseWebMock::NetConnectNotAllowedError
.