Class: Matchi::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/matchi/change.rb,
lib/matchi/change/by.rb,
lib/matchi/change/to.rb,
lib/matchi/change/from.rb,
lib/matchi/change/from/to.rb,
lib/matchi/change/by_at_most.rb,
lib/matchi/change/by_at_least.rb

Overview

Wraps the target of a change matcher.

Defined Under Namespace

Classes: By, ByAtLeast, ByAtMost, From, To

Instance Method Summary collapse

Constructor Details

#initialize(object, method, *args, **kwargs, &block) ⇒ Change

Initialize a wrapper of the change matcher with an object and the name of one of its methods.

Examples:

require "matchi/change"

Matchi::Change.new("foo", :to_s)

Parameters:

  • object (#object_id)

    An object.

  • method (Symbol)

    The name of a method.

  • args (Array)

    A list of arguments.

  • kwargs (Hash)

    A list of keyword arguments.


24
25
26
# File 'lib/matchi/change.rb', line 24

def initialize(object, method, *args, **kwargs, &block)
  @state = -> { object.send(method, *args, **kwargs, &block) }
end

Instance Method Details

#by(delta) ⇒ #matches?

Specifies the delta of the expected change.

Examples:

require "matchi/change"

object = []

change_wrapper = Matchi::Change.new(object, :length)
change_wrapper.by(1)

Parameters:

  • delta (#object_id)

    The delta of the expected change.

Returns:

  • (#matches?)

    A *change by* matcher.


75
76
77
# File 'lib/matchi/change.rb', line 75

def by(delta)
  By.new(delta, &@state)
end

#by_at_least(minimum_delta) ⇒ #matches?

Specifies a minimum delta of the expected change.

Examples:

require "matchi/change"

object = []

change_wrapper = Matchi::Change.new(object, :length)
change_wrapper.by_at_least(1)

Parameters:

  • minimum_delta (#object_id)

    The minimum delta of the expected change.

Returns:

  • (#matches?)

    A *change by at least* matcher.


41
42
43
# File 'lib/matchi/change.rb', line 41

def by_at_least(minimum_delta)
  ByAtLeast.new(minimum_delta, &@state)
end

#by_at_most(maximum_delta) ⇒ #matches?

Specifies a maximum delta of the expected change.

Examples:

require "matchi/change"

object = []

change_wrapper = Matchi::Change.new(object, :length)
change_wrapper.by_at_most(1)

Parameters:

  • maximum_delta (#object_id)

    The maximum delta of the expected change.

Returns:

  • (#matches?)

    A *change by at most* matcher.


58
59
60
# File 'lib/matchi/change.rb', line 58

def by_at_most(maximum_delta)
  ByAtMost.new(maximum_delta, &@state)
end

#from(old_value) ⇒ #matches?

Specifies the original value.

Examples:

require "matchi/change"

change_wrapper = Matchi::Change.new("foo", :to_s)
change_wrapper.from("foo")

Parameters:

  • old_value (#object_id)

    The original value.

Returns:

  • (#matches?)

    A *change from* wrapper.


90
91
92
# File 'lib/matchi/change.rb', line 90

def from(old_value)
  From.new(old_value, &@state)
end

#to(new_value) ⇒ #matches?

Specifies the new value to expect.

Examples:

require "matchi/change"

change_wrapper = Matchi::Change.new("foo", :to_s)
change_wrapper.to("FOO")

Parameters:

  • new_value (#object_id)

    The new value to expect.

Returns:

  • (#matches?)

    A *change to* matcher.


105
106
107
# File 'lib/matchi/change.rb', line 105

def to(new_value)
  To.new(new_value, &@state)
end