邮件器规范

默认情况下,Mailer 规范位于 spec/mailers 文件夹中。在任何上下文中添加元数据 type: :mailer 会使它的示例被视为邮件器规范。

邮件器规范是 ActionMailer::TestCase 的一个薄包装器,除了 RSpec 自身的行为和期望外,还包含它提供的所有行为和断言。

示例

require "rails_helper"

RSpec.describe Notifications, type: :mailer do
  describe "notify" do
    let(:mail) { Notifications.signup }

    it "renders the headers" do
      expect(mail.subject).to eq("Signup")
      expect(mail.to).to eq(["to@example.org"])
      expect(mail.from).to eq(["from@example.com"])
    end

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

主题