如何在 rspec 中将 html 电子邮件的全文内容作为单行字符串获取?
假设这是mail.html.haml:
%p
This product is worth:
= @amount
So buy it now!
在 rspec 我先发送电子邮件,然后执行以下操作:
expect(ActionMailer::Base.deliveries.last.html_part.body).to include("This product is worth: €30 So buy it now")
或者:
expect(ActionMailer::Base.deliveries.last.html_part.body.raw_source).to include("This product is worth: €30 So buy it now")
或者:
expect(ActionMailer::Base.deliveries.last.html_part.body.raw_source).to have_content("This product is worth: €30 So buy it now")
这些不起作用,因为 html 像这样输出到 rspec:
+ This product is worth:
+ €30
+ So buy it now!
所以我的原始代码是正确的,但我似乎无法在 rspec 中获取它。如何将这 3 行合并为 1 行,以便我可以正确调用 include 或 have_content?
*编辑
Failure/Error:
expect(ActionMailer::Base.deliveries.last.html_part.body.raw_source).to have_content(%q|This product is worth:
€30
So buy it now!|)
expected
<p>
This product is worth:
€30
So buy it now!
Good luck!
</p>