ohbarye / pbt

Property-Based Testing tool for Ruby, supporting multiple concurrency methods (Ractor, multiprocesses, multithreads).
https://rubygems.org/gems/pbt
MIT License
207 stars 4 forks source link

Implement fixed hash arbitrary and allow to pass kwargs as arbitraries #7

Closed ohbarye closed 6 months ago

ohbarye commented 6 months ago

Change

This adds FixedHashArbitrary to generate/shrink a Hash.

Also this allows to pass keyword arbitrary to Pbt.property and its predicate method.

Pbt.assert do
  Pbt.property(x: Pbt.integer, y: Pbt.integer) do |hash|
    # use hash
  end
end

Note: I wanted to pass keyword arguments with destructuring but Ractor doesn't allow the usage. Ractor interprets the keyword arguments as its own and raises ArgumentError.

  Pbt.property(x: Pbt.integer, y: Pbt.integer) do |x:, y:|
    # use x, y
  end
Ractor.new(x: 1, y: 2) { |x:, y:| }
# unknown keyword: :x, :y (ArgumentError)