Class: Matchi::Change::FromTo
- Inherits:
-
Object
- Object
- Matchi::Change::FromTo
- Defined in:
- lib/matchi/change/from_to.rb
Overview
Passes when the observed value is the old value before the block and the new value after it, both compared like Eq. The block is always evaluated; a wrong initial value is a failure of the expectation, like a wrong final value.
Instance Method Summary collapse
-
#initialize(old_value, new_value, &state) ⇒ FromTo
constructor
A new instance of FromTo.
- #match? ⇒ Boolean
- #to_s ⇒ String
Constructor Details
#initialize(old_value, new_value, &state) ⇒ FromTo
Returns a new instance of FromTo.
20 21 22 23 24 25 26 |
# File 'lib/matchi/change/from_to.rb', line 20 def initialize(old_value, new_value, &state) raise ::ArgumentError, "a block must be provided" unless block_given? @old_value = old_value @new_value = new_value @state = state end |
Instance Method Details
#match? ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/matchi/change/from_to.rb', line 31 def match? raise ::ArgumentError, "a block must be provided" unless block_given? initial = Eq.eql?(@old_value, @state.call) yield initial && Eq.eql?(@new_value, @state.call) end |
#to_s ⇒ String
41 42 43 |
# File 'lib/matchi/change/from_to.rb', line 41 def to_s "change from #{@old_value.inspect} to #{@new_value.inspect}" end |