【问题标题】:Testing defaults in Rails ActionMailer在 Rails ActionMailer 中测试默认值
【发布时间】:2011-09-22 03:00:37
【问题描述】:

您如何在 ActionMailer 规范中测试这些行?

default 'HEADER' => Proc.new { "information" },
  :cc => "asdf@asdf.com",
  :from => "asdf@asdf.com",
  :to => "asdf@asdf.com"

【问题讨论】:

  • 我不会担心测试默认标题和电子邮件字段,我会检查这些的 actionmailer 测试覆盖率。如果您要添加标头,我认为您可以在控制器测试中检查标头哈希,或者您可以将 curl 与 --head 一起使用并检查原始输出。

标签: ruby-on-rails ruby-on-rails-3 rspec rspec2 actionmailer


【解决方案1】:

类似的东西:

# notifier_spec.rb
require "spec_helper"

describe Notifier do
  describe "welcome" do
    let(:user) { Factory :user }
    let(:mail) { Notifier.welcome(user) }

    it "renders the headers" do
      mail.content_type.should eq('text/plain; charset=UTF-8')
      mail.subject.should eq("Welcome")
      mail.cc.should eq(["zombie@example.com"])
      mail.from.should eq(["zombie@example.com"])
      mail.to.should eq([user.email])
    end

    it "renders the body" do
      mail.body.encoded.should match("Hi")
    end
  end
end

Ryan Bates(= 一群人)就是这样做的。

【讨论】:

    猜你喜欢
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2016-10-11
    • 1970-01-01
    • 2011-02-16
    • 2021-11-30
    相关资源
    最近更新 更多