class Matchi::Change::ByAtMost
*Change by at most* matcher.
Attributes
expected[R]
@return [#object_id] An expected delta.
Public Class Methods
new(expected, &state)
click to toggle source
Initialize the matcher with an object and a block.
@example
require "matchi/change/by_at_most" object = [] Matchi::Change::ByAtMost.new(1) { object.length }
@param expected [#object_id] An expected delta. @param state [Proc] A block of code to execute to get the
state of the object.
# File lib/matchi/change/by_at_most.rb, line 22 def initialize(expected, &state) @expected = expected @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/by_at_most.rb, line 53 def inspect "#{self.class}(#{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/by_at_most" object = [] matcher = Matchi::Change::ByAtMost.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.
# File lib/matchi/change/by_at_most.rb, line 44 def matches? value_before = @state.call yield value_after = @state.call expected >= (value_after - value_before) end
to_s()
click to toggle source
Returns a string representing the matcher.
# File lib/matchi/change/by_at_most.rb, line 58 def to_s "change by at most #{expected.inspect}" end