@@ -89,7 +89,7 @@ def email_with_optional_args(required_arg, optional_arg = nil); end
89
89
expect {
90
90
TestMailer . test_email . deliver_later
91
91
} . not_to have_enqueued_mail ( TestMailer , :test_email )
92
- } . to raise_error ( /expected not to enqueue TestMailer.test_email exactly 1 time, but enqueued 1/ )
92
+ } . to raise_error ( /expected not to enqueue TestMailer.test_email exactly 1 time but enqueued 1/ )
93
93
end
94
94
95
95
it "passes with :once count" do
@@ -129,7 +129,7 @@ def email_with_optional_args(required_arg, optional_arg = nil); end
129
129
it "generates a failure message with at least hint" do
130
130
expect {
131
131
expect { } . to have_enqueued_mail ( TestMailer , :test_email ) . at_least ( :once )
132
- } . to raise_error ( /expected to enqueue TestMailer.test_email at least 1 time, but enqueued 0/ )
132
+ } . to raise_error ( /expected to enqueue TestMailer.test_email at least 1 time but enqueued 0/ )
133
133
end
134
134
135
135
it "generates a failure message with at most hint" do
@@ -138,7 +138,7 @@ def email_with_optional_args(required_arg, optional_arg = nil); end
138
138
TestMailer . test_email . deliver_later
139
139
TestMailer . test_email . deliver_later
140
140
} . to have_enqueued_mail ( TestMailer , :test_email ) . at_most ( :once )
141
- } . to raise_error ( /expected to enqueue TestMailer.test_email at most 1 time, but enqueued 2/ )
141
+ } . to raise_error ( /expected to enqueue TestMailer.test_email at most 1 time but enqueued 2/ )
142
142
end
143
143
144
144
it "passes for mailer methods that accept arguments when the provided argument matcher is not used" do
@@ -183,16 +183,47 @@ def email_with_optional_args(required_arg, optional_arg = nil); end
183
183
} . to raise_error ( /expected to enqueue TestMailer.email_with_args exactly 1 time with \[ 1, 2\] , but enqueued 0/ )
184
184
end
185
185
186
+ it "passes when deliver_later is called with a wait_until argument" do
187
+ send_time = Date . tomorrow . noon
188
+
189
+ expect { TestMailer . test_email . deliver_later ( wait_until : send_time ) }
190
+ . to have_enqueued_email ( TestMailer , :test_email ) . at ( send_time )
191
+ end
192
+
193
+ it "generates a failure message with at" do
194
+ send_time = Date . tomorrow . noon
195
+
196
+ expect {
197
+ expect { TestMailer . test_email . deliver_later ( wait_until : send_time + 1 ) }
198
+ . to have_enqueued_email ( TestMailer , :test_email ) . at ( send_time )
199
+ } . to raise_error ( /expected to enqueue TestMailer.test_email exactly 1 time at #{ send_time . inspect } / )
200
+ end
201
+
202
+ it "passes when deliver_later is called with a queue argument" do
203
+ expect { TestMailer . test_email . deliver_later ( queue : 'urgent_mail' ) }
204
+ . to have_enqueued_email ( TestMailer , :test_email ) . on_queue ( 'urgent_mail' )
205
+ end
206
+
207
+ it "generates a failure message with on_queue" do
208
+ expect {
209
+ expect { TestMailer . test_email . deliver_later ( queue : 'not_urgent_mail' ) }
210
+ . to have_enqueued_email ( TestMailer , :test_email ) . on_queue ( 'urgent_mail' )
211
+ } . to raise_error ( /expected to enqueue TestMailer.test_email exactly 1 time on queue urgent_mail/ )
212
+ end
213
+
186
214
it "generates a failure message with unmatching enqueued mail jobs" do
215
+ send_time = Date . tomorrow . noon
216
+ queue = 'urgent_mail'
217
+
187
218
message = "expected to enqueue TestMailer.email_with_args exactly 1 time with [1, 2], but enqueued 0" + \
188
219
"\n Queued deliveries:" + \
189
220
"\n TestMailer.test_email" + \
190
- "\n TestMailer.email_with_args with [3, 4]"
221
+ "\n TestMailer.email_with_args with [3, 4], on queue #{ queue } , at #{ send_time } "
191
222
192
223
expect {
193
224
expect {
194
225
TestMailer . test_email . deliver_later
195
- TestMailer . email_with_args ( 3 , 4 ) . deliver_later
226
+ TestMailer . email_with_args ( 3 , 4 ) . deliver_later ( wait_until : send_time , queue : queue )
196
227
} . to have_enqueued_email ( TestMailer , :email_with_args ) . with ( 1 , 2 )
197
228
} . to raise_error ( message )
198
229
end
0 commit comments