【问题标题】:NoMethodError: undefined method `body' for nil:NilClass (test failure)NoMethodError: nil:NilClass 的未定义方法“body”(测试失败)
【发布时间】:2019-12-29 06:30:26
【问题描述】:

我得到一个失败(在 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? :/

【问题讨论】:

    标签: ruby-on-rails ruby rubygems ruby-on-rails-5


    【解决方案1】:

    html_part是设置如果你发送多部分邮件,你可以调用mail.body.to_s代替,应该设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-14
      • 2013-01-14
      • 2017-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多