我正在开发一个 ruby on rails 项目,我正在尝试测试“from” header 字段,但测试用例失败。
这是我在邮件操作中设置的内容
def some_actoin
mail(to: xyz@example.com,
from: '"Example" <service@example.com>',
subject: "test subject")
end
end
在 rspec 测试用例中,
mail.from.should == '"Example" <service@example.com>'
我的测试用例因以下错误而失败
expected: '"Example" <service@example.com>'
got: [service@example.com] (using ==)
用发件人电子邮件地址测试发件人标题的方法是否错误?
感谢任何帮助!
最佳答案
mail.from
仅包含发件人电子邮件地址。您还需要测试显示名称。
mail.from.should eq(['service@example.com'])
mail[:from].display_names.should eq(['Example'])
关于ruby-on-rails - 使用 rspec 测试邮件程序 'from' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22479862/