-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Adds documentation and feature for job specs #1725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
Feature: job spec | ||
|
||
Job specs provide alternative assertions to those available in | ||
`ActiveJob::TestHelper` and help assert behaviour of the jobs themselves | ||
and that other entities correctly enqueue them. | ||
|
||
Job specs are marked by `:type => :job` or if you have set | ||
`config.infer_spec_type_from_file_location!` by placing them in `spec/jobs`. | ||
|
||
With job specs, you can: | ||
|
||
* specify the job class which was enqueued | ||
* specify the arguments passed to the job | ||
* specify when the job was enqueued until | ||
* specify the queue which the job was enqueued to | ||
|
||
Check the documentation on | ||
[`have_been_enqueued`](matchers/have-been-enqueued-matcher) and | ||
[`have_enqueued_job`](matchers/have-enqueued-job-matcher) for more | ||
information. | ||
|
||
Background: | ||
Given active job is available | ||
|
||
Scenario: specify that job was enqueued | ||
Given a file named "spec/jobs/upload_backups_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadBackupsJob, :type => :job do | ||
describe "#perform_later" do | ||
it "uploads a backup" do | ||
ActiveJob::Base.queue_adapter = :test | ||
expect { | ||
UploadBackupsJob.perform_later('backup') | ||
}.to have_enqueued_job | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/jobs/upload_backups_spec.rb` | ||
Then the example should pass | ||
|
||
Scenario: specify that job was enqueued for the correct date and time | ||
Given a file named "spec/jobs/upload_backups_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadBackupsJob, :type => :job do | ||
describe "#perform_later" do | ||
it "uploads a backup" do | ||
ActiveJob::Base.queue_adapter = :test | ||
expect { | ||
UploadBackupsJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later('backup') | ||
}.to have_enqueued_job.with('backup').on_queue("low").at(Date.tomorrow.noon) | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/jobs/upload_backups_spec.rb` | ||
Then the example should pass | ||
|
||
Scenario: specify that job was enqueued with alias block syntax | ||
Given a file named "spec/jobs/upload_backups_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadBackupsJob, :type => :job do | ||
describe "#perform_later" do | ||
it "uploads a backup" do | ||
ActiveJob::Base.queue_adapter = :test | ||
expect { | ||
UploadBackupsJob.perform_later('backup') | ||
}.to enqueue_job | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/jobs/upload_backups_spec.rb` | ||
Then the example should pass | ||
|
||
Scenario: specify that job was enqueued with imperative syntax | ||
Given a file named "spec/jobs/upload_backups_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadBackupsJob, :type => :job do | ||
describe "#perform_later" do | ||
it "uploads a backup" do | ||
ActiveJob::Base.queue_adapter = :test | ||
UploadBackupsJob.perform_later('backup') | ||
expect(UploadBackupsJob).to have_been_enqueued | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/jobs/upload_backups_spec.rb` | ||
Then the example should pass | ||
|
||
Scenario: specify that job was enqueued with imperative syntax and a chained expectation | ||
Given a file named "spec/jobs/upload_backups_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadBackupsJob, :type => :job do | ||
describe "#perform_later" do | ||
it "uploads a backup" do | ||
ActiveJob::Base.queue_adapter = :test | ||
UploadBackupsJob.perform_later('backup') | ||
expect(UploadBackupsJob).to have_been_enqueued.exactly(:once) | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/jobs/upload_backups_spec.rb` | ||
Then the example should pass | ||
|
||
Scenario: the test adapter must be set to :test | ||
Given a file named "spec/jobs/upload_backups_spec.rb" with: | ||
"""ruby | ||
require "rails_helper" | ||
|
||
RSpec.describe UploadBackupsJob, :type => :job do | ||
describe "#perform_later" do | ||
it "uploads a backup" do | ||
ActiveJob::Base.queue_adapter = :development | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec spec/jobs/upload_backups_spec.rb` | ||
Then the example should fail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link doesn't currently work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'd like to fix this, I'd welcome a PR!, this ones already been merged tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I wasn't clear if there was some kind of a deploy that needed to happen to make the URL work so it wasn't clear to me what the fix would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, you're totally right, /cc @myronmarston how do we publish to relish again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rake relish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, one flaw in this plan, I don't have access!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've signed up with the usual email address if you want to add me so I can do this Myron.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added you as a collaborator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link works now, thanks @myronmarston and @drewish