prop_check 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba078df3937d6f069a4ed24e9aaed9617dc1eb03139be0189e51b060b11a75ba
4
- data.tar.gz: 0fe77f31d282754df6712aafae7995e82e99d9ee86f8ad12bd060596147dafe1
3
+ metadata.gz: 4c85d7bb545c99b3953f68f42a7e37e14b96ddde115b42670689aa7094dfef42
4
+ data.tar.gz: efe151cb45c09d94d7e987d490096a321488832bc8d8041ab513ee64b71335d9
5
5
  SHA512:
6
- metadata.gz: e49791f3e5a380e822f4d86f39444a09e26828c4b1ea7c90d298c9eedcc14d8c6fdc05864439e1984b0cead4183beb1ae108bee82c7ce6dccbe11aae5efbd248
7
- data.tar.gz: cddd15cf550e166ec93d15fa2ffdf07a68646aa6750d544b6a5cf64c9bfb44177b638e6ff1df2ce25e28105df05aa838534e6eaafadefb7688aed32dae9d3bbc
6
+ metadata.gz: b5d180fe6141074ef202fba5c251a96492c2e5ad9706491ec615df1e5010c12623e3c5b53b8adaa5e75435df9ec48a464543672e33c81af4b18528da6f184860
7
+ data.tar.gz: a4b2e62dee58f53bc291202cbae157119eba7858f24b70ea5eb8790e578eceb0f2b140c1e5707c68037fcc09c2dddd17f57970de45fb3271503322a4de25fe05
@@ -15,7 +15,8 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby-version: ['2.5', '2.6', '2.7', '3.0']
18
+ # NOTE: Ruby 3.2 is not in here, as `doctest-core` first needs to be updated to support it
19
+ ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
19
20
 
20
21
  steps:
21
22
  - uses: actions/checkout@v3
@@ -27,5 +28,9 @@ jobs:
27
28
  with:
28
29
  ruby-version: ${{ matrix.ruby-version }}
