[英]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. 我正在开发一个ruby on rails项目,我正在尝试测试'from'头字段,但测试用例失败了。
Here is what I am setting in the mailer action 这是我在邮件程序中设置的内容
def some_actoin
mail(to: xyz@example.com,
from: '"Example" <service@example.com>',
subject: "test subject")
end
end
And in the rspec test case, 在rspec测试案例中,
mail.from.should == '"Example" <service@example.com>'
My test case is failing with following error 我的测试用例失败,出现以下错误
expected: '"Example" <service@example.com>'
got: [service@example.com] (using ==)
Is is the wrong way to test from-header title with from-header email address ? 用from-header电子邮件地址测试from-header标题是错误的方法吗?
Appreciates any help! 感谢任何帮助!
The mail.from
just contains the from email address. mail.from
只包含来自电子邮件的地址。 You'll want to test the display name too. 您也想测试显示名称。
mail.from.should eq(['service@example.com'])
mail[:from].display_names.should eq(['Example'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.