From e3cf607ce854d958da1aade2a2b006aecad5888d Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 4 Sep 2024 11:50:33 +0100 Subject: [PATCH 01/10] Documentation improvements --- README.md | 2 +- features/Generators.md | 19 +++++++++---------- .../{GettingStarted.md => Getting_started.md} | 0 3 files changed, 10 insertions(+), 11 deletions(-) rename features/{GettingStarted.md => Getting_started.md} (100%) 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/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 From bc6dfc71fd2c77bff166c6db1b4f2921c2a2bf64 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 4 Sep 2024 18:28:38 +0100 Subject: [PATCH 02/10] Merge pull request #2794 from rspec/fix-ruby-3-3-5 Silence warning in mailer preview path check --- .../spec/verify_mailer_preview_path_spec.rb | 2 ++ features/backtrace_filtering.feature | 4 ++-- spec/rspec/rails/matchers/have_enqueued_mail_spec.rb | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) 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/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/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index cc4b05a06..0503080ba 100644 --- a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb +++ b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb @@ -373,7 +373,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 From 5280ba1345fbbbfce1e71a5b874918466ad2003c Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 5 Sep 2024 13:49:03 +0100 Subject: [PATCH 03/10] Merge pull request #2798 from rspec/fix-rails-main-for-solid-cache Fix rails main for solid cache --- Rakefile | 14 ++++++++++++-- example_app_generator/generate_stuff.rb | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) 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 From fb19d53c7aa1520c7491dc88cbd44c6a06e8b9b6 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 5 Sep 2024 13:49:43 +0100 Subject: [PATCH 04/10] Merge pull request #2793 from davidrunger/update-have-enqueued-mail-method-name Update method name in HaveEnqueuedMail (job_match? to job_matches?) --- Changelog.md | 5 +++++ lib/rspec/rails/matchers/have_enqueued_mail.rb | 4 ++-- .../rails/matchers/have_enqueued_mail_spec.rb | 15 +++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index a5a654bfa..42b7f1ab2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,11 @@ ### Development [Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.1...7-0-maintenance) +Bug Fixes: + +* Fix `have_enqueued_mail` wrongful failure when expecting no enqueued mail but + a non-mail job is enqueued. (David Runger, #2793) + ### 7.0.1 / 2024-09-03 [Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.0...v7.0.1) 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/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index 0503080ba..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) From 5a9a2d1c14f3934122456fd62457d1e718d35dcd Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 5 Sep 2024 14:06:23 +0100 Subject: [PATCH 05/10] Reword changelog --- Changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 42b7f1ab2..056ef4c06 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,8 +3,8 @@ Bug Fixes: -* Fix `have_enqueued_mail` wrongful failure when expecting no enqueued mail but - a non-mail job is enqueued. (David Runger, #2793) +* 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) From 5ec0d1ff782bfe094216e36f25de7bb75bdd2888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Wed, 4 Sep 2024 09:09:36 +0200 Subject: [PATCH 06/10] Fix Changelog.md typo. --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 056ef4c06..9ccb821c9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -24,7 +24,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) From 796e5d2ec314ed948a2744ab0f713c186bdb53d9 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 9 Oct 2024 18:50:10 +0100 Subject: [PATCH 07/10] Merge pull request #2807 from johnpitchko/specify-default-system-spec-driver Explain how to set a default driver for system specs --- features/system_specs/system_specs.feature | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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). From fb0e5a1e5573b258d00b7730d98efaf8361dcaca Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 9 Oct 2024 18:51:24 +0100 Subject: [PATCH 08/10] Rails main dropped Ruby 3.1 --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) 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 From b8c0875b819ce555efce6994a233dbe666ae0bb4 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 8 Nov 2024 18:45:15 +0000 Subject: [PATCH 09/10] v7.0.2 --- Changelog.md | 5 ++++- lib/rspec/rails/version.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 9ccb821c9..7fc5bada3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ ### 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-08 +[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.1...v7.0.2) Bug Fixes: 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 From 9fb18ca05a1a9c69b2ed68cec9826bdcb9392dec Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Sat, 9 Nov 2024 09:27:42 +0000 Subject: [PATCH 10/10] Correct date for release of 7.0.2 --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 7fc5bada3..7cb4c4437 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,7 @@ ### Development [Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.2...7-0-maintenance) -### 7.0.2 / 2024-11-08 +### 7.0.2 / 2024-11-09 [Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.1...v7.0.2) Bug Fixes: