prop_check 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '099a3bafe1fae426f476e3add7fb93ab333506670c72c35bb78e5e505b9f0764'
4
- data.tar.gz: d1c433ef97043f38c84a5bf8768fb46aa5fcc97f00518da831fbebc36142d2e5
3
+ metadata.gz: 0b569736a2799a9455febcbb900042168be2f872a46657080cf1f31771e8f569
4
+ data.tar.gz: a97cf13cfdaaab60b16221493eab5a2de0fe7160e8d785f1ac9f5daad838e66a
5
5
  SHA512:
6
- metadata.gz: 782411f48a77c4bc2213d6ecaecd70d7d7c3609c13bab2125ce853dedd7d3029fd8801ac882154d8c924cea212698740d8e330f8e2b90f460a5a87484413e560
7
- data.tar.gz: dd18135801b66e2f073e82066506f8bb26cf031a4bd8d2fc208864acd7ef3a7ec564f8364628d34e4ab40429a5444a1dbc41f329bb4c7d3a608011407bb0a923
6
+ metadata.gz: 980bda5f214ae656a859d14041846b540341b7279cfe5fd997639d624d282811fc18968ade23822687c7b97de9363b4a3346d9dac58a0a3708585f1c02b5c45d
7
+ data.tar.gz: f62979c7577fae30c86b357bb50894b79c15d62603325c2496f4e341fdb93d40079873a83138f357c36c66a32089908e3e2368ac9ee579396e57f9c1714d1439
@@ -1 +1,4 @@
1
- - 0.8.0 New syntax that is more explicit, passng generated values to blocks as parameters.
1
+ - 0.12.0 - `PropCheck::Generators#instance`
2
+ - 0.11.0 - Improved syntax to support Ruby 2.7 and up without deprecation warnings, full support for `#where`.
3
+ - 0.10.0 - Some bugfixes, support for `#where`
4
+ - 0.8.0 - New syntax that is more explicit, passng generated values to blocks as parameters.
data/README.md CHANGED
@@ -24,10 +24,12 @@ Before releasing this gem on Rubygems, the following things need to be finished:
24
24
  - [x] Filtering generators.
25
25
  - [x] Customize the max. of samples to run.
26
26
  - [x] Stop after a ludicrous amount of generator runs, to prevent malfunctioning (infinitely looping) generators from blowing up someone's computer.
27
- - [x] Look into customization of settings from e.g. command line arguments.
27
+ - [x] Look into customization of settings from e.g. command line arguments.
28
28
  - [x] Good, unicode-compliant, string generators.
29
29
  - [x] Filtering generator outputs.
30
30
  - [x] Before/after/around hooks to add setup/teardown logic to be called before/after/around each time a check is run with new data.
31
+ - [x] `#instance` generator to allow the easy creation of generators for custom datatypes.
32
+ - [ ] A usage guide.
31
33
 
32
34
  # Nice-to-haves
33
35
 
@@ -520,5 +520,43 @@ module PropCheck
520
520
  def nillable(other_generator)
521
521
  frequency(9 => other_generator, 1 => constant(nil))
522
522
  end
523
+
524
+ ##
525
+ # Generates an instance of `klass`
526
+ # using `args` and/or `kwargs`
527
+ # as generators for the arguments that are passed to `klass.new`
528
+ #
529
+ # ## Example:
530
+ #
531
+ # Given a class like this:
532
+ #
533
+ #
534
+ # class User
535
+ # def initialize(name: , age: )
536
+ # @name = name
537
+ # @age = age
538
+ # end
539
+ #
540
+ # def inspect
541
+ # "<User name: #{@name.inspect}, age: #{@age.inspect}>"
542
+ # end
543
+ # end
544
+ #
545
+ # >> user_gen = Generators.instance(User, name: Generators.printable_ascii_string, age: Generators.nonnegative_integer)
546
+ # >> user_gen.sample(3, rng: Random.new(42)).inspect
547
+ # => "[<User name: \"S|.g\", age: 10>, <User name: \"rvjj\", age: 10>, <User name: \"7\\\"5T!w=\", age: 5>]"
548
+ def instance(klass, *args, **kwargs)
549
+ tuple(*args).bind do |vals|
550
+ fixed_hash(**kwargs).map do |kwvals|
551
+ if kwvals == {}
552
+ klass.new(*vals)
553
+ elsif vals == []
554
+ klass.new(**kwvals)
555
+ else
556
+ klass.new(*vals, **kwvals)
557
+ end
558
+ end
559
+ end
560
+ end
523
561
  end
524
562
  end
@@ -1,3 +1,3 @@
1
1
  module PropCheck
2
- VERSION = '0.11.1'
2
+ VERSION = '0.12.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prop_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qqwy/Wiebe-Marten Wijnja