【问题标题】:Fast Testing: How to test Mailer without Loading Rails快速测试:如何在不加载 Rails 的情况下测试 Mailer
【发布时间】:2013-01-28 04:19:49
【问题描述】:

我有一些工作要重构邮件程序类。我不想把所有的时间都花在加载 rails 和等待测试是否通过。我想不包括 spec_helper 并加快我的测试。

如何只包含 ActionMailer?

我试过了:

require 'action_mailer'

但我仍然遇到此错误:

uninitialized constant ActionMailer (NameError)

有什么想法吗?

【问题讨论】:

  • 我认为您需要在这里提供更多信息,尤其是 Rails、RSpec 等的哪些版本。

标签: ruby-on-rails rspec actionmailer


【解决方案1】:

我正在使用 MiniTest,以下对我来说很好用。您或许可以从中推断,或在您的问题中提供更多信息。

require 'minitest/autorun'
require 'mocha'
require "minitest-matchers"
require 'action_mailer'
require "email_spec"

require File.expand_path('../../../../app/mailers/my_mailer', __FILE__)

class MyMailerTest < MiniTest::Unit::TestCase
  include EmailSpec::Helpers
  include EmailSpec::Matchers

  def test_it_is_sent_from_me
    email = MyMailer.refund_processed(42)
    email.must be_delivered_from("me@example.com")
  end
end

【讨论】:

    猜你喜欢
    • 2012-12-23
    • 2011-04-15
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    相关资源
    最近更新 更多