-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
describe UberTask do | ||
describe '.report' do | ||
it 'reports from task' do | ||
reported = false | ||
on_report_called = false | ||
|
||
UberTask.run do | ||
UberTask.on_report do | ||
on_report_called = true | ||
end | ||
|
||
UberTask.report do | ||
reported = true | ||
end | ||
end | ||
|
||
expect(reported).to be(true) | ||
expect(on_report_called).to be(true) | ||
end | ||
end | ||
end |
This file contains 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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
describe UberTask do | ||
describe '.retry' do | ||
shared_examples 'retries the task' do | ||
it 'retries the task' do | ||
run_count = 0 | ||
on_retry_count = 0 | ||
|
||
UberTask.run(retry_count: 3) do | ||
UberTask.on_retry do | ||
on_retry_count += 1 | ||
end | ||
|
||
if run_count < 2 | ||
run_count += 1 | ||
subject | ||
end | ||
end | ||
|
||
expect(run_count).to be(2) | ||
expect(on_retry_count).to be(2) | ||
end | ||
end | ||
|
||
context 'with block' do | ||
subject { described_class.retry { 'retry reason' } } | ||
|
||
it_behaves_like 'retries the task' | ||
end | ||
|
||
context 'without block' do | ||
subject { described_class.retry } | ||
|
||
it_behaves_like 'retries the task' | ||
end | ||
|
||
context 'with wait' do | ||
subject { described_class.retry(wait: 1) } | ||
|
||
it_behaves_like 'retries the task' | ||
end | ||
end | ||
end |
This file contains 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 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 |
---|---|---|
@@ -1,14 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
describe UberTask do | ||
it 'skips the task' do | ||
task_skipped = true | ||
describe '.skip' do | ||
shared_examples 'skips the task' do | ||
it 'skips the task' do | ||
task_skipped = true | ||
on_skip_called = false | ||
|
||
UberTask.run do | ||
UberTask.skip | ||
task_skipped = false | ||
UberTask.run do | ||
UberTask.on_skip do | ||
on_skip_called = true | ||
end | ||
|
||
subject | ||
|
||
task_skipped = false | ||
end | ||
|
||
expect(task_skipped).to be(true) | ||
expect(on_skip_called).to be(true) | ||
end | ||
end | ||
|
||
context 'with block' do | ||
subject { described_class.skip { 'skip reason' } } | ||
|
||
it_behaves_like 'skips the task' | ||
end | ||
|
||
expect(task_skipped).to be(true) | ||
context 'without block' do | ||
subject { described_class.skip } | ||
|
||
it_behaves_like 'skips the task' | ||
end | ||
end | ||
end |