prop_check 0.18.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/run_tests.yaml +3 -2
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/Justfile +16 -0
- data/README.md +37 -15
- data/lib/prop_check/generators.rb +3 -3
- data/lib/prop_check/property/output_formatter.rb +10 -5
- data/lib/prop_check/property.rb +0 -1
- data/lib/prop_check/version.rb +1 -1
- data/prop_check.gemspec +1 -3
- metadata +5 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97039234e58c965b91cba40c589808d7ac1e4b559355fd4df719edb89f7b837
|
4
|
+
data.tar.gz: a87f0c2377918f4d05c6b1d06838b0581a01b21ddba4a1e74929e046cc33f5d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6821b9be704593dcf577c8b9e29191e731009358faf0f3f4405b8333e8246681cbc76327bbb4f74d9a748f255ba65e2379cdadf51b3fa601746f2db89ba5e906
|
7
|
+
data.tar.gz: 3aa1b4d7313e5713ec9a2960461f89b7b14f265dabe57fe8c5040ce99450f66a61280e903df50879176a5850c56e802d9650f4c952968ab69c5b0030c1349d74
|
@@ -15,8 +15,9 @@ jobs:
|
|
15
15
|
runs-on: ubuntu-latest
|
16
16
|
strategy:
|
17
17
|
matrix:
|
18
|
-
# NOTE:
|
19
|
-
|
18
|
+
# NOTE: We're stopping testing Ruby < 3.0 since prop_check version 1.0.0
|
19
|
+
# It will _probably_ still work but as they're end-of-life, no guarantees!
|
20
|
+
ruby-version: ['3.0', '3.1', '3.2']
|
20
21
|
|
21
22
|
steps:
|
22
23
|
- uses: actions/checkout@v3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
- 1.0.0
|
2
|
+
- Changes:
|
3
|
+
- Pretty-print failures using Ruby's builtin `PP`, so `prop_check` no longer depends on the `awesome_print` gem. (c.f. #19)
|
4
|
+
- 0.18.2
|
5
|
+
- Documentation updates:
|
6
|
+
- Adding an example of using prop_check with the `test-unit` testing framework to the README. (c.f. #18, thank you, @niku!)
|
7
|
+
- Fixing typos in various parts of the documentation. (c.f. #16, #17, #21. Thank you, @meganemura, @niku and @harlantwood!)
|
1
8
|
- 0.18.1
|
2
9
|
- Fixes:
|
3
10
|
- Compatibility with Ruby 3.2:
|
data/Gemfile
CHANGED
data/Justfile
ADDED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ PropCheck allows you to do Property Testing in Ruby.
|
|
5
5
|
[![Gem](https://img.shields.io/gem/v/prop_check.svg)](https://rubygems.org/gems/prop_check)
|
6
6
|
[![Ruby RSpec tests build status](https://github.com/Qqwy/ruby-prop_check/actions/workflows/run_tests.yaml/badge.svg)](https://github.com/Qqwy/ruby-prop_check/actions/workflows/run_tests.yaml)
|
7
7
|
[![Maintainability](https://api.codeclimate.com/v1/badges/71897f5e6193a5124a53/maintainability)](https://codeclimate.com/github/Qqwy/ruby-prop_check/maintainability)
|
8
|
-
[![RubyDoc](https://img.shields.io/badge/%F0%9F%93%9ARubyDoc-documentation-informational.svg)](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/
|
8
|
+
[![RubyDoc](https://img.shields.io/badge/%F0%9F%93%9ARubyDoc-documentation-informational.svg)](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/main/)
|
9
9
|
|
10
10
|
It features:
|
11
11
|
|
@@ -14,6 +14,8 @@ It features:
|
|
14
14
|
- Shrinking to a minimal counter-example on failure.
|
15
15
|
- Hooks to perform extra set-up/cleanup logic before/after every example case.
|
16
16
|
|
17
|
+
It requires _no_ external dependencies, and integrates well with all common test frameworks (see below).
|
18
|
+
|
17
19
|
## What is PropCheck?
|
18
20
|
|
19
21
|
PropCheck is a Ruby library to create unit tests which are simpler to write and more powerful when run, finding edge-cases in your code you wouldn't have thought to look for.
|
@@ -156,6 +158,23 @@ class NaiveAverageTest < MiniTest::Unit::TestCase
|
|
156
158
|
end
|
157
159
|
```
|
158
160
|
|
161
|
+
The test case, using test-unit:
|
162
|
+
``` ruby
|
163
|
+
require "test-unit"
|
164
|
+
|
165
|
+
class TestNaiveAverage < Test::Unit::TestCase
|
166
|
+
G = PropCheck::Generators
|
167
|
+
|
168
|
+
def test_that_it_returns_an_integer_for_any_input
|
169
|
+
PropCheck.forall(G.array(G.integer)) do |numbers|
|
170
|
+
result = naive_average(numbers)
|
171
|
+
|
172
|
+
assert_instance_of(Integer, result)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
159
178
|
The test case, using only vanilla Ruby:
|
160
179
|
```ruby
|
161
180
|
# And then in a test case:
|
@@ -201,16 +220,15 @@ For instance, when a failure happens with the input `x = 100`,
|
|
201
220
|
PropCheck will see if the failure still happens with `x = 50`.
|
202
221
|
If it does , it will try `x = 25`. If not, it will try `x = 75`, and so on.
|
203
222
|
|
204
|
-
This means if something only goes wrong for `x
|
223
|
+
This means for example that if something only goes for wrong for `x >= 8`, the program will try:
|
205
224
|
- `x = 100`(fails),
|
206
225
|
- `x = 50`(fails),
|
207
226
|
- `x = 25`(fails),
|
208
227
|
- `x = 12`(fails),
|
209
|
-
- `x = 6`(
|
210
|
-
- `x =
|
211
|
-
- `x = 1` (succeeds), `x = 2` (fails).
|
228
|
+
- `x = 6`(succeeds), `x = 9` (fails)
|
229
|
+
- `x = 7`(succeeds), `x = 8` (fails).
|
212
230
|
|
213
|
-
and thus the simplified case of `x =
|
231
|
+
and thus the simplified case of `x = 8` is shown in the output.
|
214
232
|
|
215
233
|
The documentation of the provided generators explain how they shrink.
|
216
234
|
A short summary:
|
@@ -222,7 +240,7 @@ A short summary:
|
|
222
240
|
|
223
241
|
### Builtin Generators
|
224
242
|
|
225
|
-
PropCheck comes with [many builtin generators in the PropCheck::Generators](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/
|
243
|
+
PropCheck comes with [many builtin generators in the PropCheck::Generators](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/main/PropCheck/Generators) module.
|
226
244
|
|
227
245
|
It contains generators for:
|
228
246
|
- (any, positive, negative, etc.) integers,
|
@@ -250,7 +268,7 @@ Always returns the given value. No shrinking.
|
|
250
268
|
|
251
269
|
Allows you to take the result of one generator and transform it into something else.
|
252
270
|
|
253
|
-
>> G.choose(32..128).map(&:chr).sample(1, size: 10, Random.new(42))
|
271
|
+
>> G.choose(32..128).map(&:chr).sample(1, size: 10, rng: Random.new(42))
|
254
272
|
=> ["S"]
|
255
273
|
|
256
274
|
#### Generator#bind
|
@@ -262,7 +280,7 @@ Allows you to create one or another generator conditionally on the output of ano
|
|
262
280
|
|
263
281
|
This is an advanced feature. Often, you can use a combination of `Generators.tuple` and `Generator#map` instead:
|
264
282
|
|
265
|
-
>> G.tuple(integer, integer).sample(1, size: 100, rng: Random.new(42)
|
283
|
+
>> G.tuple(G.integer, G.integer).sample(1, size: 100, rng: Random.new(42))
|
266
284
|
=> [[2, 79]]
|
267
285
|
|
268
286
|
#### Generators.one_of
|
@@ -288,8 +306,8 @@ you can use `Generators.frequency` which takes a hash of (integer_frequency => g
|
|
288
306
|
There are even more functions in the `Generator` class and the `Generators` module that you might want to use,
|
289
307
|
although above are the most generally useful ones.
|
290
308
|
|
291
|
-
[PropCheck::Generator documentation](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/
|
292
|
-
[PropCheck::Generators documentation](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/
|
309
|
+
[PropCheck::Generator documentation](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/main/PropCheck/Generator)
|
310
|
+
[PropCheck::Generators documentation](https://www.rubydoc.info/github/Qqwy/ruby-prop_check/main/PropCheck/Generators)
|
293
311
|
|
294
312
|
|
295
313
|
## Usage within Rails / with a database
|
@@ -309,13 +327,17 @@ Here are some simple recommendations for the best results:
|
|
309
327
|
.check(&block)
|
310
328
|
end
|
311
329
|
```
|
312
|
-
- Other setup/cleanup should also usually happen around each generated example rather than around the whole test: Instead of using the hooks exposed by RSpec/MiniTest/etc., use the before/after/around hooks exposed by PropCheck.
|
330
|
+
- Other setup/cleanup should also usually happen around each generated example rather than around the whole test: Instead of using the hooks exposed by RSpec/MiniTest/test-unit/etc., use the before/after/around hooks exposed by PropCheck.
|
313
331
|
|
314
332
|
## Development
|
315
333
|
|
316
|
-
After checking out the repo,
|
334
|
+
After checking out the repo, use the [just](https://github.com/casey/just) command runner for common tasks:
|
317
335
|
|
318
|
-
|
336
|
+
- `just setup`: Installs dev dependencies
|
337
|
+
- `just test`: Runs the test suite
|
338
|
+
- `just console`: Opens an IRb console with the gem loaded for experimenting.
|
339
|
+
- `just install`: Install the gem on your local machine.
|
340
|
+
- `just release`: Create and push a new release to the git repo and Rubygems. (Be sure to increase the version number in `version.rb` first!)
|
319
341
|
|
320
342
|
## Contributing
|
321
343
|
|
@@ -327,7 +349,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
327
349
|
|
328
350
|
## Code of Conduct
|
329
351
|
|
330
|
-
Everyone interacting in the PropCheck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Qqwy/ruby-prop_check/blob/
|
352
|
+
Everyone interacting in the PropCheck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Qqwy/ruby-prop_check/blob/main/CODE_OF_CONDUCT.md).
|
331
353
|
|
332
354
|
## Attribution and Thanks
|
333
355
|
|
@@ -234,7 +234,7 @@ module PropCheck
|
|
234
234
|
end
|
235
235
|
|
236
236
|
##
|
237
|
-
# Generates any
|
237
|
+
# Generates any nonzero floating-point number.
|
238
238
|
# Will generate special floats (except NaN) from time to time.
|
239
239
|
# c.f. #float
|
240
240
|
def nonzero_float
|
@@ -266,7 +266,7 @@ module PropCheck
|
|
266
266
|
end
|
267
267
|
|
268
268
|
##
|
269
|
-
# Generates
|
269
|
+
# Generates negative floating point numbers
|
270
270
|
# Will generate special floats (except NaN) from time to time.
|
271
271
|
# c.f. #float
|
272
272
|
def negative_float
|
@@ -479,7 +479,7 @@ module PropCheck
|
|
479
479
|
|
480
480
|
##
|
481
481
|
#
|
482
|
-
# Alias for `#hash` that does not conflict with a possibly
|
482
|
+
# Alias for `#hash` that does not conflict with a possibly overridden `Object#hash`.
|
483
483
|
#
|
484
484
|
def hash_of(key_generator, value_generator, **kwargs)
|
485
485
|
array(tuple(key_generator, value_generator), **kwargs)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
##
|
2
2
|
# @api private
|
3
|
+
require 'pp'
|
4
|
+
|
3
5
|
module PropCheck::Property::OutputFormatter
|
4
6
|
extend self
|
5
7
|
|
@@ -32,10 +34,13 @@ module PropCheck::Property::OutputFormatter
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def print_roots(lazy_tree_val)
|
35
|
-
|
36
|
-
lazy_tree_val[0].
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
data =
|
38
|
+
if lazy_tree_val.is_a?(Array) && lazy_tree_val.length == 1 && lazy_tree_val[0].is_a?(Hash)
|
39
|
+
lazy_tree_val[0]
|
40
|
+
else
|
41
|
+
lazy_tree_val
|
42
|
+
end
|
43
|
+
|
44
|
+
PP.pp(data, '')
|
40
45
|
end
|
41
46
|
end
|
data/lib/prop_check/property.rb
CHANGED
data/lib/prop_check/version.rb
CHANGED
data/prop_check.gemspec
CHANGED
@@ -6,7 +6,7 @@ require "prop_check/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "prop_check"
|
8
8
|
spec.version = PropCheck::VERSION
|
9
|
-
spec.authors = ["Qqwy/
|
9
|
+
spec.authors = ["Qqwy/Marten Wijnja"]
|
10
10
|
spec.email = ["w-m@wmcode.nl"]
|
11
11
|
|
12
12
|
spec.summary = %q{PropCheck allows you to do property-based testing, including shrinking.}
|
@@ -35,6 +35,4 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.require_paths = ["lib"]
|
36
36
|
|
37
37
|
spec.required_ruby_version = '>= 2.5.1'
|
38
|
-
|
39
|
-
spec.add_dependency 'amazing_print', '~> 1.2'
|
40
38
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prop_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Qqwy/
|
7
|
+
- Qqwy/Marten Wijnja
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: amazing_print
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.2'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.2'
|
11
|
+
date: 2024-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: PropCheck allows you to do property-based testing, including shrinking.
|
28
14
|
(akin to Haskell's QuickCheck, Erlang's PropEr, Elixir's StreamData). This means
|
29
15
|
that your test are run many times with different, autogenerated inputs, and as soon
|
@@ -43,6 +29,7 @@ files:
|
|
43
29
|
- CHANGELOG.md
|
44
30
|
- CODE_OF_CONDUCT.md
|
45
31
|
- Gemfile
|
32
|
+
- Justfile
|
46
33
|
- LICENSE.txt
|
47
34
|
- README.md
|
48
35
|
- Rakefile
|