29
30
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
30
- - name: Run tests
31
- run: bundle exec rake
31
+ - name: Run tests & push test coverage to Codeclimate
32
+ uses: paambaati/codeclimate-action@v3.2.0
33
+ env:
34
+ CC_TEST_REPORTER_ID: '9d18f5b43e49eecd6c3da64d85ea9c765d3606c129289d7c8cadf6d448713311'
35
+ with:
36
+ coverageCommand: bundle exec rake
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.7.1
1
+ ruby 2.7.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ - 0.18.2
2
+ - Documentation updates:
3
+ - PR #18: Adding an example of using prop_check with the `test-unit` testing framework to the README. Thank you, @niku!
4
+ - PR #17, #18, #21: fixing typos in various parts of the documentation. Thank you, @meganemura, @niku and @harlantwood!
5
+ - 0.18.1
6
+ - Fixes:
7
+ - Compatibility with Ruby 3.2:
8
+ - Use `Random` instead of no-longer-available `Random::DEFAULT` on Ruby 3.x.
9
+ - Ensure when a hash is passed (such as in `PropCheck.forall(hash_of(integer, string)) { |hash| ... }` that when an empty hash is generated, `hash` is still `{}` and not `nil`. ([Ruby 3.x treats `fun(**{})` differently than Ruby 2.x](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#other-minor-changes-empty-hash))
1
10
  - 0.18.0
2
11
  - Features:
3
12
  - Allows calling `PropCheck::Property#check` without a block, which will just return `self`. This is useful for writing wrapper functions that use `before/after/around/with_config` etc hooks which might themselves optionally want a block so they can be chained. (See the `forall_with_db` snippet in the README for an example)
data/Gemfile CHANGED
@@ -8,6 +8,6 @@ gem "bundler", "~> 2.0"
8
8
  group :test do
9
9
  gem "rake", "~> 12.3", require: false
10
10
  gem "rspec", "~> 3.0", require: false
11
- gem "doctest-rspec", require: false
11
+ gem "doctest2-rspec", require: false
12
12
  gem "simplecov", require: false
13
13
  end
data/Justfile ADDED
@@ -0,0 +1,16 @@
1
+ setup_and_test: setup test
2
+
3
+ setup:
4
+ bin/setup
5
+
6
+ test:
7
+ bundle exec rspec
8
+
9
+ console:
10
+ bin/console
11
+
12
+ install:
13
+ bundle exec rake install
14
+
15
+ release:
16
+ bundle exec rake release
data/README.md CHANGED
@@ -156,6 +156,23 @@ class NaiveAverageTest < MiniTest::Unit::TestCase
156
156
  end
157
157
  ```
158
158
 
159
+ The test case, using test-unit:
160
+ ``` ruby
161
+ require "test-unit"
162
+
163
+ class TestNaiveAverage < Test::Unit::TestCase
164
+ G = PropCheck::Generators
165
+
166
+ def test_that_it_returns_an_integer_for_any_input
167
+ PropCheck.forall(G.array(G.integer)) do |numbers|
168
+ result = naive_average(numbers)
169
+
170
+ assert_instance_of(Integer, result)
171
+ end
172
+ end
173
+ end
174
+ ```
175
+
159
176
  The test case, using only vanilla Ruby:
160
177
  ```ruby
161
178
  # And then in a test case:
@@ -250,7 +267,7 @@ Always returns the given value. No shrinking.
250
267
 
251
268
  Allows you to take the result of one generator and transform it into something else.
252
269
 
253
- >> G.choose(32..128).map(&:chr).sample(1, size: 10, Random.new(42))
270
+ >> G.choose(32..128).map(&:chr).sample(1, size: 10, rng: Random.new(42))
254
271
  => ["S"]
255
272
 
256
273
  #### Generator#bind
@@ -262,7 +279,7 @@ Allows you to create one or another generator conditionally on the output of ano
262
279
 
263
280
  This is an advanced feature. Often, you can use a combination of `Generators.tuple` and `Generator#map` instead:
264
281
 
265
- >> G.tuple(integer, integer).sample(1, size: 100, rng: Random.new(42)
282
+ >> G.tuple(G.integer, G.integer).sample(1, size: 100, rng: Random.new(42))
266
283
  => [[2, 79]]
267
284
 
268
285
  #### Generators.one_of
@@ -309,13 +326,17 @@ Here are some simple recommendations for the best results:
309
326
  .check(&block)
310
327
  end
311
328
  ```
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.
329
+ - 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
330
 
314
331
  ## Development
315
332
 
316
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
333
+ After checking out the repo, use the [just](https://github.com/casey/just) command runner for common tasks:
317
334
 
318
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
335
+ - `just setup`: Installs dev dependencies
336
+ - `just test`: Runs the test suite
337
+ - `just console`: Opens an IRb console with the gem loaded for experimenting.
338
+ - `just install`: Install the gem on your local machine.
339
+ - `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
340
 
320
341
  ## Contributing
321
342
 
@@ -9,7 +9,14 @@ module PropCheck
9
9
  # to be used during the shrinking phase.
10
10
  class Generator
11
11
  @@default_size = 10
12
- @@default_rng = Random.new
12
+ @@default_rng =
13
+ # Backwards compatibility: Random::DEFAULT is deprecated in Ruby 3.x
14
+ # but required in Ruby 2.x and 1.x
15
+ if RUBY_VERSION.to_i >= 3
16
+ Random
17
+ else
18
+ Random::DEFAULT
19
+ end
13
20
  @@max_consecutive_attempts = 100
14
21
  @@default_kwargs = { size: @@default_size, rng: @@default_rng,
15
22
  max_consecutive_attempts: @@max_consecutive_attempts }
@@ -115,7 +122,9 @@ module PropCheck
115
122
  # This can be used to inspect the configuration inside a `#map` or `#where`
116
123
  # and act on it.
117
124
  #
118
- # >> 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)
125
+ # >> example_config = PropCheck::Property::Configuration.new(default_epoch: Date.new(2022, 11, 22))
126
+ # >> generator = Generators.choose(0..100).with_config.map { |int, conf| Date.jd(conf[:default_epoch].jd + int) }
127
+ # >> generator.call(size: 10, rng: Random.new(42), config: example_config)
119
128
  # => Date.new(2023, 01, 12)
120
129
  def with_config
121
130
  Generator.new do |**kwargs|
@@ -234,7 +234,7 @@ module PropCheck
234
234
  end
235
235
 
236
236
  ##
237
- # Generates any nonzerno floating-point number.
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 positive floating point numbers
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 overriden `Object#hash`.
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)
@@ -33,6 +33,9 @@ module PropCheck
33
33
  end
34
34
 
35
35
  def call_splatted(val, &block)
36
+ # Handle edge case where Ruby >= 3 behaves differently than Ruby <= 2
37
+ # c.f. https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#other-minor-changes-empty-hash
38
+ return block.call({}) if val.is_a?(Hash) && val.empty?
36
39
  return block.call(**val) if val.is_a?(Hash) && val.keys.all? { |k| k.is_a?(Symbol) }
37
40
 
38
41
  block.call(val)
@@ -332,7 +332,7 @@ c.f. https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-k
332
332
  end
333
333
 
334
334
  private def raw_attempts_enum(binding_generator)
335
- rng = Random::DEFAULT
335
+ rng = Random.new
336
336
  size = 1
337
337
  (0...@config.max_generate_attempts)
338
338
  .lazy
@@ -1,3 +1,3 @@
1
1
  module PropCheck
2
- VERSION = '0.18.0'
2
+ VERSION = '0.18.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prop_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qqwy/Wiebe-Marten Wijnja
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-22 00:00:00.000000000 Z
11
+ date: 2024-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -43,6 +43,7 @@ files:
43
43
  - CHANGELOG.md
44
44
  - CODE_OF_CONDUCT.md
45
45
  - Gemfile
46
+ - Justfile
46
47
  - LICENSE.txt
47
48
  - README.md
48
49
  - Rakefile
@@ -68,7 +69,7 @@ metadata:
68
69
  homepage_uri: https://github.com/Qqwy/ruby-prop_check/
69
70
  source_code_uri: https://github.com/Qqwy/ruby-prop_check/
70
71
  changelog_uri: https://github.com/Qqwy/ruby-prop_check/CHANGELOG.md
71
- post_install_message:
72
+ post_install_message:
72
73
  rdoc_options: []
73
74
  require_paths:
74
75
  - lib
@@ -83,8 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
86
  requirements: []
86
- rubygems_version: 3.2.3
87
- signing_key:
87
+ rubygems_version: 3.1.6
88
+ signing_key:
88
89
  specification_version: 4
89
90
  summary: PropCheck allows you to do property-based testing, including shrinking.
90
91
  test_files: []