test_tube 1.1.0 → 2.0.0
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 +4 -4
- data/README.md +18 -15
- data/lib/test_tube.rb +11 -13
- data/lib/test_tube/base.rb +2 -0
- data/lib/test_tube/invoker.rb +4 -2
- data/lib/test_tube/passer.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b343e487d9f73eb0af9f0aeee5ba11c35cab9f644e7a106b3f8a259f3567d142
|
4
|
+
data.tar.gz: 9b28e9986b96cc1af7f1db0b9e98715364a4ff08579038d0a9663a67bd6dbf78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dd6be662939a33715130137e2ea9c6f5cebf95b9c33c18bf56457f2c08ac5e50e094c7e63eff045a1d7d9b4bfcee1db2652d43bcd1fc0a324e3ad99e3e1d17e
|
7
|
+
data.tar.gz: 9139defd6aa5d96e1d7b2dcfd676a60757b6bb496fb8ea071164e04c624de3e2d327bede1148e5fd793b5c39c57e7715e69f2982f8de6df9bfc95ed85b7b4c27
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Test Tube
|
2
2
|
|
3
|
-
[](https://github.com/fixrb/test_tube/releases)
|
4
|
+
[](https://rubydoc.info/github/fixrb/test_tube/main)
|
5
|
+
[](https://github.com/fixrb/test_tube/actions?query=workflow%3Aci+branch%3Amain)
|
6
|
+
[](https://github.com/fixrb/test_tube/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
|
+
[](https://github.com/fixrb/test_tube/raw/main/LICENSE.md)
|
6
8
|
|
7
9
|
> A test tube to conduct software experiments 🧪
|
8
10
|
|
@@ -57,10 +59,10 @@ of code:
|
|
57
59
|
block_of_code = -> { "101010".to_i(2) }
|
58
60
|
|
59
61
|
experiment = TestTube.invoke(
|
60
|
-
block_of_code,
|
61
62
|
isolation: false,
|
62
63
|
matcher: BeTheAnswer.new,
|
63
|
-
negate: false
|
64
|
+
negate: false,
|
65
|
+
&block_of_code
|
64
66
|
)
|
65
67
|
|
66
68
|
experiment.actual # => 42
|
@@ -85,6 +87,7 @@ experiment.got # => true
|
|
85
87
|
```
|
86
88
|
|
87
89
|
### __Matchi__ matchers
|
90
|
+
|
88
91
|
To facilitate the addition of matchers, a collection is available via the
|
89
92
|
[__Matchi__ project](https://github.com/fixrb/matchi/).
|
90
93
|
|
@@ -102,11 +105,12 @@ An example of successful experience:
|
|
102
105
|
|
103
106
|
```ruby
|
104
107
|
experiment = TestTube.invoke(
|
105
|
-
-> { "foo".blank? },
|
106
108
|
isolation: false,
|
107
109
|
matcher: Matchi::Matcher::RaiseException.new(NoMethodError),
|
108
110
|
negate: false
|
109
|
-
)
|
111
|
+
) do
|
112
|
+
"foo".blank?
|
113
|
+
end
|
110
114
|
|
111
115
|
experiment.actual # => #<NoMethodError: undefined method `blank?' for "foo":String>
|
112
116
|
experiment.error # => nil
|
@@ -117,10 +121,10 @@ Another example of an experiment that fails:
|
|
117
121
|
|
118
122
|
```ruby
|
119
123
|
experiment = TestTube.invoke(
|
120
|
-
-> { 0.1 + 0.2 },
|
121
124
|
isolation: false,
|
122
125
|
matcher: Matchi::Matcher::Equal.new(0.3),
|
123
|
-
negate: false
|
126
|
+
negate: false,
|
127
|
+
&-> { 0.1 + 0.2 }
|
124
128
|
)
|
125
129
|
|
126
130
|
experiment.actual # => 0.30000000000000004
|
@@ -132,11 +136,10 @@ Finally, an experiment which causes an error:
|
|
132
136
|
|
133
137
|
```ruby
|
134
138
|
experiment = TestTube.invoke(
|
135
|
-
-> { BOOM },
|
136
139
|
isolation: false,
|
137
140
|
matcher: Matchi::Matcher::Match.new(/^foo$/),
|
138
141
|
negate: false
|
139
|
-
)
|
142
|
+
) { BOOM }
|
140
143
|
|
141
144
|
experiment.actual # => nil
|
142
145
|
experiment.error # => #<NameError: uninitialized constant BOOM>
|
@@ -160,10 +163,10 @@ side effects:
|
|
160
163
|
|
161
164
|
```ruby
|
162
165
|
experiment = TestTube.invoke(
|
163
|
-
block_of_code,
|
164
166
|
isolation: true,
|
165
167
|
matcher: Matchi::Matcher::Eql.new("Hello, Alice!"),
|
166
|
-
negate: false
|
168
|
+
negate: false,
|
169
|
+
&block_of_code
|
167
170
|
)
|
168
171
|
|
169
172
|
experiment.inspect # => <TestTube actual="Hello, Alice!" error=nil got=true>
|
@@ -175,10 +178,10 @@ Otherwise, we can experiment without any code isolation:
|
|
175
178
|
|
176
179
|
```ruby
|
177
180
|
experiment = TestTube.invoke(
|
178
|
-
block_of_code,
|
179
181
|
isolation: false,
|
180
182
|
matcher: Matchi::Matcher::Eql.new("Hello, Alice!"),
|
181
|
-
negate: false
|
183
|
+
negate: false,
|
184
|
+
&block_of_code
|
182
185
|
)
|
183
186
|
|
184
187
|
experiment.inspect # => <TestTube actual="Hello, Alice!" error=nil got=true>
|
data/lib/test_tube.rb
CHANGED
@@ -4,11 +4,13 @@ require_relative File.join("test_tube", "invoker")
|
|
4
4
|
require_relative File.join("test_tube", "passer")
|
5
5
|
|
6
6
|
# Namespace for the TestTube library.
|
7
|
+
#
|
8
|
+
# @api public
|
7
9
|
module TestTube
|
8
|
-
# @param input [#call] The callable object to test.
|
9
10
|
# @param isolation [Boolean] Compute in isolation or not.
|
10
11
|
# @param matcher [#matches?] A matcher.
|
11
12
|
# @param negate [Boolean] Invert the matcher or not.
|
13
|
+
# @param input [Proc] The callable object to test.
|
12
14
|
#
|
13
15
|
# @example
|
14
16
|
# require "test_tube"
|
@@ -19,16 +21,13 @@ module TestTube
|
|
19
21
|
# end
|
20
22
|
# end
|
21
23
|
#
|
22
|
-
# TestTube.invoke(
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# matcher: BeTheAnswer.new,
|
26
|
-
# negate: false
|
27
|
-
# )
|
24
|
+
# TestTube.invoke(isolation: false, matcher: BeTheAnswer.new, negate: false) do
|
25
|
+
# "101010".to_i(2)
|
26
|
+
# end
|
28
27
|
#
|
29
28
|
# @return [Invoker] A software experiment.
|
30
|
-
def self.invoke(
|
31
|
-
Invoker.new(
|
29
|
+
def self.invoke(isolation:, matcher:, negate:, &input)
|
30
|
+
Invoker.new(isolation: isolation, matcher: matcher, negate: negate, &input)
|
32
31
|
end
|
33
32
|
|
34
33
|
# @param input [#object_id] The callable object to test.
|
@@ -44,10 +43,9 @@ module TestTube
|
|
44
43
|
# end
|
45
44
|
# end
|
46
45
|
#
|
47
|
-
# TestTube.pass(
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# negate: false
|
46
|
+
# TestTube.pass("101010".to_i(2),
|
47
|
+
# matcher: BeTheAnswer.new,
|
48
|
+
# negate: false
|
51
49
|
# )
|
52
50
|
#
|
53
51
|
# @return [Passer] A software experiment.
|
data/lib/test_tube/base.rb
CHANGED
data/lib/test_tube/invoker.rb
CHANGED
@@ -6,16 +6,18 @@ require_relative "base"
|
|
6
6
|
|
7
7
|
module TestTube
|
8
8
|
# Evaluate an actual value invoking it with #call method.
|
9
|
+
#
|
10
|
+
# @api private
|
9
11
|
class Invoker < Base
|
10
12
|
# Class initializer.
|
11
13
|
#
|
12
14
|
# rubocop:disable Lint/RescueException, Metrics/MethodLength
|
13
15
|
#
|
14
|
-
# @param input [#call] The callable object to test.
|
15
16
|
# @param isolation [Boolean] Compute in isolation or not.
|
16
17
|
# @param matcher [#matches?] A matcher.
|
17
18
|
# @param negate [Boolean] Invert the matcher or not.
|
18
|
-
|
19
|
+
# @param input [Proc] The callable object to test.
|
20
|
+
def initialize(isolation:, matcher:, negate:, &input)
|
19
21
|
super()
|
20
22
|
|
21
23
|
@got = negate ^ matcher.matches? do
|
data/lib/test_tube/passer.rb
CHANGED
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: 2.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: 2021-
|
11
|
+
date: 2021-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: defi
|