无法在测试中运行ActionMailer断言?

时间:2018-11-13 21:20:23

标签: ruby-on-rails ruby-on-rails-5.2

我不知道为什么无法在测试中使用ActionMailer断言。我从头开始生成了一个 Rails 5.2.1 应用程序,搭建了一个模型,当我调用诸如assert_emails之类的方法时,仍然出现NoMethodError。

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  test "the truth" do
    assert_emails 0 do
      assert true
    end
  end
end

这引发了一个异常:

NoMethodError: undefined method `assert_emails' for #<UserTest:0x007ff3ebeb58c0>

我想念什么?

1 个答案:

答案 0 :(得分:0)

我可以通过将其包含在test_helper.rb中来对其进行修复,但是我不确定为什么必须这样做:

class ActiveSupport::TestCase
  include ActionMailer::TestHelper
  ...
end