diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70b310f2a..ad118a06b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,9 +43,6 @@ jobs: - ruby: 3.2 env: RAILS_VERSION: 'main' - - ruby: 3.1 - env: - RAILS_VERSION: 'main' # Rails 7.2 builds >= 3.1 - ruby: 3.3 diff --git a/Changelog.md b/Changelog.md index a5a654bfa..7cb4c4437 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,13 @@ ### Development -[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.1...7-0-maintenance) +[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.2...7-0-maintenance) + +### 7.0.2 / 2024-11-09 +[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.1...v7.0.2) + +Bug Fixes: + +* Fix issue with `have_enqueued_mail` when jobs were incorrectly matched due + to refactoring in #2780. (David Runger, #2793) ### 7.0.1 / 2024-09-03 [Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.0...v7.0.1) @@ -19,7 +27,7 @@ Enhancements: * Change default driver for system specs on Rails 7.2 to match its default. (Steve Polito, #2746) * Verify ActiveJob arguments by comparing to the method signature. (Oli Peate, #2745) -* Add suggestion to rails_helper.rb to skip when not in test most. (Glauco Custódio, #2751) +* Add suggestion to rails_helper.rb to skip when not in test mode. (Glauco Custódio, #2751) * Add `at_priority` qualifier to `have_enqueued_job` set of matchers. (mbajur, #2759) * Add spec directories to `rails stats` on Rails main / 8.0.0. (Petrik de Heus, #2781) diff --git a/README.md b/README.md index 2cd924513..9fa7139c2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ expressed in plain English. According to [RSpec Rails new versioning strategy][] use: * **[`rspec-rails` 7.x][]** for Rails 7.x. -* **[`rspec-rails` 6.x][]** for Rails 6.1. +* **[`rspec-rails` 6.x][]** for Rails 6.1, 7.0 or 7.1. * **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x. * **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x. * **[`rspec-rails` 3.x][]** for Rails earlier than 5.0. diff --git a/Rakefile b/Rakefile index da1a6fc94..35aac1bdf 100644 --- a/Rakefile +++ b/Rakefile @@ -105,6 +105,11 @@ namespace :smoke do in_example_app args.cmd.to_s end + desc "run rake routes in example app" + task :routes do + in_example_app "bin/rails routes" + end + desc "run RSPEC_OPTS environment variable in the example app for local dev" task :rspec do in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rspec #{ENV.fetch("RSPEC_OPTS")}" @@ -144,6 +149,11 @@ namespace :no_active_record do "no_active_record:smoke", ] + desc "run rake routes in example app" + task :routes do + in_example_app "bin/rails routes", app_dir: example_app_dir + end + desc "run RSPEC_OPTS environment variable in the example app for local dev" task :rspec do in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rspec #{ENV.fetch("RSPEC_OPTS")}", app_dir: example_app_dir @@ -165,7 +175,7 @@ namespace :no_active_record do sh "rm -f #{bindir}/rails" sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-bootsnap " \ "--skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --skip-spring " \ - "--skip-action-text --template=example_app_generator/generate_app.rb" + "--skip-action-text --skip-solid --template=example_app_generator/generate_app.rb" in_example_app(app_dir: example_app_dir) do sh "./ci_retry_bundle_install.sh 2>&1" @@ -188,7 +198,7 @@ namespace :no_active_record do desc "generate a bunch of stuff with generators" task :stuff do - in_example_app "bin/rake #{rails_template_command} LOCATION='../../example_app_generator/generate_stuff.rb'", app_dir: example_app_dir + in_example_app "bin/rake #{rails_template_command} LOCATION='../../example_app_generator/generate_stuff.rb' __RSPEC_NO_AR=true", app_dir: example_app_dir end end end diff --git a/example_app_generator/generate_stuff.rb b/example_app_generator/generate_stuff.rb index 57e2f705d..77d5a3ef9 100644 --- a/example_app_generator/generate_stuff.rb +++ b/example_app_generator/generate_stuff.rb @@ -57,10 +57,10 @@ def skip_active_record? end def self.environment_hooks - if defined?(ActiveRecord) - AR - else + if ENV['__RSPEC_NO_AR'] NoAR + else + AR end end end diff --git a/example_app_generator/spec/verify_mailer_preview_path_spec.rb b/example_app_generator/spec/verify_mailer_preview_path_spec.rb index 9f21bc01e..68bb840a4 100644 --- a/example_app_generator/spec/verify_mailer_preview_path_spec.rb +++ b/example_app_generator/spec/verify_mailer_preview_path_spec.rb @@ -33,6 +33,8 @@ def capture_exec(*ops) .reject { |line| line =~ /DEPRECATION WARNING/ } .reject { |line| line =~ /warning: previous/ } .reject { |line| line =~ /warning: already/ } + .reject { |line| line =~ /but will no longer be part of the default gems / } + .reject { |line| line =~ /You can add .* to your Gemfile/ } .join .chomp CaptureExec.new(out, $?.exitstatus) diff --git a/features/Generators.md b/features/Generators.md index 61fc83fec..74f96b241 100644 --- a/features/Generators.md +++ b/features/Generators.md @@ -1,7 +1,7 @@ # Using generators -RSpec spec are normally generated alongside other application components. -For instance, `rails generate model` will also generate an RSpec spec file +RSpec `_spec.rb` files are normally generated alongside other application components. +For instance, `rails generate model` will also generate an RSpec `_spec.rb` file for the model. Note that the generators are there to help you get started, but they are no @@ -18,17 +18,16 @@ will create a new spec file in `spec/models/widget_spec.rb`. The same generator pattern is available for all specs: -* scaffold -* model +* channel * controller -* helper -* view -* mailer -* integration * feature -* job -* channel * generator +* helper +* job * mailbox +* mailer +* model * request +* scaffold * system +* view diff --git a/features/GettingStarted.md b/features/Getting_started.md similarity index 100% rename from features/GettingStarted.md rename to features/Getting_started.md diff --git a/features/backtrace_filtering.feature b/features/backtrace_filtering.feature index 58ef79802..360481a3f 100644 --- a/features/backtrace_filtering.feature +++ b/features/backtrace_filtering.feature @@ -39,9 +39,9 @@ Feature: Backtrace filtering Scenario: Using the bare `rspec` command When I run `rspec` Then the output should contain "1 example, 1 failure" - And the output should not contain "activesupport" + And the output should not contain "actionpack" Scenario: Using `rspec --backtrace` When I run `rspec --backtrace` Then the output should contain "1 example, 1 failure" - And the output should contain "activesupport" + And the output should contain "actionpack" diff --git a/features/system_specs/system_specs.feature b/features/system_specs/system_specs.feature index bb729ac3f..33b893010 100644 --- a/features/system_specs/system_specs.feature +++ b/features/system_specs/system_specs.feature @@ -19,7 +19,21 @@ Feature: System specs RSpec **does not** use your `ApplicationSystemTestCase` helper. Instead it uses the default `driven_by(:selenium)` from Rails. If you want to override - this behaviour you can call `driven_by` manually in a test. + this behaviour you need to call `driven_by` in your specs. + + This can either be done manually in the spec files themselves or + you can use the configuration helpers to do this for every system spec, + for example by adding the following to `spec/rails_helper.rb`: + + ```ruby + RSpec.configure do |config| + ... + config.before(type: :system) do + driven_by :selenium_headless # Or your preferred default driver + end + ... + end + ``` System specs run in a transaction. So unlike feature specs with javascript, you do not need [DatabaseCleaner](https://github.com/DatabaseCleaner/database_cleaner). diff --git a/lib/rspec/rails/matchers/have_enqueued_mail.rb b/lib/rspec/rails/matchers/have_enqueued_mail.rb index 9d2c405b3..85aaea274 100644 --- a/lib/rspec/rails/matchers/have_enqueued_mail.rb +++ b/lib/rspec/rails/matchers/have_enqueued_mail.rb @@ -72,7 +72,7 @@ def mailer_class_name @mailer_class ? @mailer_class.name : 'ActionMailer::Base' end - def job_match?(job) + def job_matches?(job) legacy_mail?(job) || parameterized_mail?(job) || unified_mail?(job) end @@ -123,7 +123,7 @@ def check_active_job_adapter def unmatching_mail_jobs @unmatching_jobs.select do |job| - job_match?(job) + job_matches?(job) end end diff --git a/lib/rspec/rails/version.rb b/lib/rspec/rails/version.rb index 7fa7d3a8e..6b24e7e04 100644 --- a/lib/rspec/rails/version.rb +++ b/lib/rspec/rails/version.rb @@ -3,7 +3,7 @@ module Rails # Version information for RSpec Rails. module Version # Current version of RSpec Rails, in semantic versioning format. - STRING = '7.0.1' + STRING = '7.0.2' end end end diff --git a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index cc4b05a06..14b886189 100644 --- a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb +++ b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb @@ -20,6 +20,10 @@ class AnotherTestMailer < ActionMailer::Base def test_email; end end + class NonMailerJob < ActiveJob::Base + def perform; end + end + if RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? class UnifiedMailer < ActionMailer::Base self.delivery_job = ActionMailer::MailDeliveryJob @@ -95,6 +99,10 @@ def test_email; end expect { }.not_to have_enqueued_email end + it "passes when negated with 0 arguments and a non-mailer job is enqueued" do + expect { NonMailerJob.perform_later }.not_to have_enqueued_email + end + it "passes when only given mailer argument" do expect { TestMailer.test_email.deliver_later @@ -305,11 +313,6 @@ def test_email; end end it "generates a failure message with unmatching enqueued mail jobs" do - non_mailer_job = Class.new(ActiveJob::Base) do - def perform; end - def self.name; "NonMailerJob"; end - end - send_time = Date.tomorrow.noon queue = 'urgent_mail' @@ -320,7 +323,7 @@ def self.name; "NonMailerJob"; end expect { expect { - non_mailer_job.perform_later + NonMailerJob.perform_later TestMailer.test_email.deliver_later TestMailer.email_with_args(3, 4).deliver_later(wait_until: send_time, queue: queue) }.to have_enqueued_email(TestMailer, :email_with_args).with(1, 2) @@ -373,7 +376,13 @@ def self.name; "NonMailerJob"; end } end - context 'when parameterized', skip: !RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? do + context 'when parameterized' do + before do + unless RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? + skip "This version of Rails does not support parameterized mailers" + end + end + it "passes when mailer is parameterized" do expect { TestMailer.with('foo' => 'bar').test_email.deliver_later