Skip to content

Commit d6e6cf6

Browse files
authored
Merge pull request #2015 from SzNagyMisu/m_pr
Documentation for `have_enqueued_job` (#1576)
2 parents 2f25700 + 5e0bdcd commit d6e6cf6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

features/matchers/have_enqueued_job_matcher.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ Feature: have_enqueued_job matcher
3939
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
4040
Then the examples should all pass
4141

42+
Scenario: Checking passed arguments to job - block syntax
43+
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
44+
"""ruby
45+
require "rails_helper"
46+
47+
RSpec.describe UploadBackupsJob do
48+
it "matches with enqueued job" do
49+
ActiveJob::Base.queue_adapter = :test
50+
expect {
51+
UploadBackupsJob.perform_later('backups.txt', rand(100), 'uninteresting third argument')
52+
}.to have_enqueued_job.with { |file_name, seed|
53+
expect(file_name).to eq 'backups.txt'
54+
expect(seed).to be < 100
55+
}
56+
end
57+
end
58+
"""
59+
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
60+
Then the examples should all pass
61+
4262
Scenario: Checking job enqueued time
4363
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
4464
"""ruby

lib/rspec/rails/matchers/active_job.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ def matches?(job)
240240
# expect {
241241
# HelloJob.set(queue: "low").perform_later(42)
242242
# }.to have_enqueued_job.with(42).on_queue("low").at(:no_wait)
243+
#
244+
# expect {
245+
# HelloJob.perform_later('rspec_rails', %w[ world rspec rails ], 42)
246+
# }.to have_enqueued_job.with { |_from, to, times|
247+
# # I don't want to check argument `from`
248+
# expect(to).to include 'rspec'
249+
# expect(times).to eq 42
250+
# }
243251
def have_enqueued_job(job = nil)
244252
check_active_job_adapter
245253
ActiveJob::HaveEnqueuedJob.new(job)

0 commit comments

Comments
 (0)