test_tube 1.1.0 → 2.0.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: f1c0e61708e5bd5a64d8c57b429c1dcdb74c35003fb2717aeb09777c10b58ed4
4
- data.tar.gz: 99e9ee9069e4b5a3124fb42566eaf9bed7cce5328335ba8ef0abc96b285f9715
3
+ metadata.gz: b343e487d9f73eb0af9f0aeee5ba11c35cab9f644e7a106b3f8a259f3567d142
4
+ data.tar.gz: 9b28e9986b96cc1af7f1db0b9e98715364a4ff08579038d0a9663a67bd6dbf78
5
5
  SHA512:
6
- metadata.gz: 3e30d9ccb6fc2186e61d6f3278da6db17568fe8144fe3008af9a1523a579eeb345246e4f5bc6675fe9d4ba3090890ef400c535f69f0fd3ba0f909f8511d17545
7
- data.tar.gz: c58676b8830b438bfde6fc83a12cf8c110e0049da7b7b63385742628e304bce385bfcbed2303d21abb26bc7b76c647394caf0d6a41679bd5e3939e762b0aa83a
6
+ metadata.gz: 3dd6be662939a33715130137e2ea9c6f5cebf95b9c33c18bf56457f2c08ac5e50e094c7e63eff045a1d7d9b4bfcee1db2652d43bcd1fc0a324e3ad99e3e1d17e
7
+ data.tar.gz: 9139defd6aa5d96e1d7b2dcfd676a60757b6bb496fb8ea071164e04c624de3e2d327bede1148e5fd793b5c39c57e7715e69f2982f8de6df9bfc95ed85b7b4c27
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Test Tube
2
2
 
3
- [![Build Status](https://api.travis-ci.org/fixrb/test_tube.svg?branch=main)](https://travis-ci.org/fixrb/test_tube)
4
- [![Gem Version](https://badge.fury.io/rb/test_tube.svg)](https://rubygems.org/gems/test_tube)
5
- [![Documentation](https://img.shields.io/:yard-docs-38c800.svg)](https://rubydoc.info/gems/test_tube)
3
+ [![Version](https://img.shields.io/github/v/tag/fixrb/test_tube?label=Version&logo=github)](https://github.com/fixrb/test_tube/releases)
4
+ [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/test_tube/main)
5
+ [![CI](https://github.com/fixrb/test_tube/workflows/CI/badge.svg?branch=main)](https://github.com/fixrb/test_tube/actions?query=workflow%3Aci+branch%3Amain)
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
+ [![License](https://img.shields.io/github/license/fixrb/test_tube?label=License&logo=github)](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
- # -> { "101010".to_i(2) },
24
- # isolation: false,
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(input, isolation:, matcher:, negate:)
31
- Invoker.new(input, isolation: isolation, matcher: matcher, negate: negate)
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
- # "101010".to_i(2),
49
- # matcher: BeTheAnswer.new,
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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  module TestTube
4
4
  # Abstract class representing the state of an experiment.
5
+ #
6
+ # @api private
5
7
  class Base
6
8
  # Expectation's actual value.
7
9
  #
@@ -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
- def initialize(input, isolation:, matcher:, negate:)
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
@@ -4,6 +4,8 @@ require_relative "base"
4
4
 
5
5
  module TestTube
6
6
  # Evaluate an actual value passed in parameter.
7
+ #
8
+ # @api private
7
9
  class Passer < Base
8
10
  # Class initializer.
9
11
  #
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.1.0
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-06-20 00:00:00.000000000 Z
11
+ date: 2021-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: defi