From 6aeeb1bedb92fb4f83aed51d8148fc5ec82ec091 Mon Sep 17 00:00:00 2001 From: Klaus Weidinger Date: Tue, 24 Jan 2023 21:57:55 +0100 Subject: [PATCH 1/8] Add support for Ruby 3.2 --- lib/prop_check/property.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/prop_check/property.rb b/lib/prop_check/property.rb index 4df3305..1b2082d 100644 --- a/lib/prop_check/property.rb +++ b/lib/prop_check/property.rb @@ -332,7 +332,7 @@ def check(&block) end private def raw_attempts_enum(binding_generator) - rng = Random::DEFAULT + rng = Random.new size = 1 (0...@config.max_generate_attempts) .lazy From 843bfbfaa5ef2cf4b7119b6b7d18bc97ec04f599 Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 20:57:40 +0300 Subject: [PATCH 2/8] Backwards-compatible handling of default Random generator. - Use `Random` (the class) on Ruby >= 3 - Use `Random::DEFAULT` on Ruby < 3. (since 3.x this is deprecated) --- lib/prop_check/generator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/prop_check/generator.rb b/lib/prop_check/generator.rb index cd329b9..6933844 100644 --- a/lib/prop_check/generator.rb +++ b/lib/prop_check/generator.rb @@ -9,7 +9,14 @@ module PropCheck # to be used during the shrinking phase. class Generator @@default_size = 10 - @@default_rng = Random.new + @@default_rng = + # Backwards compatibility: Random::DEFAULT is deprecated in Ruby 3.x + # but required in Ruby 2.x and 1.x + if RUBY_VERSION.to_i >= 3 + Random + else + Random::DEFAULT + end @@max_consecutive_attempts = 100 @@default_kwargs = { size: @@default_size, rng: @@default_rng, max_consecutive_attempts: @@max_consecutive_attempts } From 730066371bbe372a54ab0c48d77e254a9f8653fa Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 21:13:34 +0300 Subject: [PATCH 3/8] Ensure proper handling of generated hashes in Ruby >= 3.0, since the behaviour of `myfun(**{})` changed c.f. https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#other-minor-changes-empty-hash --- lib/prop_check/helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/prop_check/helper.rb b/lib/prop_check/helper.rb index a0f8833..c1214f8 100644 --- a/lib/prop_check/helper.rb +++ b/lib/prop_check/helper.rb @@ -33,6 +33,9 @@ def lazy_append(this_enumerator, other_enumerator) end def call_splatted(val, &block) + # Handle edge case where Ruby >= 3 behaves differently than Ruby <= 2 + # c.f. https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#other-minor-changes-empty-hash + return block.call({}) if val.is_a?(Hash) && val.empty? return block.call(**val) if val.is_a?(Hash) && val.keys.all? { |k| k.is_a?(Symbol) } block.call(val) From b004a2087e75dc36f1e84479eb712a108c5b38e7 Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 21:19:18 +0300 Subject: [PATCH 4/8] Update Github action workflow to add CI testing for Ruby versions 3.1 and 3.2 and drop version 2.5 since: - the CI bundler build step does not seem to support it anymore - It is a truly ancient version now as well; official support for 2.5 from the Ruby lang teaam has ended long ago. --- .github/workflows/run_tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index d5394ac..55e84de 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.5', '2.6', '2.7', '3.0'] + ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2'] steps: - uses: actions/checkout@v3 From 06ea98a2935ac7fb39bf421ab9a1655d2d1958e0 Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 21:26:02 +0300 Subject: [PATCH 5/8] Fix GH workflow because of changes in CodeClimate --- .github/workflows/run_tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 55e84de..4545d74 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -30,6 +30,6 @@ jobs: - name: Run tests & push test coverage to Codeclimate uses: paambaati/codeclimate-action@v3.2.0 env: - CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_REPORTER_ID }} + CC_TEST_REPORTER_ID: '9d18f5b43e49eecd6c3da64d85ea9c765d3606c129289d7c8cadf6d448713311' with: coverageCommand: bundle exec rake From 7fe056597cc1cb53ec7903be13f7ba72791e9690 Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 21:30:41 +0300 Subject: [PATCH 6/8] Remove Ruby version 3.2 from GH workflow for now, since test-dep `doctest-core` needs to be updated first. --- .github/workflows/run_tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 4545d74..c6b383b 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -15,7 +15,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2'] + # NOTE: Ruby 3.2 is not in here, as `doctest-core` first needs to be updated to support it + ruby-version: ['2.6', '2.7', '3.0', '3.1'] steps: - uses: actions/checkout@v3 From 0f70a3cdfbdf681276a4d0871c7f9d509df4c55b Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 21:31:37 +0300 Subject: [PATCH 7/8] Bump version :-) --- lib/prop_check/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/prop_check/version.rb b/lib/prop_check/version.rb index 3d0a4aa..36fab57 100644 --- a/lib/prop_check/version.rb +++ b/lib/prop_check/version.rb @@ -1,3 +1,3 @@ module PropCheck - VERSION = '0.18.0' + VERSION = '0.18.1' end From 61c55b2d4befd578a5960a65c37dd69a836ab2cb Mon Sep 17 00:00:00 2001 From: qqwy Date: Thu, 11 May 2023 21:36:16 +0300 Subject: [PATCH 8/8] Write changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8c759c..d10b2ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +- 0.18.1 + - Fixes: + - Compatibility with Ruby 3.2: + - Use `Random` instead of no-longer-available `Random::DEFAULT` on Ruby 3.x. + - Ensure when a hash is passed (such as in `PropCheck.forall(hash_of(integer, string)) { |hash| ... }` that when an empty hash is generated, `hash` is still `{}` and not `nil`. ([Ruby 3.x treats `fun(**{})` differently than Ruby 2.x](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#other-minor-changes-empty-hash)) - 0.18.0 - Features: - Allows calling `PropCheck::Property#check` without a block, which will just return `self`. This is useful for writing wrapper functions that use `before/after/around/with_config` etc hooks which might themselves optionally want a block so they can be chained. (See the `forall_with_db` snippet in the README for an example)