测试Rails ActionMailer中的默认值

时间:2011-09-22 03:00:37

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

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

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

1 个答案:

答案 0 :(得分: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(=整个buncha人)的做法。