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











up vote
2
down vote

favorite












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?










share|improve this question
























  • Try to make a typo in your mailer class and you will see why we do test this. It is more like an integration test. We are testing here if our code sends an email.
    – P. Boro
    Nov 6 at 14:25








  • 2




    I don't think this is a good test. It looks like it belongs to the ActionMailer proyect and not yours. @P.Boro if you want to prevent typos, you could have better and more clear specs (mailer spec for the mailer method, view tests for the template).
    – arieljuod
    Nov 6 at 14:31















up vote
2
down vote

favorite












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?










share|improve this question
























  • Try to make a typo in your mailer class and you will see why we do test this. It is more like an integration test. We are testing here if our code sends an email.
    – P. Boro
    Nov 6 at 14:25








  • 2




    I don't think this is a good test. It looks like it belongs to the ActionMailer proyect and not yours. @P.Boro if you want to prevent typos, you could have better and more clear specs (mailer spec for the mailer method, view tests for the template).
    – arieljuod
    Nov 6 at 14:31













up vote
2
down vote

favorite









up vote
2
down vote

favorite











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?










share|improve this question















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?







ruby-on-rails rspec






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 9:10









fool-dev

5,57272440




5,57272440










asked Nov 6 at 12:43









mogya

565




565












  • Try to make a typo in your mailer class and you will see why we do test this. It is more like an integration test. We are testing here if our code sends an email.
    – P. Boro
    Nov 6 at 14:25








  • 2




    I don't think this is a good test. It looks like it belongs to the ActionMailer proyect and not yours. @P.Boro if you want to prevent typos, you could have better and more clear specs (mailer spec for the mailer method, view tests for the template).
    – arieljuod
    Nov 6 at 14:31


















  • Try to make a typo in your mailer class and you will see why we do test this. It is more like an integration test. We are testing here if our code sends an email.
    – P. Boro
    Nov 6 at 14:25








  • 2




    I don't think this is a good test. It looks like it belongs to the ActionMailer proyect and not yours. @P.Boro if you want to prevent typos, you could have better and more clear specs (mailer spec for the mailer method, view tests for the template).
    – arieljuod
    Nov 6 at 14:31
















Try to make a typo in your mailer class and you will see why we do test this. It is more like an integration test. We are testing here if our code sends an email.
– P. Boro
Nov 6 at 14:25






Try to make a typo in your mailer class and you will see why we do test this. It is more like an integration test. We are testing here if our code sends an email.
– P. Boro
Nov 6 at 14:25






2




2




I don't think this is a good test. It looks like it belongs to the ActionMailer proyect and not yours. @P.Boro if you want to prevent typos, you could have better and more clear specs (mailer spec for the mailer method, view tests for the template).
– arieljuod
Nov 6 at 14:31




I don't think this is a good test. It looks like it belongs to the ActionMailer proyect and not yours. @P.Boro if you want to prevent typos, you could have better and more clear specs (mailer spec for the mailer method, view tests for the template).
– arieljuod
Nov 6 at 14:31

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53172174%2fwhats-the-meaning-to-test-actionmailerbase-deliveries-size%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53172174%2fwhats-the-meaning-to-test-actionmailerbase-deliveries-size%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings