class RSpec::Matchers::BuiltIn::SpecificValuesChange

@api private Base class for specifying a change from and/or to specific values.

Constants

MATCH_ANYTHING

@private

Public Class Methods

new(change_details, from, to) click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 185
def initialize(change_details, from, to)
  @change_details  = change_details
  @expected_before = from
  @expected_after  = to
end

Public Instance Methods

description() click to toggle source

@private

# File lib/rspec/matchers/built_in/change.rb, line 197
def description
  "change #{@change_details.value_representation} #{change_description}"
end
failure_message() click to toggle source

@private

# File lib/rspec/matchers/built_in/change.rb, line 202
def failure_message
  return not_given_a_block_failure unless Proc === @event_proc
  return before_value_failure      unless @matches_before
  return did_not_change_failure    unless @change_details.changed?
  after_value_failure
end
matches?(event_proc) click to toggle source

@private

# File lib/rspec/matchers/built_in/change.rb, line 192
def matches?(event_proc)
  perform_change(event_proc) && @change_details.changed? && @matches_before && matches_after?
end
supports_block_expectations?() click to toggle source

@private

# File lib/rspec/matchers/built_in/change.rb, line 210
def supports_block_expectations?
  true
end
supports_value_expectations?() click to toggle source

@private

# File lib/rspec/matchers/built_in/change.rb, line 215
def supports_value_expectations?
  false
end

Private Instance Methods

after_value_failure() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 244
def after_value_failure
  "expected #{@change_details.value_representation} " \
  "to have changed to #{description_of @expected_after}, " \
  "but is now #{description_of @change_details.actual_after}"
end
before_value_failure() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 238
def before_value_failure
  "expected #{@change_details.value_representation} " \
  "to have initially been #{description_of @expected_before}, " \
  "but was #{@actual_before_description}"
end
did_change_failure() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 255
def did_change_failure
  "expected #{@change_details.value_representation} not to have changed, but " \
  "did change from #{@actual_before_description} " \
  "to #{description_of @change_details.actual_after}"
end
did_not_change_failure() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 250
def did_not_change_failure
  "expected #{@change_details.value_representation} " \
  "to have changed #{change_description}, but did not change"
end
matches_after?() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 234
def matches_after?
  values_match?(@expected_after, @change_details.actual_after)
end
not_given_a_block_failure() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 261
def not_given_a_block_failure
  "expected #{@change_details.value_representation} to have changed " \
  "#{change_description}, but was not given a block"
end
perform_change(event_proc) click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 221
def perform_change(event_proc)
  @event_proc = event_proc
  @change_details.perform_change(event_proc) do |actual_before|
    # pre-compute values derived from the `before` value before the
    # mutation is applied, in case the specified mutation is mutation
    # of a single object (rather than a changing what object a method
    # returns). We need to cache these values before the `before` value
    # they are based on potentially gets mutated.
    @matches_before = values_match?(@expected_before, actual_before)
    @actual_before_description = description_of(actual_before)
  end
end