-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added specs for UberTask #on_retry and #on_report methods #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
describe UberTask do | ||
describe '.on_report' do | ||
context 'when no block is passed' do | ||
it 'returns nil' do | ||
described_class.run do |task| | ||
expect(described_class.on_report).to be_nil | ||
end | ||
end | ||
end | ||
|
||
context 'when a block is passed' do | ||
it 'returns nil' do | ||
described_class.run do |task| | ||
result = described_class.on_report do | ||
"Added some logs" | ||
end | ||
|
||
expect(result.call).to eq("Added some logs") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update the we need to check that the block was added to the task's handlers (you can see here that tasks are expected to have a handlers attribute). |
||
end | ||
end | ||
end | ||
end | ||
|
||
describe '.on_retry' do | ||
context 'when no block is passed' do | ||
it 'returns the wait time and set handlers retry to nil' do | ||
described_class.run do |task| | ||
described_class.on_retry(report: false, wait: 12) | ||
|
||
expect(task.handlers[:retry]).to be_nil | ||
expect(task.retry_info.report).to be false | ||
expect(task.retry_info.wait).to eq(12) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to update the |
||
end | ||
end | ||
end | ||
|
||
context 'when a block is passed' do | ||
it 'returns the wait time and set handlers retry to the passed block' do | ||
expected_block = { | ||
first_name: "Sam", | ||
last_name: "Example" | ||
} | ||
|
||
described_class.run do |task| | ||
described_class.on_retry(report: true, wait: 30) do | ||
expected_block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify this test by returning a random number like 42 and avoiding the expected_block hash. |
||
end | ||
|
||
expect(task.handlers[:retry].call).to eq(expected_block) | ||
expect(task.retry_info.report).to be true | ||
expect(task.retry_info.wait).to eq(30) | ||
end | ||
end | ||
end | ||
end | ||
end |
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.
the |task| can be removed here since it is not used in the test.