在我的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;rn boundary="something""
@expected.attachments["#{offer_log.aws_key}.pdf"] = {
:mime_type => 'application/pdf',
:content => fake_pdf.body
}
和存根我的邮件,以获得fake_pdf,而不是一个真正的PDF通常从S3获取,所以我确信PDF的主体匹配。
然而,我得到这个长错误告诉我,一个电子邮件是预期的,但收到了一个稍微不同的电子邮件:
<...Mime-Version: 1.0rnContent-Type: multipart/mixedrnContent-Transfer-Encoding: 7bit...> expected but was
<...Mime-Version: 1.0rnContent-Type: multipart/mixed;rn boundary="--==_mimepart_50f06fa9c06e1_118dd3fd552035ae03352b";rn charset=UTF-8rnContent-Transfer-Encoding: 7bit...>
我没有匹配生成的电子邮件的字符集或部分边界。
我如何定义或存根我期望的电子邮件的这方面?
这是我从特定附件的rspec测试中复制的一个示例,希望它能有所帮助(邮件可以通过调用您的mailer方法或在调用.deliver后偷看交付数组来创建):
mail.attachments.should have(1).attachment
attachment = mail.attachments[0]
attachment.should be_a_kind_of(Mail::Part)
attachment.content_type.should be_start_with('application/ics;')
attachment.filename.should == 'event.ics'
我有类似的东西,我想检查附加的csv的内容。我需要这样的东西,因为它看起来像r
插入了换行符:
expect(mail.attachments.first.body.encoded.gsub(/r/, '')).to(
eq(
<<~CSV
"Foo","Bar"
"1","2"
CSV
)
)