Class: Matchi::Change::From::To
- Inherits:
-
Object
- Object
- Matchi::Change::From::To
- Defined in:
- lib/matchi/change/from/to.rb
Overview
*Change from to* matcher.
Instance Method Summary collapse
-
#initialize(expected_init, expected_new_value, &state) ⇒ To
constructor
Initialize the matcher with two objects 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_init, expected_new_value, &state) ⇒ To
Initialize the matcher with two objects and a block.
21 22 23 24 25 26 27 |
# File 'lib/matchi/change/from/to.rb', line 21 def initialize(expected_init, expected_new_value, &state) raise ::ArgumentError, "a block must be provided" unless block_given? @expected_init = expected_init @expected = expected_new_value @state = state end |
Instance Method Details
#match? ⇒ Boolean
Boolean comparison on the expected change by comparing the value before and after the code execution.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/matchi/change/from/to.rb', line 44 def match? raise ::ArgumentError, "a block must be provided" unless block_given? value_before = @state.call return false unless @expected_init == value_before yield value_after = @state.call @expected == value_after end |
#to_s ⇒ String
Returns a string representing the matcher.
59 60 61 |
# File 'lib/matchi/change/from/to.rb', line 59 def to_s "change from #{@expected_init.inspect} to #{@expected.inspect}" end |