lib/prop_check/generator.rb in prop_check-0.18.0 vs lib/prop_check/generator.rb in prop_check-0.18.1

- old
+ new

@@ -7,11 +7,18 @@ # The root of this tree is the value to be used during testing, # and the children are 'smaller' values related to the root, # 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 } ## @@ -113,10 +120,12 @@ # Turns a generator returning `x` into a generator returning `[x, config]` # where `config` is the current `PropCheck::Property::Configuration`. # This can be used to inspect the configuration inside a `#map` or `#where` # and act on it. # - # >> Generators.choose(0..100).with_config.map { |int, conf| Date.jd(conf[:default_epoch].jd + int) }.call(size: 10, rng: Random.new(42), config: PropCheck::Property::Configuration.new) + # >> example_config = PropCheck::Property::Configuration.new(default_epoch: Date.new(2022, 11, 22)) + # >> generator = Generators.choose(0..100).with_config.map { |int, conf| Date.jd(conf[:default_epoch].jd + int) } + # >> generator.call(size: 10, rng: Random.new(42), config: example_config) # => Date.new(2023, 01, 12) def with_config Generator.new do |**kwargs| result = generate(**kwargs) result.map { |val| [val, kwargs[:config]] }