Shoulda::ActionMailer::Assertions

Public Instance Methods

assert_did_not_send_email() click to toggle source

Asserts that no ActionMailer mails were delivered

 assert_did_not_send_email
    # File lib/shoulda/action_mailer/assertions.rb, line 33
33:       def assert_did_not_send_email
34:         ::ActiveSupport::Deprecation.warn("use: should_not have_sent_email")
35:         msg = "Sent #{::ActionMailer::Base.deliveries.size} emails.\n"
36:         ::ActionMailer::Base.deliveries.each { |m| msg << "  '#{m.subject}' sent to #{m.to.to_sentence}\n" }
37:         assert ::ActionMailer::Base.deliveries.empty?, msg
38:       end
assert_sent_email() click to toggle source

Asserts that an email was delivered. Can take a block that can further narrow down the types of emails you’re expecting.

 assert_sent_email

Passes if ActionMailer::Base.deliveries has an email

 assert_sent_email do |email|
   email.subject =~ /hi there/ && email.to.include?('none@none.com')
 end

Passes if there is an email with subject containing ‘hi there’ and ‘none@none.com’ as one of the recipients.

    # File lib/shoulda/action_mailer/assertions.rb, line 18
18:       def assert_sent_email
19:       ::ActiveSupport::Deprecation.warn("use: should have_sent_email")
20:         emails = ::ActionMailer::Base.deliveries
21:         assert !emails.empty?, "No emails were sent"
22:         if block_given?
23:           matching_emails = emails.select {|email| yield email }
24:           assert !matching_emails.empty?, "None of the emails matched."
25:         end
26:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.