ruby-on-rails - NoMethodError: nil:NilClass 的未定义方法“body”(测试失败)
问题描述
我得到一个失败(在 premailer-rails 中)这样说:
ActionMailer::Base delivery delivers email with inlined CSS
Failure/Error: body = mail.html_part.body.to_s
NoMethodError:
undefined method `body' for nil:NilClass
# ./spec/integration/delivery_spec.rb:9:in `block (2 levels) in <top (required)>'
这是spec/integration/delivery_spec.rb
:
require 'spec_helper'
describe 'ActionMailer::Base delivery' do
it 'delivers email with inlined CSS' do
WelcomeMailer.welcome_email("world").deliver_now
mail = ActionMailer::Base.deliveries.last
expect(mail).to be_present
body = mail.html_part.body.to_s
expect(body).to be_present
expect(body).to include(%{<p style="font-size: 12px;">Hello world</p>})
end
end
不确定发生了什么;为什么会出现 NoMethodError?:/
解决方案
html_part
如果您发送多部分电子邮件,则设置,您可以mail.body.to_s
改为调用,它应该设置。
推荐阅读
- android - 由于未知原因,Android file.exists 返回 false
- amazon-web-services - CloudFormation 部署是否应该通过 CI/CD 完成?
- python - 如何从熊猫数据框中的列中删除文本
- hana - 如何在使用 HANA DB 运行的 HANA XS 上部署 Fiori Launchpad?
- angular - Ngrx 和 Angular 6 中带有 HttpClient 的解析器
- java - 你如何让 Mockito 与 Kotlin 不可为空的类型配合得很好?
- java - 离线保存 Blogger 提取的数据
- c# - ImmutableHashSet RemoveWhere
- amazon-dynamodb - 由同一个 DynamoDB 表支持的多个微服务?
- javascript - 如何用ajax调用href函数