在我的 ActionMailer::TestCase 测试中,我期望:
@expected.to = BuyadsproMailer.group_to(campaign.agency.users)
@expected.subject = "You submitted #{offer_log.total} worth of offers for #{offer_log.campaign.name} "
@expected.from = "BuyAds Pro <feedback@buyads.com>"
@expected.body = read_fixture('deliver_to_agency')
@expected.content_type = "multipart/mixed;\r\n boundary=\"something\""
@expected.attachments["#{offer_log.aws_key}.pdf"] = {
:mime_type => 'application/pdf',
:content => fake_pdf.body
}
我希望通过对我的邮件传送程序进行修改,以便在不从S3获取真实PDF的情况下获得假的PDF文件,并确保PDF文件的内容匹配。
然而,我收到了一条异常错误信息,告诉我期望接收一封电子邮件,但却收到了一个略微不同的电子邮件。
<...Mime-Version: 1.0\r\nContent-Type: multipart/mixed\r\nContent-Transfer-Encoding: 7bit...> expected but was
<...Mime-Version: 1.0\r\nContent-Type: multipart/mixed;\r\n boundary=\"--==_mimepart_50f06fa9c06e1_118dd3fd552035ae03352b\";\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit...>
我无法匹配生成的电子邮件的字符集或部分边界。
我该如何定义或存根化预期电子邮件的这个方面?
Mail::Part
类型似乎是不必要的,如果在未来版本的Rails中类名不同,则可能会使测试变得不必要地脆弱。如果对象不是正确类型,则其响应content_type
和filename
方法的可能性极低。 - Steve Jorgensenexpect(attachment.body).to eq fake_pdf.body
。 - jwadsackexpects
语法看起来像这样:it { is_expected.to have(1).attachments }
。 - danielricecodes