Sha256: 8e8be08ce649f792c5b16dfb69c2349a62ae183926940807965009b7c2a45528

Contents?: true

Size: 1.29 KB

Versions: 65

Compression:

Stored size: 1.29 KB

Contents

module Shoulda # :nodoc:
  module ActionMailer # :nodoc:
    module Assertions
      # 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.
      #
      def assert_sent_email
        emails = ::ActionMailer::Base.deliveries
        assert !emails.empty?, "No emails were sent"
        if block_given?
          matching_emails = emails.select {|email| yield email }
          assert !matching_emails.empty?, "None of the emails matched."
        end
      end

      # Asserts that no ActionMailer mails were delivered
      #
      #  assert_did_not_send_email
      def assert_did_not_send_email
        msg = "Sent #{::ActionMailer::Base.deliveries.size} emails.\n"
        ::ActionMailer::Base.deliveries.each { |m| msg << "  '#{m.subject}' sent to #{m.to.to_sentence}\n" }
        assert ::ActionMailer::Base.deliveries.empty?, msg
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 17 rubygems

Version Path
Flamefork-shoulda-2.10.1 lib/shoulda/action_mailer/assertions.rb
Flamefork-shoulda-2.10.2 lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.0 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.1 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.10 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.11 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.12 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.13 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.14 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.15 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.16 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.17 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.2 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.3 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.4 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.5 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.6 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.7 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
auser-poolparty-1.3.8 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb
fairchild-poolparty-1.3.17 vendor/gems/shoulda/lib/shoulda/action_mailer/assertions.rb