有很多关于如何测试邮件的信息。
但是我还没有找到任何资源来测试邮件程序以检查他们是否真的使用了正确的模板。
例子:
class NewsletterMailer < ActionMailer::Base
include SendGrid
default from: -> { SystemConfiguration.newsletter_from_email }
def send_newsletter_to_groups(newsletter_campaign_id, group_ids)
newsletter_campaign = NewsletterCampaign.find newsletter_campaign_id
emails = Group.where(:id => group_ids).map(&:emails).flatten
build_and_send_email(newsletter_campaign, emails)
end
end
app/views/newsletter_mailer/send_newsletter_to_group.html.erb
我有错字。
我写send_newsletter_to_group.html.erb
而不是send_newsletter_to_groups.html.erb
我的规格仍然通过:
require "spec_helper"
describe NewsletterMailer do
before { create(:system_configuration) }
let(:newsletter) { create(:newsletter_campaign) }
describe '.send_newsletter_to_groups' do
before do
create(:system_configuration)
create_list(:group, 3)
create_list(:user, 2, groups: [Group.first], newsletter_subscription: true)
create_list(:user, 2, groups: [Group.last], newsletter_subscription: true)
create_list(:user, 2, name: "pippo")
end
let(:group_ids) { Group.pluck(:id) }
subject { NewsletterMailer.send_newsletter_to_groups(newsletter.id, group_ids) }
its(:to) { should == User.where("name != 'pippo'").map(&:email) }
its(:from) { should be_present }
its(:subject) { should be_present }
end
end
但是电子邮件不包含正文。
它只是发送空白电子邮件,因为部分名称(send_newsletter_to_group.html.erb
)我打错了。
如何测试这个?在梅勒。