Froze rails gems
[depot.git] / vendor / rails / actionmailer / lib / action_mailer / test_helper.rb
1 module ActionMailer
2 module TestHelper
3 # Asserts that the number of emails sent matches the given number.
4 #
5 # def test_emails
6 # assert_emails 0
7 # ContactMailer.deliver_contact
8 # assert_emails 1
9 # ContactMailer.deliver_contact
10 # assert_emails 2
11 # end
12 #
13 # If a block is passed, that block should cause the specified number of emails to be sent.
14 #
15 # def test_emails_again
16 # assert_emails 1 do
17 # ContactMailer.deliver_contact
18 # end
19 #
20 # assert_emails 2 do
21 # ContactMailer.deliver_contact
22 # ContactMailer.deliver_contact
23 # end
24 # end
25 def assert_emails(number)
26 if block_given?
27 original_count = ActionMailer::Base.deliveries.size
28 yield
29 new_count = ActionMailer::Base.deliveries.size
30 assert_equal original_count + number, new_count, "#{number} emails expected, but #{new_count - original_count} were sent"
31 else
32 assert_equal number, ActionMailer::Base.deliveries.size
33 end
34 end
35
36 # Assert that no emails have been sent.
37 #
38 # def test_emails
39 # assert_no_emails
40 # ContactMailer.deliver_contact
41 # assert_emails 1
42 # end
43 #
44 # If a block is passed, that block should not cause any emails to be sent.
45 #
46 # def test_emails_again
47 # assert_no_emails do
48 # # No emails should be sent from this block
49 # end
50 # end
51 #
52 # Note: This assertion is simply a shortcut for:
53 #
54 # assert_emails 0
55 def assert_no_emails(&block)
56 assert_emails 0, &block
57 end
58 end
59 end
60
61 module Test
62 module Unit
63 class TestCase
64 include ActionMailer::TestHelper
65 end
66 end
67 end