hypothesis-specs 0.4.0 → 0.5.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 +12 -0
- data/lib/hypothesis.rb +29 -1
- data/lib/hypothesis/engine.rb +5 -1
- data/src/lib.rs +23 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b61a06e5e23722e55967de84342fb6baa43247b7900e0d3e0e45e02c5efa71ab
|
4
|
+
data.tar.gz: 509ee84bbbb29624d1c94b696e3b60cdcf0a458c94f6f0a5463cadfaef514261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b0c4bd91e31ef524b27f0b85137caec78978216c684cbf3b92aa9ebe788d598b98e8362e3960c52563e31ffd005279539349606ad4c7bb689ae7d1cf972e71
|
7
|
+
data.tar.gz: 958a99a260e866c32eaa8faa9e1d57aa4c479a02dfd7e4f966f2b3d790e473beacf93d9127164ee20fc8edcecb8b32ff5675efeec5b1edf0053d9254958b21e1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# Hypothesis for Ruby 0.5.0 (2021-01-25)
|
2
|
+
|
3
|
+
Adds support for skipping shrinking. While shrinking is extremely helpful and important in general, it has the potential to be quite time consuming. It can be useful to observe a raw failure before choosing to allow the engine to try to shrink. [hypothesis-python](https://hypothesis.readthedocs.io/en/latest/settings.html#phases) already provides the ability to skip shrinking, so there is precedent for this being useful. While `hypothesis-ruby` does not have the concept of other "Phases" yet, we can still start off the API by using this concept.
|
4
|
+
|
5
|
+
Usage:
|
6
|
+
|
7
|
+
```
|
8
|
+
hypothesis(phases: Phase.excluding(:shrink)) do
|
9
|
+
# Failures here will be displayed directly and shrinking will be avoided
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
1
13
|
# Hypothesis for Ruby 0.4.0 (2021-01-12)
|
2
14
|
|
3
15
|
This removes hypothesis-ruby's dependence on RSpec. Now, it can be used with any Ruby test runner.
|
data/lib/hypothesis.rb
CHANGED
@@ -7,6 +7,28 @@ require_relative 'hypothesis/testcase'
|
|
7
7
|
require_relative 'hypothesis/engine'
|
8
8
|
require_relative 'hypothesis/world'
|
9
9
|
|
10
|
+
module Phase
|
11
|
+
SHRINK = :shrink
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def all
|
16
|
+
[SHRINK]
|
17
|
+
end
|
18
|
+
|
19
|
+
def excluding(*phases)
|
20
|
+
unknown_phases = phases.reject { |phase| Phase.all.include?(phase) }
|
21
|
+
unless unknown_phases.empty?
|
22
|
+
raise(
|
23
|
+
ArgumentError,
|
24
|
+
"Attempting to exclude unknown phases: #{unknown_phases}"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
all - phases
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
10
32
|
# This is the main module for using Hypothesis.
|
11
33
|
# It is expected that you will include this in your
|
12
34
|
# tests, but its methods are also available on the
|
@@ -201,7 +223,12 @@ module Hypothesis
|
|
201
223
|
# should store previously failing test cases. If it is nil, Hypothesis
|
202
224
|
# will use a default of .hypothesis/examples in the current directory.
|
203
225
|
# May also be set to false to disable the database functionality.
|
204
|
-
def hypothesis(
|
226
|
+
def hypothesis(
|
227
|
+
max_valid_test_cases: 200,
|
228
|
+
phases: Phase.all,
|
229
|
+
database: nil,
|
230
|
+
&block
|
231
|
+
)
|
205
232
|
unless World.current_engine.nil?
|
206
233
|
raise UsageError, 'Cannot nest hypothesis calls'
|
207
234
|
end
|
@@ -210,6 +237,7 @@ module Hypothesis
|
|
210
237
|
World.current_engine = Engine.new(
|
211
238
|
hypothesis_stable_identifier,
|
212
239
|
max_examples: max_valid_test_cases,
|
240
|
+
phases: phases,
|
213
241
|
database: database
|
214
242
|
)
|
215
243
|
World.current_engine.run(&block)
|
data/lib/hypothesis/engine.rb
CHANGED
@@ -19,7 +19,11 @@ module Hypothesis
|
|
19
19
|
database = nil if database == false
|
20
20
|
|
21
21
|
@core_engine = HypothesisCoreEngine.new(
|
22
|
-
name,
|
22
|
+
name,
|
23
|
+
database,
|
24
|
+
seed,
|
25
|
+
options.fetch(:max_examples),
|
26
|
+
options.fetch(:phases)
|
23
27
|
)
|
24
28
|
|
25
29
|
@exceptions_to_tags = Hash.new { |h, k| h[k] = h.size }
|
data/src/lib.rs
CHANGED
@@ -4,15 +4,19 @@ extern crate rutie;
|
|
4
4
|
extern crate lazy_static;
|
5
5
|
extern crate conjecture;
|
6
6
|
|
7
|
+
use std::convert::TryFrom;
|
7
8
|
use std::mem;
|
8
9
|
|
9
|
-
use rutie::{
|
10
|
+
use rutie::{
|
11
|
+
AnyException, AnyObject, Array, Boolean, Class, Exception, Float, Integer, NilClass, Object,
|
12
|
+
RString, Symbol, VM,
|
13
|
+
};
|
10
14
|
|
11
15
|
use conjecture::data::{DataSource, Status, TestResult};
|
12
16
|
use conjecture::database::{BoxedDatabase, DirectoryDatabase, NoDatabase};
|
13
17
|
use conjecture::distributions;
|
14
18
|
use conjecture::distributions::Repeat;
|
15
|
-
use conjecture::engine::Engine;
|
19
|
+
use conjecture::engine::{Engine, Phase};
|
16
20
|
|
17
21
|
pub struct HypothesisCoreDataSourceStruct {
|
18
22
|
source: Option<DataSource>,
|
@@ -77,6 +81,7 @@ impl HypothesisCoreEngineStruct {
|
|
77
81
|
database_path: Option<String>,
|
78
82
|
seed: u64,
|
79
83
|
max_examples: u64,
|
84
|
+
phases: Vec<Phase>,
|
80
85
|
) -> HypothesisCoreEngineStruct {
|
81
86
|
let xs: [u32; 2] = [seed as u32, (seed >> 32) as u32];
|
82
87
|
let db: BoxedDatabase = match database_path {
|
@@ -85,7 +90,7 @@ impl HypothesisCoreEngineStruct {
|
|
85
90
|
};
|
86
91
|
|
87
92
|
HypothesisCoreEngineStruct {
|
88
|
-
engine: Engine::new(name, max_examples, &xs, db),
|
93
|
+
engine: Engine::new(name, max_examples, phases, &xs, db),
|
89
94
|
pending: None,
|
90
95
|
interesting_examples: Vec::new(),
|
91
96
|
}
|
@@ -151,13 +156,26 @@ methods!(
|
|
151
156
|
name: RString,
|
152
157
|
database_path: RString,
|
153
158
|
seed: Integer,
|
154
|
-
max_example: Integer
|
159
|
+
max_example: Integer,
|
160
|
+
phases: Array
|
155
161
|
) -> AnyObject {
|
162
|
+
let rust_phases = safe_access(phases)
|
163
|
+
.into_iter()
|
164
|
+
.map(|ruby_phase| {
|
165
|
+
let phase_sym = safe_access(ruby_phase.try_convert_to::<Symbol>());
|
166
|
+
let phase = Phase::try_from(phase_sym.to_str())
|
167
|
+
.map_err(|e| AnyException::new("ArgumentError", Some(&e)));
|
168
|
+
|
169
|
+
safe_access(phase)
|
170
|
+
})
|
171
|
+
.collect();
|
172
|
+
|
156
173
|
let core_engine = HypothesisCoreEngineStruct::new(
|
157
174
|
safe_access(name).to_string(),
|
158
175
|
database_path.ok().map(|p| p.to_string()),
|
159
176
|
safe_access(seed).to_u64(),
|
160
177
|
safe_access(max_example).to_u64(),
|
178
|
+
rust_phases,
|
161
179
|
);
|
162
180
|
|
163
181
|
Class::from_existing("HypothesisCoreEngine")
|
@@ -465,5 +483,5 @@ fn mark_child_status(
|
|
465
483
|
}
|
466
484
|
|
467
485
|
fn safe_access<T>(value: Result<T, AnyException>) -> T {
|
468
|
-
|
486
|
+
value.map_err(VM::raise_ex).unwrap()
|
469
487
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hypothesis-specs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David R. Maciver
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01-
|
12
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rutie
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
rubygems_version: 3.2.
|
92
|
+
rubygems_version: 3.2.6
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: Hypothesis is a powerful, flexible, and easy to use library for property-based
|