我创建了这个模块:support/mailer_macros.rb
module MailerMacros
def last_email
ActionMailer::Base.deliveries.last
end
def reset_email
ActionMailer::Base.deliveries = []
end
end
我想从我的 testhelper 中访问它,所以我在 test/test_helper.rb 中这样做了:
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
#require "capybara/rails"
require "minitest/rails/capybara"
require "support/mailer_macros"
class ActiveSupport::TestCase
include MailerMacros
reset_email
end
但是当我运行我的测试时,我得到了错误:
undefined local variable or method `reset_email' for ActiveSupport::TestCase:Class
怎么了?谢谢!