Sha256: fa3f5c99c0c79939376342f876d65e30ac8e27f595b1e59a5c67b5891239f712

Contents?: true

Size: 1.39 KB

Versions: 48

Compression:

Stored size: 1.39 KB

Contents

module ThoughtBot # :nodoc:
  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
end

Version data entries

48 entries across 48 versions & 11 rubygems

Version Path
emschwar-shoulda-2.0.6.1 lib/shoulda/action_mailer/assertions.rb
francois-shoulda-2.0.5.1 lib/shoulda/action_mailer/assertions.rb
francois-shoulda-2.0.5.2 lib/shoulda/action_mailer/assertions.rb
francois-shoulda-2.0.5.4 lib/shoulda/action_mailer/assertions.rb
gsterndale-warrant-0.2.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.6/lib/shoulda/action_mailer/assertions.rb
gsterndale-warrant-0.3.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.6/lib/shoulda/action_mailer/assertions.rb
hashrocket-clearance-0.4.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/lib/shoulda/action_mailer/assertions.rb
hashrocket-clearance-0.4.1 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/lib/shoulda/action_mailer/assertions.rb
hashrocket-clearance-0.4.2 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/lib/shoulda/action_mailer/assertions.rb
hashrocket-clearance-0.4.3 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/lib/shoulda/action_mailer/assertions.rb
mattknox-goaloc-0.3.0 lib/goaloc/generators/resources/shoulda/lib/shoulda/action_mailer/assertions.rb
mattknox-goaloc-0.4.0 lib/goaloc/generators/resources/shoulda/lib/shoulda/action_mailer/assertions.rb
mjankowski-shoulda-2.0.4 lib/shoulda/action_mailer/assertions.rb
mjankowski-shoulda-2.0.5 lib/shoulda/action_mailer/assertions.rb
rmm5t-shoulda-2.0.2 lib/shoulda/action_mailer/assertions.rb
rmm5t-shoulda-2.0.5 lib/shoulda/action_mailer/assertions.rb
rmm5t-shoulda-2.0.6 lib/shoulda/action_mailer/assertions.rb
technicalpickles-shoulda-2.0.0 lib/shoulda/action_mailer/assertions.rb
technicalpickles-shoulda-2.0.1 lib/shoulda/action_mailer/assertions.rb
technicalpickles-shoulda-2.0.2 lib/shoulda/action_mailer/assertions.rb