class RSpec::Matchers::BuiltIn::ChangeDetails

@private Encapsulates the details of the before/after values.

Attributes

actual_after[R]
actual_before[R]
message[R]

Public Class Methods

new(receiver=nil, message=nil, &block) click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 295
def initialize(receiver=nil, message=nil, &block)
  if receiver && !message
    raise(
      ArgumentError,
      "`change` requires either an object and message "                "(`change(obj, :msg)`) or a block (`change { }`). "                "You passed an object but no message."
    )
  end
  @message    = message ? "##{message}" : "result"
  @value_proc = block || lambda { receiver.__send__(message) }
end

Public Instance Methods

actual_delta() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 318
def actual_delta
  @actual_after - @actual_before
end
changed?() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 314
def changed?
  @actual_before != @actual_after
end
perform_change(event_proc) click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 308
def perform_change(event_proc)
  @actual_before = evaluate_value_proc
  event_proc.call
  @actual_after = evaluate_value_proc
end

Private Instance Methods

evaluate_value_proc() click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 324
def evaluate_value_proc
  case val = @value_proc.call
  when IO # enumerable, but we don't want to dup it.
    val
  when Enumerable, String
    val.dup
  else
    val
  end
end