Sha256: 7cec448ab0706ea9650135c641b1dc8e820f9a790364af72356e31c1f4b8d409

Contents?: true

Size: 1.56 KB

Versions: 91

Compression:

Stored size: 1.56 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
      ::ActiveSupport::Deprecation.warn("use: should have_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

      # should have_sent_email.with_subject(/hi there/).to('none@none.com').from('noreply@example.com').with_body(/reach out/)

      # Asserts that no ActionMailer mails were delivered
      #
      #  assert_did_not_send_email
      def assert_did_not_send_email
        ::ActiveSupport::Deprecation.warn("use: should_not have_sent_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

91 entries across 61 versions & 10 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
challah-0.6.2 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
challah-0.6.1 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb
challah-0.6.0 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_mailer/assertions.rb