@@ -152,7 +152,7 @@ def perform; raise StandardError; end
152152 it "fails when job is not enqueued" do
153153 expect {
154154 expect { }.to have_enqueued_job
155- }.to raise_error (/expected to enqueue exactly 1 jobs, but enqueued 0/)
155+ }.to fail_with (/expected to enqueue exactly 1 jobs, but enqueued 0/)
156156 end
157157
158158 it "fails when too many jobs enqueued" do
@@ -161,20 +161,20 @@ def perform; raise StandardError; end
161161 heavy_lifting_job.perform_later
162162 heavy_lifting_job.perform_later
163163 }.to have_enqueued_job.exactly(1)
164- }.to raise_error (/expected to enqueue exactly 1 jobs, but enqueued 2/)
164+ }.to fail_with (/expected to enqueue exactly 1 jobs, but enqueued 2/)
165165 end
166166
167167 it "reports correct number in fail error message" do
168168 heavy_lifting_job.perform_later
169169 expect {
170170 expect { }.to have_enqueued_job.exactly(1)
171- }.to raise_error (/expected to enqueue exactly 1 jobs, but enqueued 0/)
171+ }.to fail_with (/expected to enqueue exactly 1 jobs, but enqueued 0/)
172172 end
173173
174174 it "fails when negated and job is enqueued" do
175175 expect {
176176 expect { heavy_lifting_job.perform_later }.not_to have_enqueued_job
177- }.to raise_error (/expected not to enqueue at least 1 jobs, but enqueued 1/)
177+ }.to fail_with (/expected not to enqueue at least 1 jobs, but enqueued 1/)
178178 end
179179
180180 it "fails when negated and several jobs enqueued" do
@@ -183,7 +183,7 @@ def perform; raise StandardError; end
183183 heavy_lifting_job.perform_later
184184 heavy_lifting_job.perform_later
185185 }.not_to have_enqueued_job
186- }.to raise_error (/expected not to enqueue at least 1 jobs, but enqueued 2/)
186+ }.to fail_with (/expected not to enqueue at least 1 jobs, but enqueued 2/)
187187 end
188188
189189 it "passes with job name" do
@@ -238,7 +238,7 @@ def perform; raise StandardError; end
238238 it "generates failure message with at least hint" do
239239 expect {
240240 expect { }.to have_enqueued_job.at_least(:once)
241- }.to raise_error (/expected to enqueue at least 1 jobs, but enqueued 0/)
241+ }.to fail_with (/expected to enqueue at least 1 jobs, but enqueued 0/)
242242 end
243243
244244 it "generates failure message with at most hint" do
@@ -247,7 +247,7 @@ def perform; raise StandardError; end
247247 hello_job.perform_later
248248 hello_job.perform_later
249249 }.to have_enqueued_job.at_most(:once)
250- }.to raise_error (/expected to enqueue at most 1 jobs, but enqueued 2/)
250+ }.to fail_with (/expected to enqueue at most 1 jobs, but enqueued 2/)
251251 end
252252
253253 it "passes with provided queue name as string" do
@@ -291,7 +291,7 @@ def perform; raise StandardError; end
291291 travel_to time do
292292 expect {
293293 expect { hello_job.set(wait: 5).perform_later }.to have_enqueued_job.at(time + 5)
294- }.to raise_error (/expected to enqueue exactly 1 jobs/)
294+ }.to fail_with (/expected to enqueue exactly 1 jobs/)
295295 end
296296 end
297297
@@ -315,7 +315,7 @@ def perform; raise StandardError; end
315315 expect {
316316 hello_job.perform_later
317317 }.to have_enqueued_job.at(date)
318- }.to raise_error (/expected to enqueue exactly 1 jobs, at .+ but enqueued 0/)
318+ }.to fail_with (/expected to enqueue exactly 1 jobs, at .+ but enqueued 0/)
319319 end
320320
321321 it "has an enqueued job when not providing at and there is a wait" do
@@ -343,21 +343,15 @@ def perform; raise StandardError; end
343343 expect {
344344 two_args_job.perform_later(1)
345345 }.to have_enqueued_job.with(1)
346- }.to raise_error(
347- RSpec::Expectations::ExpectationNotMetError,
348- /Incorrect arguments passed to TwoArgsJob: Wrong number of arguments/
349- )
346+ }.to fail_with(/Incorrect arguments passed to TwoArgsJob: Wrong number of arguments/)
350347 end
351348
352349 it "fails if the job's signature/arguments are mismatched keyword/positional arguments" do
353350 expect {
354351 expect {
355352 keyword_args_job.perform_later(1, 2)
356353 }.to have_enqueued_job.with(1, 2)
357- }.to raise_error(
358- RSpec::Expectations::ExpectationNotMetError,
359- /Incorrect arguments passed to KeywordArgsJob: Missing required keyword arguments/
360- )
354+ }.to fail_with(/Incorrect arguments passed to KeywordArgsJob: Missing required keyword arguments/)
361355 end
362356
363357 it "passes with provided arguments containing global id object" do
@@ -384,7 +378,7 @@ def perform; raise StandardError; end
384378 expect {
385379 hello_job.perform_later(1)
386380 }.to have_enqueued_job(hello_job).with(42).on_queue("low").at(date).exactly(2).times
387- }.to raise_error (message)
381+ }.to fail_with (message)
388382 end
389383
390384 it "throws descriptive error when no test adapter set" do
@@ -490,37 +484,31 @@ def perform; raise StandardError; end
490484 it "fails when job is not enqueued" do
491485 expect {
492486 expect(heavy_lifting_job).to have_been_enqueued
493- }.to raise_error (/expected to enqueue exactly 1 jobs, but enqueued 0/)
487+ }.to fail_with (/expected to enqueue exactly 1 jobs, but enqueued 0/)
494488 end
495489
496490 it "fails if the arguments do not match the job's signature" do
497491 two_args_job.perform_later(1)
498492
499493 expect {
500494 expect(two_args_job).to have_been_enqueued.with(1)
501- }.to raise_error(
502- RSpec::Expectations::ExpectationNotMetError,
503- /Incorrect arguments passed to TwoArgsJob: Wrong number of arguments/
504- )
495+ }.to fail_with(/Incorrect arguments passed to TwoArgsJob: Wrong number of arguments/)
505496 end
506497
507498 it "fails if the job's signature/arguments are mismatched keyword/positional arguments" do
508499 keyword_args_job.perform_later(1, 2)
509500
510501 expect {
511502 expect(keyword_args_job).to have_been_enqueued.with(1, 2)
512- }.to raise_error(
513- RSpec::Expectations::ExpectationNotMetError,
514- /Incorrect arguments passed to KeywordArgsJob: Missing required keyword arguments/
515- )
503+ }.to fail_with(/Incorrect arguments passed to KeywordArgsJob: Missing required keyword arguments/)
516504 end
517505
518506 it "fails when negated and several jobs enqueued" do
519507 heavy_lifting_job.perform_later
520508 heavy_lifting_job.perform_later
521509 expect {
522510 expect(heavy_lifting_job).not_to have_been_enqueued
523- }.to raise_error (/expected not to enqueue at least 1 jobs, but enqueued 2/)
511+ }.to fail_with (/expected not to enqueue at least 1 jobs, but enqueued 2/)
524512 end
525513
526514 it "accepts composable matchers as an at date" do
@@ -569,7 +557,7 @@ def perform; raise StandardError; end
569557 it "fails when job is not performed" do
570558 expect {
571559 expect { }.to have_performed_job
572- }.to raise_error (/expected to perform exactly 1 jobs, but performed 0/)
560+ }.to fail_with (/expected to perform exactly 1 jobs, but performed 0/)
573561 end
574562
575563 it "fails when too many jobs performed" do
@@ -578,20 +566,20 @@ def perform; raise StandardError; end
578566 heavy_lifting_job.perform_later
579567 heavy_lifting_job.perform_later
580568 }.to have_performed_job.exactly(1)
581- }.to raise_error (/expected to perform exactly 1 jobs, but performed 2/)
569+ }.to fail_with (/expected to perform exactly 1 jobs, but performed 2/)
582570 end
583571
584572 it "reports correct number in fail error message" do
585573 heavy_lifting_job.perform_later
586574 expect {
587575 expect { }.to have_performed_job.exactly(1)
588- }.to raise_error (/expected to perform exactly 1 jobs, but performed 0/)
576+ }.to fail_with (/expected to perform exactly 1 jobs, but performed 0/)
589577 end
590578
591579 it "fails when negated and job is performed" do
592580 expect {
593581 expect { heavy_lifting_job.perform_later }.not_to have_performed_job
594- }.to raise_error (/expected not to perform exactly 1 jobs, but performed 1/)
582+ }.to fail_with (/expected not to perform exactly 1 jobs, but performed 1/)
595583 end
596584
597585 it "passes with job name" do
@@ -646,7 +634,7 @@ def perform; raise StandardError; end
646634 it "generates failure message with at least hint" do
647635 expect {
648636 expect { }.to have_performed_job.at_least(:once)
649- }.to raise_error (/expected to perform at least 1 jobs, but performed 0/)
637+ }.to fail_with (/expected to perform at least 1 jobs, but performed 0/)
650638 end
651639
652640 it "generates failure message with at most hint" do
@@ -655,7 +643,7 @@ def perform; raise StandardError; end
655643 hello_job.perform_later
656644 hello_job.perform_later
657645 }.to have_performed_job.at_most(:once)
658- }.to raise_error (/expected to perform at most 1 jobs, but performed 2/)
646+ }.to fail_with (/expected to perform at most 1 jobs, but performed 2/)
659647 end
660648
661649 it "passes with provided queue name as string" do
@@ -707,7 +695,7 @@ def perform; raise StandardError; end
707695 expect {
708696 hello_job.perform_later(1)
709697 }.to have_performed_job(hello_job).with(42).on_queue("low").at(date).exactly(2).times
710- }.to raise_error (message)
698+ }.to fail_with (message)
711699 end
712700
713701 it "throws descriptive error when no test adapter set" do
@@ -792,7 +780,7 @@ def perform; raise StandardError; end
792780 it "fails when job is not performed" do
793781 expect {
794782 expect(heavy_lifting_job).to have_been_performed
795- }.to raise_error (/expected to perform exactly 1 jobs, but performed 0/)
783+ }.to fail_with (/expected to perform exactly 1 jobs, but performed 0/)
796784 end
797785 end
798786
0 commit comments