parameterized_testing 0.1.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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +9 -0
- data/lib/parameterized_testing/input.rb +56 -0
- data/lib/parameterized_testing/signature.rb +36 -0
- data/lib/parameterized_testing/version.rb +5 -0
- data/lib/parameterized_testing.rb +5 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14c8bc38363f24be990956aa7017b05592609391655de5a7381275f75119d007
|
4
|
+
data.tar.gz: 94039aceda855763d54907825e5f6e5b9dce67aff2a35f576f9ce0d515988e9b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 411ddb4b32aa80e42e7183267a9b0484b149f1cc5908eac3c1bba2d33bc346ecd57a44b2eb0dfb3e01b570d1e9113483b51d95ee04cc577cbba631f0bfe8bb2a
|
7
|
+
data.tar.gz: b49142f3ffe34ab8fffcea25cf5e8a8f5f22eab38a657949b6e9313e963ecdd64e812b5ce93d4cba59a313b1902f922966846437947b5422c8055547d37cf6ce
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 yubrot
|
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,9 @@
|
|
1
|
+
# ParameterizedTesting
|
2
|
+
|
3
|
+
Parameterized testing utility.
|
4
|
+
|
5
|
+
Basically, this gem is used through [`parameterized_testing-rspec`](https://github.com/yubrot/ruby_parameterized_testing/tree/main/gems/parameterized_testing-rspec), etc. See [the repository root documentation](https://github.com/yubrot/ruby_parameterized_testing).
|
6
|
+
|
7
|
+
## License
|
8
|
+
|
9
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ParameterizedTesting
|
4
|
+
# `Input` represents a single test case for a parameterized test.
|
5
|
+
class Input
|
6
|
+
attr_reader :index, :location, :initializer
|
7
|
+
|
8
|
+
# @param index [Integer]
|
9
|
+
# @param location [Thread::Backtrace::Location]
|
10
|
+
# @param initializer [Proc]
|
11
|
+
def initialize(index:, location:, initializer:)
|
12
|
+
@index = index
|
13
|
+
@location = location
|
14
|
+
@initializer = initializer
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets a human-readable label string.
|
18
|
+
# @return [String]
|
19
|
+
def label
|
20
|
+
"input[#{index}] at line #{location.lineno}"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Collects all `input { ... }` in a block.
|
24
|
+
# It is important to notice that `#parameterized` collects inputs by actually `instance_exec`uting
|
25
|
+
# the block in a dedicated context in order to get the line number of input.
|
26
|
+
# In this context, all other method calls are ignored.
|
27
|
+
# @return [Array<Input>]
|
28
|
+
def self.collect(&)
|
29
|
+
inputs = []
|
30
|
+
Collector.new(inputs).instance_exec(&)
|
31
|
+
inputs
|
32
|
+
end
|
33
|
+
|
34
|
+
class Collector # :nodoc:
|
35
|
+
def initialize(inputs)
|
36
|
+
@inputs = inputs
|
37
|
+
@next_index = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def input(&initializer)
|
41
|
+
index = @next_index
|
42
|
+
@next_index += 1
|
43
|
+
location = caller_locations(1, 1).first
|
44
|
+
@inputs << Input.new(index:, location:, initializer:)
|
45
|
+
end
|
46
|
+
|
47
|
+
def method_missing(_name, ...)
|
48
|
+
# do nothing
|
49
|
+
end
|
50
|
+
|
51
|
+
def respond_to_missing?(_name, _include_private)
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ParameterizedTesting
|
4
|
+
# `Signature` represents the signature that each `Input` in the parameterized test must satisfy.
|
5
|
+
class Signature
|
6
|
+
attr_reader :params
|
7
|
+
|
8
|
+
# @param params [Array<Symbol>]
|
9
|
+
def initialize(*params)
|
10
|
+
raise ArgumentError, "parameter name must be a symbol" if params.any? { !_1.is_a?(Symbol) }
|
11
|
+
raise ArgumentError, "parameter names must be unique" if params.uniq.size != params.size
|
12
|
+
|
13
|
+
@params = params
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Symbol]
|
17
|
+
def temporary_variable_name
|
18
|
+
@temporary_variable_name ||= :"_input_#{params.join("_")}"
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param value [Object]
|
22
|
+
# @return [Hash<Symbol, Object>, nil] Mapping of parameters and values, or `nil` if mapping fails
|
23
|
+
def map(value)
|
24
|
+
case value
|
25
|
+
when Array
|
26
|
+
return if value.size != params.size
|
27
|
+
|
28
|
+
params.zip(value).to_h
|
29
|
+
when Hash
|
30
|
+
return if value.size != params.size || params.any? { !value.key?(_1) }
|
31
|
+
|
32
|
+
value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parameterized_testing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yubrot
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Parameterized testing utility
|
14
|
+
email:
|
15
|
+
- yubrot@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE.txt
|
21
|
+
- README.md
|
22
|
+
- lib/parameterized_testing.rb
|
23
|
+
- lib/parameterized_testing/input.rb
|
24
|
+
- lib/parameterized_testing/signature.rb
|
25
|
+
- lib/parameterized_testing/version.rb
|
26
|
+
homepage: https://github.com/yubrot/ruby_parameterized_testing
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata:
|
30
|
+
homepage_uri: https://github.com/yubrot/ruby_parameterized_testing
|
31
|
+
source_code_uri: https://github.com/yubrot/ruby_parameterized_testing
|
32
|
+
changelog_uri: https://github.com/yubrot/ruby_parameterized_testing/blob/main/CHANGELOG.md
|
33
|
+
rubygems_mfa_required: 'true'
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.1.0
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubygems_version: 3.5.9
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Parameterized testing utility
|
53
|
+
test_files: []
|