Pre-Extaction:
describe "email side effects" do
it "sent an email to the PIC" do
emails_to_pic = to_addresses.select { |to| to == pic.email }
expect(emails_to_pic.size).to eq(1)
end
context "PIC is on vacation" do
it "sent an email to the backup" do
emails_to_pic = to_addresses.select { |to| to == pic.email }
emails_to_backup = to_addresses.select { |to| to == backup_pic.email }
fail "no PIC email expected" unless emails_to_pic.empty?
expect(emails_to_backup.size).to eq(1)
end
let(:pic) { din_engineer(on_vacation_until: Date.today + 1.day) }
let(:backup_pic) { din_engineer }
let(:platform) do
din_platform do |p|
p.primary_engineer_id = pic.id
p.secondary_engineer_id = backup_pic.id
end
end
context "there is no backup engineer" do
it "emails the PIC anyway" do
emails_to_pic = to_addresses.select { |to| to == pic.email }
expect(emails_to_pic.size).to eq(1)
end
let(:backup_pic) { double(id: nil) }
end
end
let(:to_addresses) do
ActionMailer::Base.deliveries.map(&:to).flatten
end
end
Post-Extraction
describe "email side effects" do
it "sent an email to the PIC" do
expect(emails_to(pic).size).to eq(1)
end
context "PIC is on vacation" do
it "sent an email to the backup" do
fail "no PIC email expected" unless emails_to(pic).empty?
expect(emails_to(backup_pic).size).to eq(1)
end
let(:pic) { din_engineer(on_vacation_until: Date.today+1.day) }
let(:backup_pic) { din_engineer }
let(:platform) do
din_platform do |p|
p.primary_engineer_id = pic.id
p.secondary_engineer_id = backup_pic.id
end
end
context "there is no backup engineer" do
it "emails the PIC anyway" do
expect(emails_to(pic).size).to eq(1)
end
let(:backup_pic) { double(id: nil) }
end
end
let(:to_addresses) do
ActionMailer::Base.deliveries.map(&:to).flatten
end
def emails_to(person)
to_addresses.select { |to| to == person.email }
end
end
I love how lines were either removed or only changed from emails_to_pic
to emails_to(pic)