Sha256: 9aed7e781523f4f5bb5c9d6f50da8840d21f2d87b90d237a1308f138029e966a

Contents?: true

Size: 1.66 KB

Versions: 197

Compression:

Stored size: 1.66 KB

Contents

module ActionMailer
  module TestHelper
    extend ActiveSupport::Concern

    # Asserts that the number of emails sent matches the given number.
    #
    #   def test_emails
    #     assert_emails 0
    #     ContactMailer.deliver_contact
    #     assert_emails 1
    #     ContactMailer.deliver_contact
    #     assert_emails 2
    #   end
    #
    # If a block is passed, that block should cause the specified number of emails to be sent.
    #
    #   def test_emails_again
    #     assert_emails 1 do
    #       ContactMailer.deliver_contact
    #     end
    #
    #     assert_emails 2 do
    #       ContactMailer.deliver_contact
    #       ContactMailer.deliver_contact
    #     end
    #   end
    def assert_emails(number)
      if block_given?
        original_count = ActionMailer::Base.deliveries.size
        yield
        new_count = ActionMailer::Base.deliveries.size
        assert_equal original_count + number, new_count, "#{number} emails expected, but #{new_count - original_count} were sent"
      else
        assert_equal number, ActionMailer::Base.deliveries.size
      end
    end

    # Assert that no emails have been sent.
    #
    #   def test_emails
    #     assert_no_emails
    #     ContactMailer.deliver_contact
    #     assert_emails 1
    #   end
    #
    # If a block is passed, that block should not cause any emails to be sent.
    #
    #   def test_emails_again
    #     assert_no_emails do
    #       # No emails should be sent from this block
    #     end
    #   end
    #
    # Note: This assertion is simply a shortcut for:
    #
    #   assert_emails 0
    def assert_no_emails(&block)
      assert_emails 0, &block
    end
  end
end

Version data entries

197 entries across 171 versions & 11 rubygems

Version Path
actionmailer-3.2.22.5 lib/action_mailer/test_helper.rb
actionmailer-3.2.22.4 lib/action_mailer/test_helper.rb
actionmailer-3.2.22.3 lib/action_mailer/test_helper.rb
actionmailer-3.2.22.2 lib/action_mailer/test_helper.rb
actionmailer-3.2.22.1 lib/action_mailer/test_helper.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.12/lib/action_mailer/test_helper.rb
actionmailer-3.2.22 lib/action_mailer/test_helper.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/actionmailer-3.2.12/lib/action_mailer/test_helper.rb
actionmailer-3.2.21 lib/action_mailer/test_helper.rb
actionmailer-3.2.20 lib/action_mailer/test_helper.rb
actionmailer-3.2.19 lib/action_mailer/test_helper.rb
actionmailer-3.2.18 lib/action_mailer/test_helper.rb
actionmailer-3.2.17 lib/action_mailer/test_helper.rb
actionmailer-3.2.16 lib/action_mailer/test_helper.rb
actionmailer-3.2.15 lib/action_mailer/test_helper.rb
actionmailer-3.2.15.rc3 lib/action_mailer/test_helper.rb
actionmailer-3.2.15.rc2 lib/action_mailer/test_helper.rb
actionmailer-3.2.15.rc1 lib/action_mailer/test_helper.rb
actionmailer-3.2.14 lib/action_mailer/test_helper.rb
actionmailer-3.2.14.rc2 lib/action_mailer/test_helper.rb