ruby-on-rails - 使用 rspec 测试邮件程序 'from' header

标签 ruby-on-rails testing actionmailer rspec-rails

我正在开发一个 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/

相关文章:

ruby-on-rails - 如何根据出生日期列出用户的年龄

jquery - 如何在rails中的数据表中发送参数

angularjs - 如何在 Protractor 中模拟拖放 Action ?

ruby-on-rails - ActionMailer 传递命令返回什么?

ruby-on-rails - 如何在 ActionMailer 中使用 Devise 助手?

ruby-on-rails - ActionMailer 测试在 Rails 3.2.8 中失败

ruby-on-rails - 在 Rails 上扩展 Flash 消息的功能?自动隐藏、嵌入链接 ?关闭按钮?

ruby-on-rails - 如何在 rails 3.2 (ActionView::PathSet) 中添加 rails View 路径

python - Django 在测试期间无法刷新数据库

internet-explorer - 网络开发测试?