Class: Matchi::Change::To
- Inherits:
-
Object
- Object
- Matchi::Change::To
- Defined in:
- lib/matchi/change/to.rb
Overview
*Change to* matcher.
Instance Method Summary collapse
-
#initialize(expected, &state) ⇒ To
constructor
Initialize the matcher with an object and a block.
-
#match? ⇒ Boolean
Boolean comparison on the expected change by comparing the value before and after the code execution.
-
#to_s ⇒ String
Returns a string representing the matcher.
Constructor Details
#initialize(expected, &state) ⇒ To
Initialize the matcher with an object and a block.
19 20 21 22 23 24 |
# File 'lib/matchi/change/to.rb', line 19 def initialize(expected, &state) raise ::ArgumentError, "a block must be provided" unless block_given? @expected = expected @state = state end |
Instance Method Details
#match? ⇒ Boolean
Boolean comparison on the expected change by comparing the value before and after the code execution.
41 42 43 44 45 46 47 48 |
# File 'lib/matchi/change/to.rb', line 41 def match? raise ::ArgumentError, "a block must be provided" unless block_given? yield value_after = @state.call @expected == value_after end |
#to_s ⇒ String
Returns a string representing the matcher.
53 54 55 |
# File 'lib/matchi/change/to.rb', line 53 def to_s "change to #{@expected.inspect}" end |