Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Qqwy/ruby-prop_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Qqwy committed May 11, 2023
2 parents 9525066 + c57caab commit ef9842a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/run_tests.yaml
Expand Up @@ -15,7 +15,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.5', '2.6', '2.7', '3.0']
# 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
Expand All @@ -30,6 +31,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
5 changes: 5 additions & 0 deletions 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)
Expand Down
9 changes: 8 additions & 1 deletion lib/prop_check/generator.rb
Expand Up @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions lib/prop_check/helper.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/prop_check/property.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/prop_check/version.rb
@@ -1,3 +1,3 @@
module PropCheck
VERSION = '0.18.0'
VERSION = '0.18.1'
end

0 comments on commit ef9842a

Please sign in to comment.