What's the meaning to test 'ActionMailer::Base.deliveries.size'?

Viewed 349

To test rails action mailer code with rspec, it's common to check ActionMailer::Base.deliveries.size like this:

it "sends an email successfully" do
  expect { mail.deliver_now }.to change { ActionMailer::Base.deliveries.size }.by(1)
end

What's the meaning of this test? What type of bug we can find by this test?

IMO, once I call the deliver method, the mail will sent automatically, that's the ActionMailer responsibility isn't that? Why we need to test ActionMailer functionality in our test code?

0 Answers
Related