lib/matchi/change/by.rb in matchi-3.0.0 vs lib/matchi/change/by.rb in matchi-3.1.0
- old
+ new
@@ -2,10 +2,13 @@
module Matchi
class Change
# *Change by* matcher.
class By
+ # @return [#object_id] An expected delta.
+ attr_reader :expected
+
# Initialize the matcher with an object and a block.
#
# @example
# require "matchi/change/by"
#
@@ -28,31 +31,33 @@
# require "matchi/change/by"
#
# object = []
#
# matcher = Matchi::Change::By.new(1) { object.length }
+ #
+ # matcher.expected # => 1
# matcher.matches? { object << "foo" } # => true
#
# @yieldreturn [#object_id] The block of code to execute.
#
# @return [Boolean] Comparison between the value before and after the
# code execution.
- def matches?(*, **)
+ def matches?
value_before = @state.call
yield
value_after = @state.call
- @expected == (value_after - value_before)
+ expected == (value_after - value_before)
end
# A string containing a human-readable representation of the matcher.
def inspect
- "#{self.class}(#{@expected.inspect})"
+ "#{self.class}(#{expected.inspect})"
end
# Returns a string representing the matcher.
def to_s
- "change by #{@expected.inspect}"
+ "change by #{expected.inspect}"
end
end
end
end