Class: ParameterizedTesting::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/parameterized_testing/signature.rb

Overview

Signature represents the signature that each Input in the parameterized test must satisfy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*params) ⇒ Signature

Returns a new instance of Signature.

Raises:

  • (TypeError)


9
10
11
12
13
14
# File 'lib/parameterized_testing/signature.rb', line 9

def initialize(*params)
  raise TypeError, "parameter name must be a symbol" if params.any? { !_1.is_a?(Symbol) }
  raise ArgumentError, "parameter names must be unique" if params.uniq.size != params.size

  @params = params
end

Instance Attribute Details

#paramsArray<Symbol> (readonly)

Returns names of the parameters.

Returns:

  • (Array<Symbol>)

    names of the parameters



7
8
9
# File 'lib/parameterized_testing/signature.rb', line 7

def params
  @params
end

Instance Method Details

#map(value) ⇒ Hash{Symbol => Object}?

Compute the mapping between parameters and values, or nil if map fails.

Parameters:

  • value (Object)

    An array with the same number of elements as the number of parameters, or a hash with each parameter name as a key. For other objects, map will fail.

Returns:

  • (Hash{Symbol => Object}, nil)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/parameterized_testing/signature.rb', line 25

def map(value)
  case value
  when Array
    return if value.size != params.size

    params.zip(value).to_h
  when Hash
    return if value.size != params.size || params.any? { !value.key?(_1) }

    value
  end
end

#temporary_variable_nameSymbol

Returns a symbol for temporary variables that are unique for each signature.

Returns:

  • (Symbol)

    a symbol for temporary variables that are unique for each signature



17
18
19
# File 'lib/parameterized_testing/signature.rb', line 17

def temporary_variable_name
  @temporary_variable_name ||= :"_input_#{params.join("_")}"
end