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 - 为什么机械师对象不保存在嵌套 block 中?

ruby-on-rails - 使用 Rails Omniauth gem 和 Google OpenID 时如何不需要用户的电子邮件

ruby-on-rails - 供应商/ bundle 和 ruby 版本

java - 在测试应用程序之前初始化 Spring Boot 测试 bean

ruby-on-rails - 有没有一种 RAILS 方法可以干燥邮件程序操作/ View ?

ruby-on-rails - 扩展 spree 以具有 Shopify 的功能?

testing - Maven 测试在安装阶段失败但在测试阶段没问题

java - Selenium Chrome 驱动程序选择证书弹出确认不起作用

ruby-on-rails - Errno::ECONNREFUSED:连接被拒绝 - connect(2) for action mailer

ruby-on-rails - 在非开发层预览邮件程序