test_tube 2.1.3 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27985c322404e783924126aac5671af89d2852979dc9cf10deae5ca2821dada7
4
- data.tar.gz: a383583d7360975bf5f1e98a0271a566be78f97a293bd8d4cec7437c6e315c4c
3
+ metadata.gz: a511d50711ff51b4ca13b4e6228f2e0d88dbfcb04b89ccb37619b1b2a3248073
4
+ data.tar.gz: 2eac86be8bdfc2733ed2fb11aa90bd4177c548e5319765549c04dd458dfd56e5
5
5
  SHA512:
6
- metadata.gz: e71d511063d6f166ddce31450773f149b679ba21f95a70ffad6f92e527c4819fe44d177d676e1b774d5478f71f31ac61cd6c971d4ad1445e89a3dcab2532d59e
7
- data.tar.gz: bf01ae4ec42fdf5075663b61b91933456bbce5a572c5582faa7c06d35cb857a90a23e18cf8cd4cf3109d1c1e4dbf4b49cd420ec0dbcb92c3517c8c5feaa360a9
6
+ metadata.gz: 80032c8cfacc36e4e49b48ba74dfbf0f0f82d8198fc2c40d66e42046d331312eb15a05bd11db0aa92fb748d3e9c6856731d3643bb543d0a90d4d725d43de9fd5
7
+ data.tar.gz: 4948793c91f4f2842af624a91d791875542c0eca3855780d266d88bc2c9153cb14fea30daf4e3f4afcd0671e439a80bb006ffba760b9669a93e4c577e8c9e345
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Cyril Kato
3
+ Copyright (c) 2021-2024 Cyril Kato
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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/releases)
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
- [![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)
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 matches?
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(isolate: false, matcher: BeTheAnswer.new, negate: false, &block_of_code)
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
- [__Matchi__ project](https://github.com/fixrb/matchi/).
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
- <p>
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/)
@@ -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, Metrics/MethodLength
12
+ # rubocop:disable Lint/RescueException
13
13
 
14
14
  # Class initializer.
15
15
  #
16
- # @param isolate [Boolean] Compute in a subprocess.
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(isolate:, matcher:, negate:, &input)
19
+ def initialize(matcher:, negate:, &input)
21
20
  super()
22
21
 
23
- @got = negate ^ matcher.matches? do
24
- value = if isolate
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, Metrics/MethodLength
32
+ # rubocop:enable Lint/RescueException
39
33
 
40
34
  private
41
35
 
42
- # @return [::Defi::Challenge] The challenge for the callable object.
36
+ # @return [::Defi::Method] The challenge for the callable object.
43
37
  #
44
- # @see https://github.com/fixrb/defi/blob/v2.0.5/lib/defi/challenge.rb
38
+ # @see https://github.com/fixrb/defi/blob/v3.0.0/lib/defi/method.rb
45
39
  def send_call
46
- ::Defi.send(:call)
40
+ ::Defi::Method.new(:call)
47
41
  end
48
42
  end
49
43
  end
@@ -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 [#matches?] A 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.matches? { input }
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
- # @param isolate [Boolean] Compute in a subprocess.
11
- # @param matcher [#matches?] A matcher.
12
- # @param negate [Boolean] Invert the matcher or not.
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 matches?
18
+ # def match?
20
19
  # 42.equal?(yield)
21
20
  # end
22
21
  # end
23
22
  #
24
- # TestTube.invoke(isolate: false, matcher: BeTheAnswer.new, negate: false) do
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(isolate:, matcher:, negate:, &input)
30
- Invoker.new(isolate: isolate, matcher: matcher, negate: negate, &input)
27
+ # @return [TestTube::Invoker] A software experiment.
28
+ def self.invoke(...)
29
+ Invoker.new(...)
31
30
  end
32
31
 
33
- # @param input [#object_id] The actual value to test.
34
- # @param matcher [#matches?] A matcher.
35
- # @param negate [Boolean] Invert the matcher or not.
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 matches?
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(input, matcher:, negate:)
53
- Passer.new(input, matcher: matcher, negate: negate)
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: 2.1.3
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: 2021-08-04 00:00:00.000000000 Z
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: 2.0.6
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: 2.0.6
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
- post_install_message:
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.7.0
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.1.6
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: []