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 +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +3 -1
- data/lib/prop_check/generators.rb +38 -0
- data/lib/prop_check/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b569736a2799a9455febcbb900042168be2f872a46657080cf1f31771e8f569
|
4
|
+
data.tar.gz: a97cf13cfdaaab60b16221493eab5a2de0fe7160e8d785f1ac9f5daad838e66a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 980bda5f214ae656a859d14041846b540341b7279cfe5fd997639d624d282811fc18968ade23822687c7b97de9363b4a3346d9dac58a0a3708585f1c02b5c45d
|
7
|
+
data.tar.gz: f62979c7577fae30c86b357bb50894b79c15d62603325c2496f4e341fdb93d40079873a83138f357c36c66a32089908e3e2368ac9ee579396e57f9c1714d1439
|
data/CHANGELOG.md
CHANGED
@@ -1 +1,4 @@
|
|
1
|
-
- 0.
|
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
|
-
|
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
|
data/lib/prop_check/version.rb
CHANGED