Unable to run ActionMailer assertions within tests?

104 views Asked by At

I can't figure out why I am unable to use the ActionMailer assertions within my tests. I generated a Rails 5.2.1 application from scratch, scaffolded a model, and still get a NoMethodError when I call methods like assert_emails.

require 'test_helper'

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

This raises an exception:

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

What am I missing?

1

There are 1 answers

0
Tom Rossi On

I can fix it by including it in my test_helper.rb but I'm not sure why I would have to:

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