Skip to content

Commit 5945955

Browse files
committed
refactor(tests): convert member mailer welcome tests to delivery assertions
Replaces expect_any_instance_of mocks with direct mail content verification for welcome email tests. Changes: - 'sends the coach welcome email to coaches' - verifies email body contains coach text - 'sends the student welcome email to students' - verifies email body contains student text - 'sends a ban email to a member' - verifies recipient and email body Removes all expect_any_instance_of(MemberMailer) mocks which were problematic for parallel test execution.
1 parent efdc71d commit 5945955

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

spec/mailers/member_mailer_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,27 @@
8181
it 'sends the coach welcome email to coaches' do
8282
member = Fabricate(:coach)
8383

84-
expect_any_instance_of(MemberMailer).to receive(:welcome_coach)
85-
expect_any_instance_of(MemberMailer).not_to receive(:welcome_student)
86-
MemberMailer.welcome(member).deliver_now
84+
mail = MemberMailer.welcome(member).deliver_now
85+
86+
expect(mail.body.encoded).to match('depends on coaches attending')
8787
end
8888

8989
it 'sends the student welcome email to students' do
9090
member = Fabricate(:student)
91-
expect_any_instance_of(MemberMailer).not_to receive(:welcome_coach)
92-
expect_any_instance_of(MemberMailer).to receive(:welcome_student)
93-
MemberMailer.welcome(member).deliver_now
91+
92+
mail = MemberMailer.welcome(member).deliver_now
93+
94+
expect(mail.body.encoded).to match('Spots are limited')
9495
end
9596

9697
it 'sends a ban email to a member' do
9798
member = Fabricate(:member)
9899
ban = Fabricate(:ban)
99-
expect_any_instance_of(MemberMailer).to receive(:ban).with(member, ban)
100100

101-
MemberMailer.ban(member, ban).deliver_now
101+
mail = MemberMailer.ban(member, ban).deliver_now
102+
103+
expect(mail.to).to eq([member.email])
104+
expect(mail.body.encoded).to match('your account has been suspended')
102105
end
103106

104107
it 'actually sends a coach email' do

0 commit comments

Comments
 (0)