Class: ParameterizedTesting::Input

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

Overview

Input represents a single test case for a parameterized test.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index:, location:, initializer:, description:) ⇒ Input

Returns a new instance of Input.



15
16
17
18
19
20
# File 'lib/parameterized_testing/input.rb', line 15

def initialize(index:, location:, initializer:, description:)
  @index = index
  @location = location
  @initializer = initializer
  @description = description
end

Instance Attribute Details

#descriptionString? (readonly)

Returns description of the input.

Returns:

  • (String, nil)

    description of the input



13
14
15
# File 'lib/parameterized_testing/input.rb', line 13

def description
  @description
end

#indexInteger (readonly)

Returns index of the input.

Returns:

  • (Integer)

    index of the input



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

def index
  @index
end

#initializerProc (readonly)

Returns the block to compute the value of this input.

Returns:

  • (Proc)

    the block to compute the value of this input



11
12
13
# File 'lib/parameterized_testing/input.rb', line 11

def initializer
  @initializer
end

#locationThread::Backtrace::Location (readonly)

Returns the location of the input { ... } block.

Returns:

  • (Thread::Backtrace::Location)

    the location of the input { ... } block



9
10
11
# File 'lib/parameterized_testing/input.rb', line 9

def location
  @location
end

Class Method Details

.collectArray<Input>

Collects all input { ... } in a block. It is important to notice that this method collects inputs by actually #instance_executing the block in a dedicated context, in order to get the line number of input. In this context, all other method calls are ignored.

Returns:



33
34
35
36
37
# File 'lib/parameterized_testing/input.rb', line 33

def self.collect(&)
  inputs = []
  Collector.new(inputs).instance_exec(&)
  inputs
end

Instance Method Details

#labelString

Returns a human-readable label string.

Returns:

  • (String)


24
25
26
# File 'lib/parameterized_testing/input.rb', line 24

def label
  "#{@description || "input[#{index}]"} (at line #{location.lineno})"
end