From d3fdeff26ed704cfdb4d8232294ba9f376a82e95 Mon Sep 17 00:00:00 2001 From: Sam Bostock Date: Sat, 13 Nov 2021 00:16:22 -0500 Subject: [PATCH] Add skip_until_version test helper This helper will skip the test ONLY if the gem version is below the specified version. This ensures that changes meant for a particular version release are included, and not forgotten or otherwise missed. --- test/integration/integration_behaviour.rb | 2 +- test/test_helper.rb | 4 ++++ test/unit/iteration_test.rb | 12 ++++++------ test/unit/throttle_enumerator_test.rb | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/integration/integration_behaviour.rb b/test/integration/integration_behaviour.rb index 36a716c4..89dd3602 100644 --- a/test/integration/integration_behaviour.rb +++ b/test/integration/integration_behaviour.rb @@ -35,7 +35,7 @@ module IntegrationBehaviour end test "unserializable corruption is prevented" do - skip "Deferred until 2.0.0" + skip_until_version("2.0.0") # Cursors are serialized as JSON, but not all objects are serializable. # time = Time.at(0).utc # => 1970-01-01 00:00:00 UTC # json = JSON.dump(time) # => "\"1970-01-01 00:00:00 UTC\"" diff --git a/test/test_helper.rb b/test/test_helper.rb index b7a0b197..29a3bc6c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -96,6 +96,10 @@ class TestCase setup do Redis.current.flushdb end + + def skip_until_version(version) + skip("Deferred until version #{version}") if Gem::Version.new(JobIteration::VERSION) < Gem::Version.new(version) + end end end diff --git a/test/unit/iteration_test.rb b/test/unit/iteration_test.rb index 164f01fd..a64bfff9 100644 --- a/test/unit/iteration_test.rb +++ b/test/unit/iteration_test.rb @@ -200,38 +200,38 @@ def foo end def test_jobs_using_time_cursor_will_raise - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") push(JobWithTimeCursor) assert_raises_cursor_error { work_one_job } end def test_jobs_using_active_record_cursor_will_raise - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") refute_nil(Product.first) push(JobWithActiveRecordCursor) assert_raises_cursor_error { work_one_job } end def test_jobs_using_symbol_cursor_will_raise - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") push(JobWithSymbolCursor) assert_raises_cursor_error { work_one_job } end def test_jobs_using_string_subclass_cursor_will_raise - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") push(JobWithStringSubclassCursor) assert_raises_cursor_error { work_one_job } end def test_jobs_using_basic_object_cursor_will_raise - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") push(JobWithBasicObjectCursor) assert_raises_cursor_error { work_one_job } end def test_jobs_using_complex_but_serializable_cursor_will_not_raise - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") push(JobWithComplexCursor) work_one_job end diff --git a/test/unit/throttle_enumerator_test.rb b/test/unit/throttle_enumerator_test.rb index 053d66dd..88255102 100644 --- a/test/unit/throttle_enumerator_test.rb +++ b/test/unit/throttle_enumerator_test.rb @@ -125,7 +125,7 @@ def each_iteration(_record, _params); end end test "does not evaluate enumerator when throttled" do - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") CustomizableThrottleJob.perform_now({ enumerator: Enumerator.new { raise StandardError, "should not evaluate when throttled" }, throttle_on: -> { true }, @@ -133,7 +133,7 @@ def each_iteration(_record, _params); end end test "can only wrap another enumerator" do - skip("Deferred until 2.0.0") + skip_until_version("2.0.0") error = assert_raises(ArgumentError) do CustomizableThrottleJob.perform_now({ enumerator: [],