test_tube 2.1.3 → 4.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 +8 -55
- data/lib/test_tube/invoker.rb +10 -16
- data/lib/test_tube/passer.rb +2 -2
- data/lib/test_tube.rb +15 -16
- metadata +8 -150
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a511d50711ff51b4ca13b4e6228f2e0d88dbfcb04b89ccb37619b1b2a3248073
|
4
|
+
data.tar.gz: 2eac86be8bdfc2733ed2fb11aa90bd4177c548e5319765549c04dd458dfd56e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80032c8cfacc36e4e49b48ba74dfbf0f0f82d8198fc2c40d66e42046d331312eb15a05bd11db0aa92fb748d3e9c6856731d3643bb543d0a90d4d725d43de9fd5
|
7
|
+
data.tar.gz: 4948793c91f4f2842af624a91d791875542c0eca3855780d266d88bc2c9153cb14fea30daf4e3f4afcd0671e439a80bb006ffba760b9669a93e4c577e8c9e345
|
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:
|
@@ -43,7 +43,7 @@ the Universe, and Everything with the following matcher:
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
class BeTheAnswer
|
46
|
-
def
|
46
|
+
def match?
|
47
47
|
42.equal?(yield)
|
48
48
|
end
|
49
49
|
end
|
@@ -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
|
@@ -78,7 +78,7 @@ experiment.got # => true
|
|
78
78
|
### __Matchi__ matchers
|
79
79
|
|
80
80
|
To facilitate the addition of matchers, a collection is available via the
|
81
|
-
[
|
81
|
+
[Matchi project](https://github.com/fixrb/matchi/).
|
82
82
|
|
83
83
|
Let's use a built-in __Matchi__ matcher:
|
84
84
|
|
@@ -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,6 @@ __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
|
+
## Sponsors
|
192
150
|
|
193
|
-
|
194
|
-
This project is sponsored by:<br />
|
195
|
-
<a href="https://sashite.com/"><img
|
196
|
-
src="https://github.com/fixrb/test_tube/raw/main/img/sashite.png"
|
197
|
-
alt="Sashite" /></a>
|
198
|
-
</p>
|
151
|
+
This project is sponsored by [Sashité](https://sashite.com/)
|
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
|
17
|
-
# @param matcher [#matches?] A matcher.
|
16
|
+
# @param matcher [#match?] 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
|
-
@got = negate ^ matcher.
|
24
|
-
value =
|
25
|
-
send_call.to!(input)
|
26
|
-
else
|
27
|
-
send_call.to(input)
|
28
|
-
end
|
29
|
-
|
22
|
+
@got = negate ^ matcher.match? do
|
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/passer.rb
CHANGED
@@ -10,13 +10,13 @@ module TestTube
|
|
10
10
|
# Class initializer.
|
11
11
|
#
|
12
12
|
# @param input [#object_id] The actual value to test.
|
13
|
-
# @param matcher [#
|
13
|
+
# @param matcher [#match?] A matcher.
|
14
14
|
# @param negate [Boolean] Invert the matcher or not.
|
15
15
|
def initialize(input, matcher:, negate:)
|
16
16
|
super()
|
17
17
|
|
18
18
|
@actual = input
|
19
|
-
@got = negate ^ matcher.
|
19
|
+
@got = negate ^ matcher.match? { input }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/test_tube.rb
CHANGED
@@ -7,38 +7,37 @@ require_relative File.join("test_tube", "passer")
|
|
7
7
|
#
|
8
8
|
# @api public
|
9
9
|
module TestTube
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @
|
13
|
-
# @param input [Proc] The callable object to test.
|
10
|
+
# Invokes a block for testing.
|
11
|
+
#
|
12
|
+
# @see TestTube::Invoker#initialize for parameter details
|
14
13
|
#
|
15
14
|
# @example
|
16
15
|
# require "test_tube"
|
17
16
|
#
|
18
17
|
# class BeTheAnswer
|
19
|
-
# def
|
18
|
+
# def match?
|
20
19
|
# 42.equal?(yield)
|
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
|
-
# @return [Invoker] A software experiment.
|
29
|
-
def self.invoke(
|
30
|
-
Invoker.new(
|
27
|
+
# @return [TestTube::Invoker] A software experiment.
|
28
|
+
def self.invoke(...)
|
29
|
+
Invoker.new(...)
|
31
30
|
end
|
32
31
|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# @
|
32
|
+
# Tests a value directly.
|
33
|
+
#
|
34
|
+
# @see TestTube::Passer#initialize for parameter details
|
36
35
|
#
|
37
36
|
# @example
|
38
37
|
# require "test_tube"
|
39
38
|
#
|
40
39
|
# class BeTheAnswer
|
41
|
-
# def
|
40
|
+
# def match?
|
42
41
|
# 42.equal?(yield)
|
43
42
|
# end
|
44
43
|
# end
|
@@ -48,8 +47,8 @@ module TestTube
|
|
48
47
|
# negate: false
|
49
48
|
# )
|
50
49
|
#
|
51
|
-
# @return [Passer] A software experiment.
|
52
|
-
def self.pass(
|
53
|
-
Passer.new(
|
50
|
+
# @return [TestTube::Passer] A software experiment.
|
51
|
+
def self.pass(...)
|
52
|
+
Passer.new(...)
|
54
53
|
end
|
55
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_tube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: defi
|
@@ -16,154 +15,14 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: 3.0.0
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !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'
|
25
|
+
version: 3.0.0
|
167
26
|
description: "A test tube to conduct software experiments \U0001F9EA"
|
168
27
|
email: contact@cyril.email
|
169
28
|
executables: []
|
@@ -179,8 +38,8 @@ files:
|
|
179
38
|
homepage: https://github.com/fixrb/test_tube
|
180
39
|
licenses:
|
181
40
|
- MIT
|
182
|
-
metadata:
|
183
|
-
|
41
|
+
metadata:
|
42
|
+
rubygems_mfa_required: 'true'
|
184
43
|
rdoc_options: []
|
185
44
|
require_paths:
|
186
45
|
- lib
|
@@ -188,15 +47,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
47
|
requirements:
|
189
48
|
- - ">="
|
190
49
|
- !ruby/object:Gem::Version
|
191
|
-
version: 2.
|
50
|
+
version: 3.2.0
|
192
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
52
|
requirements:
|
194
53
|
- - ">="
|
195
54
|
- !ruby/object:Gem::Version
|
196
55
|
version: '0'
|
197
56
|
requirements: []
|
198
|
-
rubygems_version: 3.
|
199
|
-
signing_key:
|
57
|
+
rubygems_version: 3.6.2
|
200
58
|
specification_version: 4
|
201
59
|
summary: "A test tube to conduct software experiments \U0001F9EA"
|
202
60
|
test_files: []
|