Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions spec/uber_task/uber_task_spec.rb
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|
Copy link
Member

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.

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the on_report to always return nil, the returned value was not intentional.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to update the on_retry method to always return nil. The returned value was not intentional.

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
Copy link
Member

Choose a reason for hiding this comment

The 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