Class: Suspenders::Generators::TestingGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Suspenders::Generators::TestingGenerator
- Defined in:
- lib/generators/suspenders/testing_generator.rb
Instance Method Summary collapse
- #add_gems ⇒ Object
- #configure_action_mailer_helpers ⇒ Object
- #configure_chromedriver ⇒ Object
- #configure_i18n_helper ⇒ Object
- #configure_shoulda_matchers ⇒ Object
- #create_system_spec_dir ⇒ Object
- #modify_rails_helper ⇒ Object
- #modify_spec_helper ⇒ Object
- #run_rspec_installation_script ⇒ Object
Instance Method Details
#add_gems ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/suspenders/testing_generator.rb', line 33 def add_gems gem_group :development, :test do gem "rspec-rails", "~> 6.1.0" end gem_group :test do 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 "webmock" end Bundler.with_unbundled_env { run "bundle install" } end |
#configure_action_mailer_helpers ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/generators/suspenders/testing_generator.rb', line 102 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 |
#configure_chromedriver ⇒ Object
90 91 92 |
# File 'lib/generators/suspenders/testing_generator.rb', line 90 def configure_chromedriver copy_file "driver.rb", "spec/support/driver.rb" end |
#configure_i18n_helper ⇒ Object
94 95 96 |
# File 'lib/generators/suspenders/testing_generator.rb', line 94 def configure_i18n_helper copy_file "i18n.rb", "spec/support/i18n.rb" end |
#configure_shoulda_matchers ⇒ Object
98 99 100 |
# File 'lib/generators/suspenders/testing_generator.rb', line 98 def configure_shoulda_matchers copy_file "shoulda_matchers.rb", "spec/support/shoulda_matchers.rb" end |
#create_system_spec_dir ⇒ Object
85 86 87 88 |
# File 'lib/generators/suspenders/testing_generator.rb', line 85 def create_system_spec_dir empty_directory "spec/system" create_file "spec/system/.gitkeep" end |
#modify_rails_helper ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/generators/suspenders/testing_generator.rb', line 55 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 |
#modify_spec_helper ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/suspenders/testing_generator.rb', line 63 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 |
#run_rspec_installation_script ⇒ Object
51 52 53 |
# File 'lib/generators/suspenders/testing_generator.rb', line 51 def run_rspec_installation_script rails_command "generate rspec:install" end |