Skip to content

Commit

Permalink
Capture logging and include assertion for expected output
Browse files Browse the repository at this point in the history
  • Loading branch information
bettymakes committed Aug 7, 2022
1 parent 6854947 commit 686a9c1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/unit/mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MailerTest < ActionMailer::TestCase
@user = create(:user)
create(:rubygem, owners: [@user], downloads: MIN_DOWNLOADS_FOR_MFA_RECOMMENDATION_POLICY)

Rake::Task["mfa_policy:announce_recommendation"].invoke
@io_output, _error = capture_io { Rake::Task["mfa_policy:announce_recommendation"].execute }
Delayed::Worker.new.work_off
end

Expand All @@ -20,6 +20,7 @@ class MailerTest < ActionMailer::TestCase
assert_equal ["[email protected]"], email.from
assert_equal "Please enable multi-factor authentication on your RubyGems account", email.subject
assert_match "Thank you for making the RubyGems ecosystem more secure", email.text_part.body.to_s
assert_match "Sending 1 MFA announcement email", @io_output
end
end

Expand All @@ -28,7 +29,8 @@ class MailerTest < ActionMailer::TestCase
user = create(:user, mfa_level: "disabled")
create(:rubygem, owners: [user], downloads: MIN_DOWNLOADS_FOR_MFA_REQUIRED_POLICY)

Rake::Task["mfa_policy:reminder_enable_mfa"].invoke
@io_output, _error = capture_io { Rake::Task["mfa_policy:reminder_enable_mfa"].execute }

Delayed::Worker.new.work_off

refute_empty ActionMailer::Base.deliveries
Expand All @@ -37,6 +39,7 @@ class MailerTest < ActionMailer::TestCase
assert_equal ["[email protected]"], email.from
assert_equal "[Action Required] Enable multi-factor authentication on your RubyGems account by August 15", email.subject
assert_match "Thank you for making the RubyGems ecosystem more secure", email.text_part.body.to_s
assert_match "Sending 1 MFA reminder email", @io_output
end
end

Expand Down

0 comments on commit 686a9c1

Please sign in to comment.