I want to send an email from a mailer during a unit-test. I have an empty fixture directory in /tests/fixtures/user_mailer/invite.yml
I run the code in the rails console and the mailer sends successfully. However, I cannot call the class and the method from within the test itself, even when I try dropping in a binding.pry and calling the mailer manually.
require 'test_helper'
class UserMailerTest < ActionMailer::TestCase
test "invite" do
# Create the email and store it for further assertions
email = UserMailer.create_invite('me@example.com',
'friend@example.com', Time.now)
# Send the email, then test that it got queued
assert_emails 1 do
email.deliver_now
end
# Test the body of the sent email contains what we expect it to
assert_equal read_fixture('invite').join, email.body.to_s
end
end
The error Message I receive is:
UserMailerTest#invite[/Users/richardjarram/code/catonmat/yap-backend/test/mailers/bug_mailer_test.rb:10]:
1 emails expected, but 0 were sent.
Expected: 1
Actual: 0
Aucun commentaire:
Enregistrer un commentaire