gpt4 book ai didi

ruby-on-rails-3 - Rails - 如何测试 ActionMailer 发送了特定附件?

转载 作者:行者123 更新时间:2023-12-03 09:53:27 25 4
gpt4 key购买 nike

在我的 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
}

并 stub 我的邮件以获取 fake_pdf 而不是通常从 S3 获取的真实 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...>

我不匹配生成的电子邮件的字符集或部分边界。

如何定义或 stub 预期电子邮件的这一方面?

最佳答案

这是我从特定附件的 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'

关于ruby-on-rails-3 - Rails - 如何测试 ActionMailer 发送了特定附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14286179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com