test_tube 2.1.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +6 -48
- data/lib/test_tube/invoker.rb +8 -14
- data/lib/test_tube.rb +4 -5
- metadata +8 -147
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a1dbc9ba1ec31cf75bfc230ce4eecd83b8fdaa948b0dbaa0787579d659ad7ba
|
4
|
+
data.tar.gz: f007123f4496bec8617bbc12be65b8b436c61afbead33d9a1f410dd906fdf6ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e95aa4c56a4d7f4de41056584c76f3734068f406a19991cef9b03da1f256e3e743db4a2fe4651241778686f916f206190ccae29fa93bc6a74b48f0adc3a85481
|
7
|
+
data.tar.gz: 815b44987f0e28b5930a27930d1b089218b33b33bc32d7e66d4dce147d159699584986f979c1ed218b449da4d5d07e4ffe812d3edacd44c03f01d8dd6fe08170
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Test Tube
|
2
2
|
|
3
|
-
[![Version](https://img.shields.io/github/v/tag/fixrb/test_tube?label=Version&logo=github)](https://github.com/fixrb/test_tube/
|
3
|
+
[![Version](https://img.shields.io/github/v/tag/fixrb/test_tube?label=Version&logo=github)](https://github.com/fixrb/test_tube/tags)
|
4
4
|
[![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/test_tube/main)
|
5
|
-
[![
|
5
|
+
[![Ruby](https://github.com/fixrb/test_tube/workflows/Ruby/badge.svg?branch=main)](https://github.com/fixrb/test_tube/actions?query=workflow%3Aruby+branch%3Amain)
|
6
6
|
[![RuboCop](https://github.com/fixrb/test_tube/workflows/RuboCop/badge.svg?branch=main)](https://github.com/fixrb/test_tube/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
7
|
[![License](https://img.shields.io/github/license/fixrb/test_tube?label=License&logo=github)](https://github.com/fixrb/test_tube/raw/main/LICENSE.md)
|
8
8
|
|
@@ -21,7 +21,7 @@ gem "test_tube"
|
|
21
21
|
And then execute:
|
22
22
|
|
23
23
|
```sh
|
24
|
-
bundle
|
24
|
+
bundle install
|
25
25
|
```
|
26
26
|
|
27
27
|
Or install it yourself as:
|
@@ -54,7 +54,7 @@ One possibility would be to `invoke` a whole block of code:
|
|
54
54
|
```ruby
|
55
55
|
block_of_code = -> { "101010".to_i(2) }
|
56
56
|
|
57
|
-
experiment = TestTube.invoke(
|
57
|
+
experiment = TestTube.invoke(matcher: BeTheAnswer.new, negate: false, &block_of_code)
|
58
58
|
# => <TestTube actual=42 error=nil got=true>
|
59
59
|
|
60
60
|
experiment.actual # => 42
|
@@ -94,7 +94,6 @@ An example of successful experience:
|
|
94
94
|
|
95
95
|
```ruby
|
96
96
|
experiment = TestTube.invoke(
|
97
|
-
isolate: false,
|
98
97
|
matcher: Matchi::RaiseException.new(:NoMethodError),
|
99
98
|
negate: false
|
100
99
|
) { "foo".blank? }
|
@@ -109,7 +108,6 @@ Another example of an experiment that fails:
|
|
109
108
|
|
110
109
|
```ruby
|
111
110
|
experiment = TestTube.invoke(
|
112
|
-
isolate: false,
|
113
111
|
matcher: Matchi::Be.new(0.3),
|
114
112
|
negate: false,
|
115
113
|
&-> { 0.1 + 0.2 }
|
@@ -124,7 +122,6 @@ Finally, an experiment which causes an error:
|
|
124
122
|
|
125
123
|
```ruby
|
126
124
|
experiment = TestTube.invoke(
|
127
|
-
isolate: false,
|
128
125
|
matcher: Matchi::Match.new(/^foo$/),
|
129
126
|
negate: false
|
130
127
|
) { BOOM }
|
@@ -135,45 +132,6 @@ experiment.error # => #<NameError: uninitialized constant BOOM>
|
|
135
132
|
experiment.got # => nil
|
136
133
|
```
|
137
134
|
|
138
|
-
### Code isolation
|
139
|
-
|
140
|
-
When experimenting tests, side-effects may occur. Because they may or may not be
|
141
|
-
desired, an `isolate` option is available.
|
142
|
-
|
143
|
-
Let's for instance consider this block of code:
|
144
|
-
|
145
|
-
```ruby
|
146
|
-
greeting = "Hello, world!"
|
147
|
-
block_of_code = -> { greeting.gsub!("world", "Alice") } # => #<Proc:0x00007f87f71b9690 (irb):42 (lambda)>
|
148
|
-
```
|
149
|
-
|
150
|
-
By setting the `isolate` option to `true`, we can experiment while avoiding
|
151
|
-
side effects:
|
152
|
-
|
153
|
-
```ruby
|
154
|
-
experiment = TestTube.invoke(
|
155
|
-
isolate: true,
|
156
|
-
matcher: Matchi::Eq.new("Hello, Alice!"),
|
157
|
-
negate: false,
|
158
|
-
&block_of_code
|
159
|
-
) # => <TestTube actual="Hello, Alice!" error=nil got=true>
|
160
|
-
|
161
|
-
greeting # => "Hello, world!"
|
162
|
-
```
|
163
|
-
|
164
|
-
Otherwise, we can experiment without any code isolation:
|
165
|
-
|
166
|
-
```ruby
|
167
|
-
experiment = TestTube.invoke(
|
168
|
-
isolate: false,
|
169
|
-
matcher: Matchi::Eq.new("Hello, Alice!"),
|
170
|
-
negate: false,
|
171
|
-
&block_of_code
|
172
|
-
) # => <TestTube actual="Hello, Alice!" error=nil got=true>
|
173
|
-
|
174
|
-
greeting # => "Hello, Alice!"
|
175
|
-
```
|
176
|
-
|
177
135
|
## Contact
|
178
136
|
|
179
137
|
* Source code: https://github.com/fixrb/test_tube
|
@@ -188,11 +146,11 @@ __Test Tube__ follows [Semantic Versioning 2.0](https://semver.org/).
|
|
188
146
|
|
189
147
|
The [gem](https://rubygems.org/gems/test_tube) is available as open source under the terms of the [MIT License](https://github.com/fixrb/test_tube/raw/main/LICENSE.md).
|
190
148
|
|
191
|
-
|
149
|
+
---
|
192
150
|
|
193
151
|
<p>
|
194
152
|
This project is sponsored by:<br />
|
195
153
|
<a href="https://sashite.com/"><img
|
196
154
|
src="https://github.com/fixrb/test_tube/raw/main/img/sashite.png"
|
197
|
-
alt="
|
155
|
+
alt="Sashité" /></a>
|
198
156
|
</p>
|
data/lib/test_tube/invoker.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "defi"
|
3
|
+
require "defi/method"
|
4
4
|
|
5
5
|
require_relative "base"
|
6
6
|
|
@@ -9,24 +9,18 @@ module TestTube
|
|
9
9
|
#
|
10
10
|
# @api private
|
11
11
|
class Invoker < Base
|
12
|
-
# rubocop:disable Lint/RescueException
|
12
|
+
# rubocop:disable Lint/RescueException
|
13
13
|
|
14
14
|
# Class initializer.
|
15
15
|
#
|
16
|
-
# @param isolate [Boolean] Compute in a subprocess.
|
17
16
|
# @param matcher [#matches?] A matcher.
|
18
17
|
# @param negate [Boolean] Invert the matcher or not.
|
19
18
|
# @param input [Proc] The callable object to test.
|
20
|
-
def initialize(
|
19
|
+
def initialize(matcher:, negate:, &input)
|
21
20
|
super()
|
22
21
|
|
23
22
|
@got = negate ^ matcher.matches? do
|
24
|
-
value =
|
25
|
-
send_call.to!(input)
|
26
|
-
else
|
27
|
-
send_call.to(input)
|
28
|
-
end
|
29
|
-
|
23
|
+
value = send_call.to(input)
|
30
24
|
@actual = value.object
|
31
25
|
value.call
|
32
26
|
end
|
@@ -35,15 +29,15 @@ module TestTube
|
|
35
29
|
@error = e
|
36
30
|
end
|
37
31
|
|
38
|
-
# rubocop:enable Lint/RescueException
|
32
|
+
# rubocop:enable Lint/RescueException
|
39
33
|
|
40
34
|
private
|
41
35
|
|
42
|
-
# @return [::Defi::
|
36
|
+
# @return [::Defi::Method] The challenge for the callable object.
|
43
37
|
#
|
44
|
-
# @see https://github.com/fixrb/defi/blob/
|
38
|
+
# @see https://github.com/fixrb/defi/blob/v3.0.0/lib/defi/method.rb
|
45
39
|
def send_call
|
46
|
-
::Defi.
|
40
|
+
::Defi::Method.new(:call)
|
47
41
|
end
|
48
42
|
end
|
49
43
|
end
|
data/lib/test_tube.rb
CHANGED
@@ -7,7 +7,6 @@ require_relative File.join("test_tube", "passer")
|
|
7
7
|
#
|
8
8
|
# @api public
|
9
9
|
module TestTube
|
10
|
-
# @param isolate [Boolean] Compute in a subprocess.
|
11
10
|
# @param matcher [#matches?] A matcher.
|
12
11
|
# @param negate [Boolean] Invert the matcher or not.
|
13
12
|
# @param input [Proc] The callable object to test.
|
@@ -21,13 +20,13 @@ module TestTube
|
|
21
20
|
# end
|
22
21
|
# end
|
23
22
|
#
|
24
|
-
# TestTube.invoke(
|
23
|
+
# TestTube.invoke(matcher: BeTheAnswer.new, negate: false) do
|
25
24
|
# "101010".to_i(2)
|
26
25
|
# end
|
27
26
|
#
|
28
27
|
# @return [Invoker] A software experiment.
|
29
|
-
def self.invoke(
|
30
|
-
Invoker.new(
|
28
|
+
def self.invoke(matcher:, negate:, &input)
|
29
|
+
Invoker.new(matcher:, negate:, &input)
|
31
30
|
end
|
32
31
|
|
33
32
|
# @param input [#object_id] The actual value to test.
|
@@ -50,6 +49,6 @@ module TestTube
|
|
50
49
|
#
|
51
50
|
# @return [Passer] A software experiment.
|
52
51
|
def self.pass(input, matcher:, negate:)
|
53
|
-
Passer.new(input, matcher
|
52
|
+
Passer.new(input, matcher:, negate:)
|
54
53
|
end
|
55
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_tube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: defi
|
@@ -16,154 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: brutal
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: matchi
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-md
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-performance
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rubocop-rake
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop-thread_safety
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: simplecov
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: yard
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
26
|
+
version: 3.0.0
|
167
27
|
description: "A test tube to conduct software experiments \U0001F9EA"
|
168
28
|
email: contact@cyril.email
|
169
29
|
executables: []
|
@@ -179,7 +39,8 @@ files:
|
|
179
39
|
homepage: https://github.com/fixrb/test_tube
|
180
40
|
licenses:
|
181
41
|
- MIT
|
182
|
-
metadata:
|
42
|
+
metadata:
|
43
|
+
rubygems_mfa_required: 'true'
|
183
44
|
post_install_message:
|
184
45
|
rdoc_options: []
|
185
46
|
require_paths:
|
@@ -188,14 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
49
|
requirements:
|
189
50
|
- - ">="
|
190
51
|
- !ruby/object:Gem::Version
|
191
|
-
version: 2.
|
52
|
+
version: 3.2.0
|
192
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
54
|
requirements:
|
194
55
|
- - ">="
|
195
56
|
- !ruby/object:Gem::Version
|
196
57
|
version: '0'
|
197
58
|
requirements: []
|
198
|
-
rubygems_version: 3.
|
59
|
+
rubygems_version: 3.4.19
|
199
60
|
signing_key:
|
200
61
|
specification_version: 4
|
201
62
|
summary: "A test tube to conduct software experiments \U0001F9EA"
|