Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing mailer 'from' header using rspec

I am working on a ruby on rails project, where I am trying to test the 'from' header field but the test case fails.

Here is what I am setting in the mailer action

def some_actoin
  mail(to: [email protected],
         from: '"Example" <[email protected]>',
         subject: "test subject")
  end
end

And in the rspec test case,

mail.from.should == '"Example" <[email protected]>'

My test case is failing with following error

expected: '"Example" <[email protected]>'
got: [[email protected]] (using ==)

Is is the wrong way to test from-header title with from-header email address?

Appreciates any help!

like image 629
nkm Avatar asked Mar 18 '14 12:03

nkm


1 Answers

The mail.from just contains the from email address. You'll want to test the display name too.

mail.from.should eq(['[email protected]'])
mail[:from].display_names.should eq(['Example'])
like image 164
Sam Avatar answered Oct 14 '22 13:10

Sam