Testing mailbox from the header by a rspec

I am working on a ruby ​​on rails project where I am trying to check the header field 'from', but the test case does not work.

Here's what I install in action mailer

def some_actoin mail(to: xyz@example.com , from: '"Example" < service@example.com >', subject: "test subject") end end 

And in the test case rspec

 mail.from.should == '"Example" < service@example.com >' 

In my test case, the error with the following error

 expected: '"Example" < service@example.com >' got: [ service@example.com ] (using ==) 

Is the wrong way to check header header with the email address with the title?

I appreciate any help!

+6
source share
1 answer

mail.from simply contains an email address. You may also want to check the display name.

 mail.from.should eq([' service@example.com ']) mail[:from].display_names.should eq(['Example']) 
+9
source

All Articles