parameterized_testing 0.1.1 → 0.3.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: 1ae68ed889f8978f18434df681d55770938eca2ec6a68622daddcc623c110d0d
4
- data.tar.gz: be9768a8b3c3faaead709c2de45eea17aed72d8d5c56aca9e849ef1fb7d3e23f
3
+ metadata.gz: d2e0065076e770326c01f888a5f82b0a7cda3939e16a4e64824fd24a86d2c560
4
+ data.tar.gz: be46f52978f805296958da8e63514d860b6417c9e6cda5a0cb4f15ac85ff7c47
5
5
  SHA512:
6
- metadata.gz: d0aa5bae0c96de4f2e184ccf9e62f1df1b0aee661ad030aa72caa1814cad1fb1066a262e706e29d300c3e9350b2b6ec92c7cf19bb72eabd70bc0c5fca373ac59
7
- data.tar.gz: 2a091aa7e143f39ace374a1b1ce8c881284577449cda9737edd960b7763be98d4ce3534a3a66bc5eaa43dcc8aa4bd728dff6505d89ab7286baa654e1d23cc230
6
+ metadata.gz: cf153934ac5ce7fe4c8ff313df5c9719b10a4d373da59d38e861ce748594409f0d6cb2d7febfd0e3b62191176313081af6eb791b424d30865c0c7403fd43ea64
7
+ data.tar.gz: 0b817ca2c69ec215357e6a731b142df3c35e8b750703d592de85c47a67c8d0408d8c3f81ede96df4778d03e86d78d610bd3340f9d56284a7b479b83bede2ff73
@@ -1,28 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParameterizedTesting
4
- # `Input` represents a single test case for a parameterized test.
4
+ # {Input} represents a single test case for a parameterized test.
5
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:)
6
+ # @return [Integer] index of the input
7
+ attr_reader :index
8
+ # @return [Thread::Backtrace::Location] the location of the <code>input { ... }</code> block
9
+ attr_reader :location
10
+ # @return [Proc] the block to compute the value of this input
11
+ attr_reader :initializer
12
+ # @return [String, nil] description of the input
13
+ attr_reader :description
14
+
15
+ def initialize(index:, location:, initializer:, description:)
12
16
  @index = index
13
17
  @location = location
14
18
  @initializer = initializer
19
+ @description = description
15
20
  end
16
21
 
17
- # Gets a human-readable label string.
22
+ # Returns a human-readable label string.
18
23
  # @return [String]
19
24
  def label
20
- "input[#{index}] at line #{location.lineno}"
25
+ "#{@description || "input[#{index}]"} (at line #{location.lineno})"
21
26
  end
22
27
 
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.
28
+ # Collects all <code>input { ... }</code> in a block.
29
+ # It is important to notice that this method collects inputs by actually <code>#instance_exec</code>uting
30
+ # the block in a dedicated context, in order to get the line number of input.
26
31
  # In this context, all other method calls are ignored.
27
32
  # @return [Array<Input>]
28
33
  def self.collect(&)
@@ -37,11 +42,11 @@ module ParameterizedTesting
37
42
  @next_index = 0
38
43
  end
39
44
 
40
- def input(&initializer)
45
+ def input(description = nil, &initializer)
41
46
  index = @next_index
42
47
  @next_index += 1
43
48
  location = caller_locations(1, 1).first
44
- @inputs << Input.new(index:, location:, initializer:)
49
+ @inputs << Input.new(index:, location:, initializer:, description:)
45
50
  end
46
51
 
47
52
  def method_missing(_name, ...)
@@ -52,5 +57,6 @@ module ParameterizedTesting
52
57
  true
53
58
  end
54
59
  end
60
+ private_constant :Collector
55
61
  end
56
62
  end
@@ -1,25 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParameterizedTesting
4
- # `Signature` represents the signature that each `Input` in the parameterized test must satisfy.
4
+ # {Signature} represents the signature that each {Input} in the parameterized test must satisfy.
5
5
  class Signature
6
+ # @return [Array<Symbol>] names of the parameters
6
7
  attr_reader :params
7
8
 
8
- # @param params [Array<Symbol>]
9
9
  def initialize(*params)
10
- raise ArgumentError, "parameter name must be a symbol" if params.any? { !_1.is_a?(Symbol) }
10
+ raise TypeError, "parameter name must be a symbol" if params.any? { !_1.is_a?(Symbol) }
11
11
  raise ArgumentError, "parameter names must be unique" if params.uniq.size != params.size
12
12
 
13
13
  @params = params
14
14
  end
15
15
 
16
- # @return [Symbol]
16
+ # @return [Symbol] a symbol for temporary variables that are unique for each signature
17
17
  def temporary_variable_name
18
18
  @temporary_variable_name ||= :"_input_#{params.join("_")}"
19
19
  end
20
20
 
21
- # @param value [Object]
22
- # @return [Hash<Symbol, Object>, nil] Mapping of parameters and values, or `nil` if mapping fails
21
+ # Compute the mapping between parameters and values, or <code>nil</code> if map fails.
22
+ # @param value [Object] An array with the same number of elements as the number of parameters,
23
+ # or a hash with each parameter name as a key. For other objects, map will fail.
24
+ # @return [Hash{Symbol => Object}, nil]
23
25
  def map(value)
24
26
  case value
25
27
  when Array
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParameterizedTesting
4
- VERSION = "0.1.1"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameterized_testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yubrot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
11
+ date: 2024-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parameterized testing utility
14
14
  email:
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
- rubygems_version: 3.5.9
49
+ rubygems_version: 3.5.11
50
50
  signing_key:
51
51
  specification_version: 4
52
52
  summary: Parameterized testing utility