Class: TestTube::Invoker

Inherits:
Base
  • Object
show all
Defined in:
lib/test_tube/invoker.rb

Overview

Evaluate an actual value invoking it with #call method.

Instance Attribute Summary

Attributes inherited from Base

#actual, #error, #got

Instance Method Summary collapse

Methods inherited from Base

#inspect

Constructor Details

#initialize(input, isolation:, matcher:, negate:) ⇒ Invoker

Class initializer.

rubocop:disable Lint/RescueException, Metrics/MethodLength

Parameters:

  • input (#call)

    The callable object to test.

  • isolation (Boolean)

    Compute in isolation or not.

  • matcher (#matches?)

    A matcher.

  • negate (Boolean)

    Invert the matcher or not.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/test_tube/invoker.rb', line 18

def initialize(input, isolation:, matcher:, negate:)
  super()

  @got = negate ^ matcher.matches? do
    value = if isolation
              send_call.to!(input)
            else
              send_call.to(input)
            end

    @actual = value.object
    value.call
  end
rescue ::Exception => e
  @actual = nil
  @error  = e
end