Class: TestTube::Passer Private

Inherits:
Experiment show all
Defined in:
lib/test_tube/passer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Evaluate an actual value passed in parameter. Unlike Invoker, this class handles direct value testing without executing a block, making it safer when you already have the value to test.

Examples:

Testing a direct value

TestTube.pass("101010".to_i(2),
  matcher: BeTheAnswer.new,
  negate: false
)

Instance Attribute Summary

Attributes inherited from Experiment

#actual, #error, #got

Instance Method Summary collapse

Methods inherited from Experiment

#inspect

Constructor Details

#initialize(input, matcher:, negate:) ⇒ Passer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Class initializer. Validates the matcher and negate parameter before performing the test. Since no code block is executed, this approach is immune to system-level exceptions that might occur during value computation.

Parameters:

  • input (Object)

    The actual value to test

  • matcher (#match?)

    The matcher to evaluate the result

  • negate (Boolean)

    Whether to invert the matcher result

Raises:

  • (ArgumentError)

    If the matcher doesn’t respond to match?



27
28
29
30
31
32
33
# File 'lib/test_tube/passer.rb', line 27

def initialize(input, matcher:, negate:)
  validate_matcher(matcher)
  validate_negate(negate)
  super()
  @actual = input
  @got = negate ^ matcher.match? { input }
end