hypothesis-specs 0.1.2 → 0.2.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: 8e514de73ab86bfeae1d5e5801ee47e8865c4a06d90f2053f4318f9dd9df19cb
4
- data.tar.gz: 1aff7880e50e37ee73f287ac2cd318a9201cf2ba09d45ca79ad9b778eeb2d3bd
3
+ metadata.gz: 8ceb7e5a7e7c564c26e971e6e5aacce7599ef8c3b810b879141c8ea9e97f2b7f
4
+ data.tar.gz: f5de9db4207eea15c790475cc43540faf30d69e5587be623dedf6b954b556f04
5
5
  SHA512:
6
- metadata.gz: fef51bf7876fc9b0b27363e8f73f84fa4ffde68a6ac2312b9f70bd780da1dd9a8923eeff14e092679c52d1fc74136a2529ae468a4e748ad021212e391846156b
7
- data.tar.gz: 1ba9eb0a28cde4f29a127086ecb2fdce722566cc38b3cd4cfc741ec91b704501d293c10b00828ae7efcd4df931e44518e01e312da15b8a55ef0b946573b90c6b
6
+ metadata.gz: 79c6389fefaca46af95d01f1b285a6e2cc1f9dc30c185da5efd6363e65b00f00794a9ca21ee5b551e6bb06df235c10b00777b0a8d27b3c09d8e10cdf834944ff
7
+ data.tar.gz: 5129459dbc559cb3b08354e3c0e36f691a2f9aea7f58dacf01a69760bcd9d6b06d7a7e905ac19b768b31d285ce30a7c587ab8dab54a546eb600e5e14b42d069c
@@ -1,3 +1,9 @@
1
+ # Hypothesis for Ruby 0.2.0 (2018-10-24)
2
+
3
+ This release adds an example database to Hypothesis for Ruby. This means that when a test fails,
4
+ it will automatically reuse the previously shown example when you rerun it, without having to
5
+ manually pass a seed.
6
+
1
7
  # Hypothesis for Ruby 0.1.2 (2018-09-24)
2
8
 
3
9
  This release makes the code useable via a direct require.
data/Cargo.toml CHANGED
@@ -9,4 +9,4 @@ crate-type = ["cdylib"]
9
9
  [dependencies]
10
10
  helix = '0.7.5'
11
11
  rand = '0.3'
12
- conjecture = '0.3.0'
12
+ conjecture = '0.4.0'
@@ -140,12 +140,21 @@ module Hypothesis
140
140
  #
141
141
  # A call to hypothesis does the following:
142
142
  #
143
- # 1. It tries to *generate* a failing test case.
144
- # 2. If it succeeded then it will *shrink* that failing test case.
145
- # 3. Finally, it will *display* the shrunk failing test case by
143
+ # 1. It first tries to *reuse* failing test cases for previous runs.
144
+ # 2. If there were no previous failing test cases then it tries to
145
+ # *generate* new failing test cases.
146
+ # 3. If either of the first two phases found failing test cases then
147
+ # it will *shrink* those failing test cases.
148
+ # 4. Finally, it will *display* the shrunk failing test case by
146
149
  # the error from its failing assertion, modified to show the
147
150
  # givens of the test case.
148
151
  #
152
+ # Reuse uses an internal representation of the test case, so examples
153
+ # from previous runs will obey all of the usual invariants of generation.
154
+ # However, this means that if you change your test then reuse may not
155
+ # work. Test cases that have become invalid or passing will be cleaned
156
+ # up automatically.
157
+ #
149
158
  # Generation consists of randomly trying test cases until one of
150
159
  # three things has happened:
151
160
  #
@@ -170,13 +179,20 @@ module Hypothesis
170
179
  #
171
180
  # @param max_valid_test_cases [Integer] The maximum number of valid test
172
181
  # cases to run without finding a failing test case before stopping.
173
- def hypothesis(max_valid_test_cases: 200, &block)
182
+ #
183
+ # @param database [String, nil, false] A path to a directory where Hypothesis
184
+ # should store previously failing test cases. If it is nil, Hypothesis
185
+ # will use a default of .hypothesis/examples in the current directory.
186
+ # May also be set to false to disable the database functionality.
187
+ def hypothesis(max_valid_test_cases: 200, database: nil, &block)
174
188
  unless World.current_engine.nil?
175
189
  raise UsageError, 'Cannot nest hypothesis calls'
176
190
  end
177
191
  begin
178
192
  World.current_engine = Engine.new(
179
- max_examples: max_valid_test_cases
193
+ hypothesis_stable_identifier,
194
+ max_examples: max_valid_test_cases,
195
+ database: database
180
196
  )
181
197
  World.current_engine.run(&block)
182
198
  ensure
@@ -7,16 +7,25 @@ require_relative '../hypothesis-ruby/native'
7
7
  require 'rspec/expectations'
8
8
 
9
9
  module Hypothesis
10
+ DEFAULT_DATABASE_PATH = File.join(Dir.pwd, '.hypothesis', 'examples')
11
+
10
12
  class Engine
11
13
  include RSpec::Matchers
12
14
 
13
15
  attr_reader :current_source
14
16
  attr_accessor :is_find
15
17
 
16
- def initialize(options)
18
+ def initialize(name, options)
17
19
  seed = Random.rand(2**64 - 1)
20
+
21
+ database = options.fetch(:database, nil)
22
+
23
+ database = DEFAULT_DATABASE_PATH if database.nil?
24
+
25
+ database = nil if database == false
26
+
18
27
  @core_engine = HypothesisCoreEngine.new(
19
- seed, options.fetch(:max_examples)
28
+ name, database, seed, options.fetch(:max_examples)
20
29
  )
21
30
 
22
31
  @exceptions_to_tags = Hash.new { |h, k| h[k] = h.size }
data/src/lib.rs CHANGED
@@ -16,6 +16,7 @@ use conjecture::data::{DataSource, Status, TestResult};
16
16
  use conjecture::distributions::Repeat;
17
17
  use conjecture::distributions;
18
18
  use conjecture::engine::Engine;
19
+ use conjecture::database::{BoxedDatabase, NoDatabase, DirectoryDatabase};
19
20
 
20
21
  ruby! {
21
22
  class HypothesisCoreDataSource {
@@ -49,11 +50,16 @@ ruby! {
49
50
  interesting_examples: Vec<TestResult>,
50
51
  }
51
52
 
52
- def initialize(helix, seed: u64, max_examples: u64){
53
+ def initialize(helix, name: String, database_path: Option<String>, seed: u64, max_examples: u64){
53
54
  let xs: [u32; 2] = [seed as u32, (seed >> 32) as u32];
55
+ let db: BoxedDatabase = match database_path {
56
+ None => Box::new(NoDatabase),
57
+ Some(path) => Box::new(DirectoryDatabase::new(path)),
58
+ };
59
+
54
60
  HypothesisCoreEngine{
55
61
  helix,
56
- engine: Engine::new(max_examples, &xs),
62
+ engine: Engine::new(name, max_examples, &xs, db),
57
63
  pending: None,
58
64
  interesting_examples: Vec::new(),
59
65
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypothesis-specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David R. Maciver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-24 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: helix_runtime