class Matchi::Change
Wraps the target of a change matcher.
Public Class Methods
Initialize a wrapper of the change matcher with an object and the name of one of its methods.
@example
require "matchi/change" Matchi::Change.new("foo", :to_s)
@param object [#object_id] An object. @param method [Symbol] The name of a method. @param args [Array] A list of arguments. @param kwargs [Hash] A list of keyword arguments.
# File lib/matchi/change.rb, line 24 def initialize(object, method, *args, **kwargs, &block) @state = -> { object.send(method, *args, **kwargs, &block) } end
Public Instance Methods
Specifies the delta of the expected change.
@example
require "matchi/change" object = [] change_wrapper = Matchi::Change.new(object, :length) change_wrapper.by(1)
@param delta [#object_id] The delta of the expected change.
@return [#matches?] A *change by* matcher.
# File lib/matchi/change.rb, line 75 def by(delta) By.new(delta, &@state) end
Specifies a minimum delta of the expected change.
@example
require "matchi/change" object = [] change_wrapper = Matchi::Change.new(object, :length) change_wrapper.by_at_least(1)
@param minimum_delta [#object_id] The minimum delta of the expected change.
@return [#matches?] A *change by at least* matcher.
# File lib/matchi/change.rb, line 41 def by_at_least(minimum_delta) ByAtLeast.new(minimum_delta, &@state) end
Specifies a maximum delta of the expected change.
@example
require "matchi/change" object = [] change_wrapper = Matchi::Change.new(object, :length) change_wrapper.by_at_most(1)
@param maximum_delta [#object_id] The maximum delta of the expected change.
@return [#matches?] A *change by at most* matcher.
# File lib/matchi/change.rb, line 58 def by_at_most(maximum_delta) ByAtMost.new(maximum_delta, &@state) end
Specifies the original value.
@example
require "matchi/change" change_wrapper = Matchi::Change.new("foo", :to_s) change_wrapper.from("foo")
@param old_value [#object_id] The original value.
@return [#matches?] A *change from* wrapper.
# File lib/matchi/change.rb, line 90 def from(old_value) From.new(old_value, &@state) end
Specifies the new value to expect.
@example
require "matchi/change" change_wrapper = Matchi::Change.new("foo", :to_s) change_wrapper.to("FOO")
@param new_value [#object_id] The new value to expect.
@return [#matches?] A *change to* matcher.
# File lib/matchi/change.rb, line 105 def to(new_value) To.new(new_value, &@state) end