Skip to content
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

Clear test mailbox from ActionMailer::Base between each example #2293

Merged
merged 4 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Bug Fixes:
(Jonathan Rochkind, #2242)
* `rails generate generator` command now creates related spec file (Joel Azemar, #2217)
* Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281)
* Leans ActionMailer test mailbox after each example (Benoit Tigeot, #2293)
Copy link
Member

@pirj pirj Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleans :D


### 4.0.0.beta4
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta3...v4.0.0.beta4)
Expand Down
1 change: 1 addition & 0 deletions lib/rspec/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def filter_rails_from_backtrace!

if RSpec::Rails::FeatureCheck.has_action_mailer?
config.include RSpec::Rails::MailerExampleGroup, type: :mailer
config.after { ActionMailer::Base.deliveries.clear }
end

if RSpec::Rails::FeatureCheck.has_active_job?
Expand Down
28 changes: 28 additions & 0 deletions spec/rspec/rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,34 @@ def self.application; end
expect(group.mailer_class).to be(a_mailer_class)
expect(group.new).to be_a(RSpec::Rails::MailerExampleGroup)
end

describe 'leans test mailbox after each example' do
let(:base_mailer) do
Class.new(ActionMailer::Base) do
default from: '[email protected]'

def welcome(to:)
mail(to: to, subject: 'subject', body: render(inline: "Hello", layout: false))
end
end
end

before do
ActionMailer::Base.delivery_method = :test
end

it 'send to email@' do
base_mailer.welcome(to: '[email protected]').deliver_now

expect(ActionMailer::Base.deliveries.map(&:to).flatten.sort).to eq(['[email protected]'])
end

it 'send to email_2@' do
base_mailer.welcome(to: '[email protected]').deliver_now

expect(ActionMailer::Base.deliveries.map(&:to).flatten.sort).to eq(['[email protected]'])
end
benoittgt marked this conversation as resolved.
Show resolved Hide resolved
end
end

it "has a default #file_fixture_path of 'spec/fixtures/files'" do
Expand Down