Sha256: 66f03107fde69ab929d78155237a1c45a23d24c512d3379669c2329b990db103

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require_relative File.join("from", "to")

module Matchi
  class Change
    # *Change from to* wrapper.
    class From
      # Initialize the wrapper with an object and a block.
      #
      # @example
      #   require "matchi/change/from"
      #
      #   object = "foo"
      #
      #   Matchi::Change::From.new("foo") { object.to_s }
      #
      # @param expected [#object_id]  An expected initial value.
      # @param state    [Proc]        A block of code to execute to get the
      #   state of the object.
      def initialize(expected, &state)
        @expected = expected
        @state    = state
      end

      # Specifies the new value to expect.
      #
      # @example
      #   require "matchi/change/from"
      #
      #   object = "foo"
      #
      #   change_from_wrapper = Matchi::Change::From.new("foo") { object.to_s }
      #   change_from_wrapper.to("FOO")
      #
      # @param expected_new_value [#object_id] The new value to expect.
      #
      # @return [#matches?] A *change from to* matcher.
      def to(expected_new_value)
        To.new(@expected, expected_new_value, &@state)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
matchi-3.3.2 lib/matchi/change/from.rb
matchi-3.3.1 lib/matchi/change/from.rb
matchi-3.3.0 lib/matchi/change/from.rb
matchi-3.2.0 lib/matchi/change/from.rb
matchi-3.1.1 lib/matchi/change/from.rb
matchi-3.1.0 lib/matchi/change/from.rb