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:) ⇒ Input

Returns a new instance of Input.



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

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

Instance Attribute Details

#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:



30
31
32
33
34
# File 'lib/parameterized_testing/input.rb', line 30

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

Instance Method Details

#labelString

Gets a human-readable label string.

Returns:

  • (String)


21
22
23
# File 'lib/parameterized_testing/input.rb', line 21

def label
  "input[#{index}] at line #{location.lineno}"
end