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 Attribute Summary collapse
-
#expected ⇒ #object_id
readonly
An expected new value.
Instance Method Summary collapse
-
#initialize(expected_init, expected_new_value, &state) ⇒ To
constructor
Initialize the matcher with two objects and a block.
-
#inspect ⇒ Object
A string containing a human-readable representation of the matcher.
-
#matches? ⇒ Boolean
Boolean comparison on the expected change by comparing the value before and after the code execution.
-
#to_s ⇒ Object
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.
24 25 26 27 28 |
# File 'lib/matchi/change/from/to.rb', line 24 def initialize(expected_init, expected_new_value, &state) @expected_init = expected_init @expected = expected_new_value @state = state end |
Instance Attribute Details
#expected ⇒ #object_id (readonly)
Returns An expected new value.
9 10 11 |
# File 'lib/matchi/change/from/to.rb', line 9 def expected @expected end |
Instance Method Details
#inspect ⇒ Object
A string containing a human-readable representation of the matcher.
58 59 60 |
# File 'lib/matchi/change/from/to.rb', line 58 def inspect "#{self.class}(#{@expected_init.inspect}, #{expected.inspect})" end |
#matches? ⇒ Boolean
Boolean comparison on the expected change by comparing the value before and after the code execution.
47 48 49 50 51 52 53 54 55 |
# File 'lib/matchi/change/from/to.rb', line 47 def matches? value_before = @state.call return false unless @expected_init == value_before yield value_after = @state.call expected == value_after end |
#to_s ⇒ Object
Returns a string representing the matcher.
63 64 65 |
# File 'lib/matchi/change/from/to.rb', line 63 def to_s "change from #{@expected_init.inspect} to #{expected.inspect}" end |