Class: Mocktail::Matchers::Captor

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mocktail/matchers/captor.rb,
lib/mocktail/sorbet/mocktail/matchers/captor.rb

Overview

Captors are conceptually complex implementations, but with a simple usage/purpose: They are values the user can create and hold onto that will return a matcher and then “capture” the value made by the real call, for later analysis & assertion.

Unlike other matchers, these don’t make any useful sense for stubbing, but are very useful when asserting complication call verifications

The fact the user will need the reference outside the verification call is why this is a top-level method on Mocktail, and not included in the |m| block arg to stubs/verify

See Mockito, which is the earliest implementation I know of: javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Captor.html

Defined Under Namespace

Classes: Capture

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCaptor

Returns a new instance of Captor.



53
54
55
# File 'lib/mocktail/matchers/captor.rb', line 53

def initialize
  @capture = Capture.new
end

Instance Attribute Details

#captureObject (readonly)

This T.untyped is intentional. Even though a Capture is surely returned, in order for a verification demonstration to pass its own type check, it needs to think it’s being returned whatever parameter is expected



51
52
53
# File 'lib/mocktail/matchers/captor.rb', line 51

def capture
  @capture
end

Instance Method Details

#captured?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/mocktail/matchers/captor.rb', line 57

def captured?
  @capture.captured?
end

#valueObject



61
62
63
# File 'lib/mocktail/matchers/captor.rb', line 61

def value
  @capture.value
end