Class: Matchi::Change::From
- Inherits:
-
Object
- Object
- Matchi::Change::From
- Defined in:
- lib/matchi/change/from.rb,
lib/matchi/change/from/to.rb
Overview
Initial state wrapper for building a value transition matcher.
This class acts as a wrapper that captures the expected initial state and provides methods to build a complete transition matcher. When combined with the ‘to’ method, it creates a matcher that verifies both the starting and ending values of a change operation. This is useful when you need to ensure not only the final state but also the initial state of a value.
Defined Under Namespace
Classes: To
Instance Method Summary collapse
-
#initialize(expected, &state) ⇒ From
constructor
Initialize the wrapper with an object and a block.
-
#to(expected_new_value) ⇒ #match?
Specifies the new value to expect.
Constructor Details
#initialize(expected, &state) ⇒ From
Initialize the wrapper with an object and a block.
46 47 48 49 50 51 |
# File 'lib/matchi/change/from.rb', line 46 def initialize(expected, &state) raise ::ArgumentError, "a block must be provided" unless block_given? @expected = expected @state = state end |
Instance Method Details
#to(expected_new_value) ⇒ #match?
Specifies the new value to expect.
Creates a complete transition matcher that verifies both the initial and final states of a value. The matcher will succeed only if the value starts at the expected initial state and changes to the specified new value after executing the test block.
71 72 73 |
# File 'lib/matchi/change/from.rb', line 71 def to(expected_new_value) To.new(@expected, expected_new_value, &@state) end |