1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
Feature: `have_performed_job` matcher
The `have_performed_job` (also aliased as `perform_job`) matcher is used to check if given ActiveJob job was performed.
Background:
Given active job is available
Scenario: Checking job class name
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe UploadBackupsJob do
it "matches with performed job" do
ActiveJob::Base.queue_adapter = :test
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
expect {
UploadBackupsJob.perform_later
}.to have_performed_job(UploadBackupsJob)
end
end
"""
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
Then the examples should all pass
Scenario: Checking passed arguments to job
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe UploadBackupsJob do
it "matches with performed job" do
ActiveJob::Base.queue_adapter = :test
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
expect {
UploadBackupsJob.perform_later("users-backup.txt", "products-backup.txt")
}.to have_performed_job.with("users-backup.txt", "products-backup.txt")
end
end
"""
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
Then the examples should all pass
Scenario: Checking job performed time
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe UploadBackupsJob do
it "matches with performed job" do
ActiveJob::Base.queue_adapter = :test
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true
expect {
UploadBackupsJob.set(:wait_until => Date.tomorrow.noon).perform_later
}.to have_performed_job.at(Date.tomorrow.noon)
end
end
"""
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
Then the examples should all pass
Scenario: Checking job queue name
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe UploadBackupsJob do
it "matches with performed job" do
ActiveJob::Base.queue_adapter = :test
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
expect {
UploadBackupsJob.perform_later
}.to have_performed_job.on_queue("default")
end
end
"""
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
Then the examples should all pass
Scenario: Using alias method
Given a file named "spec/jobs/upload_backups_job_spec.rb" with:
"""ruby
require "rails_helper"
RSpec.describe UploadBackupsJob do
it "matches with performed job" do
ActiveJob::Base.queue_adapter = :test
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
expect {
UploadBackupsJob.perform_later
}.to perform_job(UploadBackupsJob)
end
end
"""
When I run `rspec spec/jobs/upload_backups_job_spec.rb`
Then the examples should all pass
|