rspec-rails: Possible regression 4.0.0.beta4 to 4.0.0.rc1: List of ActionMailer deliveries is not cleared between specs
What Ruby, Rails and RSpec versions are you using?
Ruby version: 2.7.0 Rails version: 6.0.2 RSpec version: 4.0.0.rc1
The following is included for these mailer tests:
RSpec.configure do |config| config.include ActionMailer::TestHelper end
Observed behaviour
When running specs, we check the to adresses that are set for the ActionMailer::Base.deliveries, like this:
expect(ActionMailer::Base.deliveries.map(&:to).flatten.include?(leo.email)).to eq true
expect(ActionMailer::Base.deliveries.map(&:to).flatten.sort).to eq([droid.email, leo.email])
This works for version 4.0.0.beta3 and 4.0.0.beta4, but for 4.0.0.rc1, this will break.
It seems that the deliveries array is not cleared between specs. The list of email addresses that are stored in the TO of the mailer, will get larger after each spec. Therefore, running each spec seperately works, but when the fourth or fifth spec is ran, the list of adresses is way bigger than expected:
expected: ["droid@cm.nl", "leo@cm.nl"]
got: ["droid@cm.nl", "droid@cm.nl", "leo@cm.nl", "leo@cm.nl", "leo@hoefsmit.nl"]
Expected behaviour
The ActionMailer instance is reset between each spec and the TO, CC and BCC attributes of ActionMailer::Base.deliveries should be cleared between each spec.
Can you provide an example app?
I have isolated the issue into an example app: https://github.com/CUnknown/rspec-rails-bug-example
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 20 (15 by maintainers)
Commits related to this issue
- Let the user choose active job queue in system test This reverts commit 3e4c770f529237dbaa5877ff80aa0d0b4594b0d1. Do not remove ::ActionDispatch::IntegrationTest::Behavior because this lead to unwan... — committed to rspec/rspec-rails by benoittgt 4 years ago
- Clear test mailbox from ActionMailer::Base between each example We notice in https://github.com/rspec/rspec-rails/issues/2290 that ActionMailer::Base.deliveries mailbox is not cleaned between example... — committed to rspec/rspec-rails by benoittgt 4 years ago
- Clear test mailbox from ActionMailer::Base between each example We notice in https://github.com/rspec/rspec-rails/issues/2290 that ActionMailer::Base.deliveries mailbox is not cleaned between example... — committed to rspec/rspec-rails by benoittgt 4 years ago
- Clear test mailbox from ActionMailer::Base between each example We notice in https://github.com/rspec/rspec-rails/issues/2290 that ActionMailer::Base.deliveries mailbox is not cleaned between example... — committed to rspec/rspec-rails by benoittgt 4 years ago