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?
ruby-on-rails rspec
add a comment |
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?
ruby-on-rails rspec
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
add a comment |
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?
ruby-on-rails rspec
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
ruby-on-rails rspec
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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