@@ -22,5 +22,68 @@ def email_with_args(arg1, arg2); end
22
22
TestMailer . test_email . deliver_later
23
23
} . to have_enqueued_mail ( TestMailer , :test_email )
24
24
end
25
+
26
+ it "passes when using the have_enqueued_email alias" do
27
+ expect {
28
+ TestMailer . test_email . deliver_later
29
+ } . to have_enqueued_email ( TestMailer , :test_email )
30
+ end
31
+
32
+ it "passes when using the enqueue_mail alias" do
33
+ expect {
34
+ TestMailer . test_email . deliver_later
35
+ } . to enqueue_mail ( TestMailer , :test_email )
36
+ end
37
+
38
+ it "passes when using the enqueue_email alias" do
39
+ expect {
40
+ TestMailer . test_email . deliver_later
41
+ } . to enqueue_email ( TestMailer , :test_email )
42
+ end
43
+
44
+ it "passes when negated" do
45
+ expect { } . not_to have_enqueued_email ( TestMailer , :test_email )
46
+ end
47
+
48
+ # it "counts only emails enqueued in the block" do
49
+ # TestMailer.test_email
50
+
51
+ # expect {
52
+ # TestMailer.test_email
53
+ # }.to have_enqueued_email(TestMailer, :test_email).once
54
+ # end
55
+
56
+ it "passes with provided argument matchers" do
57
+ expect {
58
+ TestMailer . email_with_args ( 1 , 2 ) . deliver_later
59
+ } . to have_enqueued_mail ( TestMailer , :email_with_args ) . with ( 1 , 2 )
60
+
61
+ expect {
62
+ TestMailer . email_with_args ( 1 , 2 ) . deliver_later
63
+ } . not_to have_enqueued_mail ( TestMailer , :email_with_args ) . with ( 3 , 4 )
64
+ end
65
+
66
+ it "generates a failure message" do
67
+ expect {
68
+ expect { } . to have_enqueued_email ( TestMailer , :test_email )
69
+ } . to raise_error ( /expected to enqueue TestMailer.test_email/ )
70
+ end
71
+
72
+ it "generates a failure message with arguments" do
73
+ expect {
74
+ expect { } . to have_enqueued_email ( TestMailer , :email_with_args ) . with ( 1 , 2 )
75
+ } . to raise_error ( /expected to enqueue TestMailer.email_with_args with \[ 1, 2\] / )
76
+ end
77
+
78
+ it "throws descriptive error when no test adapter set" do
79
+ queue_adapter = ActiveJob ::Base . queue_adapter
80
+ ActiveJob ::Base . queue_adapter = :inline
81
+
82
+ expect {
83
+ expect { TestMailer . test_email } . to have_enqueued_mail ( TestMailer , :test_email )
84
+ } . to raise_error ( "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`" )
85
+
86
+ ActiveJob ::Base . queue_adapter = queue_adapter
87
+ end
25
88
end
26
89
end
0 commit comments