class Matchi::Change::From::To

*Change from to* matcher.

Attributes

expected[R]

@return [#object_id] An expected new value.

Public Class Methods

new(expected_init, expected_new_value, &state) click to toggle source

Initialize the matcher with two objects and a block.

@example

require "matchi/change/from/to"

object = "foo"

Matchi::Change::From::To.new("foo", "FOO") { object.to_s }

@param expected_init [#object_id] An expected initial value. @param expected_new_value [#object_id] An expected new value. @param state [Proc] A block of code to execute to

get the state of the object.
# 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

Public Instance Methods

inspect() click to toggle source

A string containing a human-readable representation of the matcher.

# File lib/matchi/change/from/to.rb, line 58
def inspect
  "#{self.class}(#{@expected_init.inspect}, #{expected.inspect})"
end
matches?() { || ... } click to toggle source

Boolean comparison on the expected change by comparing the value before and after the code execution.

@example

require "matchi/change/from/to"

object = "foo"

matcher = Matchi::Change::From::To.new("foo", "FOO") { object.to_s }

matcher.expected                    # => "FOO"
matcher.matches? { object.upcase! } # => true

@yieldreturn [#object_id] The block of code to execute.

@return [Boolean] Comparison between the value before and after the

code execution.
# 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() click to toggle source

Returns a string representing the matcher.

# File lib/matchi/change/from/to.rb, line 63
def to_s
  "change from #{@expected_init.inspect} to #{expected.inspect}"
end