Skip to content

Commit

Permalink
Bulk enqueue: Add test for raising when job_options are passed to .en…
Browse files Browse the repository at this point in the history
…queue rather than .bulk_enqueue

I added a matcher, `assert_raises_with_message` to make the expectation cleaner. I reckon this should have been part of minitest, like it is in RSpec
  • Loading branch information
ZimbiX committed Aug 23, 2022
1 parent b888568 commit 6f49e2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/que/job.bulk_enqueue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ def assert_enqueue(
end
end

it "should raise when job_options are passed to .enqueue rather than .bulk_enqueue" do
assert_raises_with_message(Que::Error, "When using .bulk_enqueue, job_options must be passed to that method rather than .enqueue") do
Que.bulk_enqueue do
Que.enqueue(1, two: "3", job_options: { priority: 15 })
end
end
end

describe "when enqueuing jobs with tags" do
it "should be able to specify tags on a case-by-case basis" do
assert_enqueue(
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ def sleep_until?(timeout: SLEEP_UNTIL_TIMEOUT)
end
end

def assert_raises_with_message(expected_error_class, expected_message, &block)
e = assert_raises(expected_error_class, &block)
assert_match(expected_message, e.message, "#{mu_pp(expected_error_class)} error was raised but without the expected message")
end

class << self
# More easily hammer a certain spec.
def hit(*args, &block)
Expand Down

0 comments on commit 6f49e2f

Please sign in to comment.