test_tube 1.0.0.beta0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e928758abf1d784bdf93e7d9128f3fc69a48bdcf532769a9f5250a0a09338ac
4
+ data.tar.gz: ba835fe5031d9af8fc124f6cb012008923d3080a8de953a0a31c348f693102cd
5
+ SHA512:
6
+ metadata.gz: 132fe5f45b2b7317667e868aed913d856caa86fa302a6f954ef3a5ca7c11ac0c8047125df550196999208340f731cb4fc1d296974b465e6bad66afe4c4c2c37f
7
+ data.tar.gz: e2d7535593db0618488764c7d1d42ec6902f75912c79f2bd010c7f627722d9ff5c3fb8b8e70ef30a5b6a807a104b65ff0c688dea4c76e8b8f856afb3f002bfab
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Cyril Kato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Test Tube
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)
6
+
7
+ > A test tube to conduct software experiments 🧪
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "test_tube"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```sh
20
+ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```sh
26
+ gem install test_tube
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Let's experiment the answer to the Ultimate Question of Life, the Universe, and
32
+ Everything:
33
+
34
+ ```ruby
35
+ class BeTheAnswer
36
+ def matches?
37
+ 42.equal?(yield)
38
+ end
39
+ end
40
+
41
+ tt = TestTube.content(
42
+ -> { "101010".to_i(2) },
43
+ isolation: false,
44
+ matcher: BeTheAnswer.new,
45
+ negate: false
46
+ )
47
+ # => #<TestTube::Content:0x00007fb3b328b248 @actual=42, @got=true, @error=nil>
48
+
49
+ tt.actual # => 42
50
+ tt.error # => nil
51
+ tt.got # => true
52
+ ```
53
+
54
+ ## Contact
55
+
56
+ * Source code: https://github.com/fixrb/test_tube
57
+
58
+ ## Versioning
59
+
60
+ __Test Tube__ follows [Semantic Versioning 2.0](https://semver.org/).
61
+
62
+ ## License
63
+
64
+ The [gem](https://rubygems.org/gems/test_tube) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
65
+
66
+ ***
67
+
68
+ <p>
69
+ This project is sponsored by:<br />
70
+ <a href="https://sashite.com/"><img
71
+ src="https://github.com/fixrb/test_tube/raw/main/img/sashite.png"
72
+ alt="Sashite" /></a>
73
+ </p>
data/lib/test_tube.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative File.join("test_tube", "content")
4
+ require_relative File.join("test_tube", "liquid")
5
+
6
+ # Namespace for the TestTube library.
7
+ module TestTube
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
+ #
13
+ # @return [Content] A software experiment.
14
+ def self.content(input, isolation:, matcher:, negate:)
15
+ Content.new(input, isolation: isolation, matcher: matcher, negate: negate)
16
+ end
17
+
18
+ # @param input [#call] The callable object to test.
19
+ # @param matcher [#matches?] A matcher.
20
+ # @param negate [Boolean] Invert the matcher or not.
21
+ #
22
+ # @return [Content] A software experiment.
23
+ def self.liquid(input, matcher:, negate:)
24
+ Liquid.new(input, matcher: matcher, negate: negate)
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestTube
4
+ # The liquid class is great for values.
5
+ class Base
6
+ # @return [#object_id] The actual value.
7
+ attr_reader :actual
8
+
9
+ # @return [Exception, nil] The raised exception.
10
+ attr_reader :error
11
+
12
+ # @return [Boolean, nil] The test result.
13
+ attr_reader :got
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "defi"
4
+
5
+ require_relative "base"
6
+
7
+ module TestTube
8
+ # The content class is great for blocks.
9
+ class Content < Base
10
+ # Software experiments.
11
+ #
12
+ # rubocop:disable Lint/RescueException, Metrics/MethodLength
13
+ #
14
+ # @param input [#call] The callable object to test.
15
+ # @param isolation [Boolean] Compute in isolation or not.
16
+ # @param matcher [#matches?] A matcher.
17
+ # @param negate [Boolean] Invert the matcher or not.
18
+ def initialize(input, isolation:, matcher:, negate:)
19
+ super()
20
+
21
+ @got = negate ^ matcher.matches? do
22
+ value = if isolation
23
+ send_call.to!(input)
24
+ else
25
+ send_call.to(input)
26
+ end
27
+
28
+ @actual = value.object
29
+ value.call
30
+ end
31
+ rescue ::Exception => e
32
+ @actual = nil
33
+ @error = e
34
+ end
35
+ # rubocop:enable Lint/RescueException, Metrics/MethodLength
36
+
37
+ private
38
+
39
+ # @return [::Defi::Challenge] The challenge for the callable object.
40
+ #
41
+ # @see https://github.com/fixrb/defi/blob/v2.0.5/lib/defi/challenge.rb
42
+ def send_call
43
+ ::Defi.send(:call)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module TestTube
6
+ # The liquid class is great for values.
7
+ class Liquid < Base
8
+ # Software experiments.
9
+ #
10
+ # @param input [#object_id] An actual value to test.
11
+ # @param matcher [#matches?] A matcher.
12
+ # @param negate [Boolean] Invert the matcher or not.
13
+ def initialize(input, matcher:, negate:)
14
+ super()
15
+
16
+ @actual = input
17
+ @got = negate ^ matcher.matches? { @actual }
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_tube
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Kato
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: defi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.5
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: rake
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: rubocop-md
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-performance
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-rake
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-thread_safety
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: simplecov
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: yard
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
+ description: "A test tube to conduct software experiments \U0001F9EA"
154
+ email: contact@cyril.email
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE.md
160
+ - README.md
161
+ - lib/test_tube.rb
162
+ - lib/test_tube/base.rb
163
+ - lib/test_tube/content.rb
164
+ - lib/test_tube/liquid.rb
165
+ homepage: https://github.com/fixrb/test_tube
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: 2.7.0
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">"
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.1
183
+ requirements: []
184
+ rubygems_version: 3.1.6
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: "A test tube to conduct software experiments \U0001F9EA"
188
+ test_files: []