Reputation: 361
I'm implemented a condition that if a user's email is not confirmed, they do not receive emails. My logic is, if the email isn't verified/ confirmed, return an instance of ActionMailer::Base::NullMail.new
.
I wrote this test
if @user.verified?
next
else
ActionMailer::Base::NullMail.new
end
expect(TestMailer.test_mail(expired_account)).to be_an_instance_of(ActionMailer::Base::NullMail)
and the error I'm getting is
expected #<ActionMailer::MessageDelivery(#<ActionMailer::Base::NullMail:0x00007fb0f2f24090>)> to be a kind of ActionMailer::Base::NullMail
The question is, how can I re-write my test so that I can test that if the emails aren't verified they should return an instance of ActionMailer::Base::NullMail.new
Upvotes: 2
Views: 690
Reputation: 11216
The error is telling you what the problem is right? You expect an instance of a mail type object, so change it to this. Also you should be able to use be_a
method in place of be_an_instance_of
in Rspec see docs
expect(TestMailer.test_mail(expired_account).message)
.to be_an(ActionMailer::Base::NullMail)
Upvotes: 3