Skip to content

Commit

Permalink
Merge branch 'add-test-mailbox-clear' into 4-0-maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Mar 24, 2020
2 parents 52d1665 + a597994 commit 90e8b7b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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)
* Clear ActionMailer test mailbox after each example (Benoit Tigeot, #2293)

### 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 'clears ActionMailer::Base::Deliveries after each example' do
let(: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 'only has deliveries from this test (e.g. from [email protected])' do
mailer.welcome(to: '[email protected]').deliver_now

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

it 'only has deliveries from this test (e.g. from [email protected])' do
mailer.welcome(to: '[email protected]').deliver_now

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

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

0 comments on commit 90e8b7b

Please sign in to comment.