test_tube 1.0.0.beta0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -3
- data/lib/test_tube.rb +30 -15
- data/lib/test_tube/base.rb +1 -1
- data/lib/test_tube/{content.rb → invoker.rb} +2 -2
- data/lib/test_tube/{liquid.rb → passer.rb} +3 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed96729c5b8c3a0ccef89cc6739da3e46e54c70eaf3e0975ca7af8d74db23d26
|
4
|
+
data.tar.gz: b534c7cb0d0e5de7ce02c328b1be76960214ec4e6a4d45b031fafb1d9ffac136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48ac22dc6ada96e416df896a7c6e4bf7242e2391ce3788c28b2a2aeaa2ee93a18ed5f690be51dc0a434c97a8185c112a796cb7f0985dabe90eb39b33f8b4fee9
|
7
|
+
data.tar.gz: 5a508032716cd4836009b9ac4b2b1fcdfa07e7b579fbfae771563bdebb81cf6e68efa2a7edbe897f8162015c8e45c0ba46346785026867f227cae14da4c398ca
|
data/README.md
CHANGED
@@ -28,8 +28,8 @@ gem install test_tube
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
|
32
|
-
Everything:
|
31
|
+
Assuming we'd like to experiment on the answer to the Ultimate Question of Life,
|
32
|
+
the Universe, and Everything with the following matcher:
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
class BeTheAnswer
|
@@ -37,8 +37,12 @@ class BeTheAnswer
|
|
37
37
|
42.equal?(yield)
|
38
38
|
end
|
39
39
|
end
|
40
|
+
```
|
41
|
+
|
42
|
+
One possibility would be to challenge a whole block of code:
|
40
43
|
|
41
|
-
|
44
|
+
```ruby
|
45
|
+
tt = TestTube.invoke(
|
42
46
|
-> { "101010".to_i(2) },
|
43
47
|
isolation: false,
|
44
48
|
matcher: BeTheAnswer.new,
|
@@ -51,6 +55,21 @@ tt.error # => nil
|
|
51
55
|
tt.got # => true
|
52
56
|
```
|
53
57
|
|
58
|
+
An alternative would be to challenge a value passed as a parameter:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
tt = TestTube.pass(
|
62
|
+
"101010".to_i(2),
|
63
|
+
matcher: BeTheAnswer.new,
|
64
|
+
negate: false
|
65
|
+
)
|
66
|
+
# => #<TestTube::Passer:0x00007f85c229c2d8 @actual=42, @got=true>
|
67
|
+
|
68
|
+
tt.actual # => 42
|
69
|
+
tt.error # => nil
|
70
|
+
tt.got # => true
|
71
|
+
```
|
72
|
+
|
54
73
|
## Contact
|
55
74
|
|
56
75
|
* Source code: https://github.com/fixrb/test_tube
|
data/lib/test_tube.rb
CHANGED
@@ -1,26 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative File.join("test_tube", "
|
4
|
-
require_relative File.join("test_tube", "
|
3
|
+
require_relative File.join("test_tube", "invoker")
|
4
|
+
require_relative File.join("test_tube", "passer")
|
5
5
|
|
6
6
|
# Namespace for the TestTube library.
|
7
7
|
module TestTube
|
8
|
-
# @param input [#call]
|
9
|
-
# @param isolation [Boolean]
|
10
|
-
# @param matcher [#matches?]
|
11
|
-
# @param negate [Boolean]
|
8
|
+
# @param input [#call] The callable object to test.
|
9
|
+
# @param isolation [Boolean] Compute in isolation or not.
|
10
|
+
# @param matcher [#matches?] A matcher.
|
11
|
+
# @param negate [Boolean] Invert the matcher or not.
|
12
12
|
#
|
13
|
-
# @
|
14
|
-
|
15
|
-
|
13
|
+
# @example
|
14
|
+
# invoke(
|
15
|
+
# -> { "101010".to_i(2) },
|
16
|
+
# isolation: false,
|
17
|
+
# matcher: BeTheAnswer.new,
|
18
|
+
# negate: false
|
19
|
+
# )
|
20
|
+
#
|
21
|
+
# @return [Invoker] A software experiment.
|
22
|
+
def self.invoke(input, isolation:, matcher:, negate:)
|
23
|
+
Invoker.new(input, isolation: isolation, matcher: matcher, negate: negate)
|
16
24
|
end
|
17
25
|
|
18
|
-
# @param input [#
|
19
|
-
# @param matcher [#matches?]
|
20
|
-
# @param negate [Boolean]
|
26
|
+
# @param input [#object_id] The callable object to test.
|
27
|
+
# @param matcher [#matches?] A matcher.
|
28
|
+
# @param negate [Boolean] Invert the matcher or not.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# pass(
|
32
|
+
# "101010".to_i(2),
|
33
|
+
# matcher: BeTheAnswer.new,
|
34
|
+
# negate: false
|
35
|
+
# )
|
21
36
|
#
|
22
|
-
# @return [
|
23
|
-
def self.
|
24
|
-
|
37
|
+
# @return [Passer] A software experiment.
|
38
|
+
def self.pass(input, matcher:, negate:)
|
39
|
+
Passer.new(input, matcher: matcher, negate: negate)
|
25
40
|
end
|
26
41
|
end
|
data/lib/test_tube/base.rb
CHANGED
@@ -5,8 +5,8 @@ require "defi"
|
|
5
5
|
require_relative "base"
|
6
6
|
|
7
7
|
module TestTube
|
8
|
-
# The
|
9
|
-
class
|
8
|
+
# The invoker class is great for blocks.
|
9
|
+
class Invoker < Base
|
10
10
|
# Software experiments.
|
11
11
|
#
|
12
12
|
# rubocop:disable Lint/RescueException, Metrics/MethodLength
|
@@ -3,8 +3,8 @@
|
|
3
3
|
require_relative "base"
|
4
4
|
|
5
5
|
module TestTube
|
6
|
-
# The
|
7
|
-
class
|
6
|
+
# The passer class is great for values.
|
7
|
+
class Passer < Base
|
8
8
|
# Software experiments.
|
9
9
|
#
|
10
10
|
# @param input [#object_id] An actual value to test.
|
@@ -14,7 +14,7 @@ module TestTube
|
|
14
14
|
super()
|
15
15
|
|
16
16
|
@actual = input
|
17
|
-
@got = negate ^ matcher.matches? {
|
17
|
+
@got = negate ^ matcher.matches? { input }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
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: 1.0.0
|
4
|
+
version: 1.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-06-
|
11
|
+
date: 2021-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: defi
|
@@ -160,8 +160,8 @@ files:
|
|
160
160
|
- README.md
|
161
161
|
- lib/test_tube.rb
|
162
162
|
- lib/test_tube/base.rb
|
163
|
-
- lib/test_tube/
|
164
|
-
- lib/test_tube/
|
163
|
+
- lib/test_tube/invoker.rb
|
164
|
+
- lib/test_tube/passer.rb
|
165
165
|
homepage: https://github.com/fixrb/test_tube
|
166
166
|
licenses:
|
167
167
|
- MIT
|
@@ -177,9 +177,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: 2.7.0
|
178
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
179
|
requirements:
|
180
|
-
- - "
|
180
|
+
- - ">="
|
181
181
|
- !ruby/object:Gem::Version
|
182
|
-
version:
|
182
|
+
version: '0'
|
183
183
|
requirements: []
|
184
184
|
rubygems_version: 3.1.6
|
185
185
|
signing_key:
|