class RSpec::Matchers::BuiltIn::ChangeDetails
@private Encapsulates the details of the before/after values.
Attributes
actual_after[R]
actual_before[R]
Public Class Methods
new(matcher_name, receiver=nil, message=nil, &block)
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 318 def initialize(matcher_name, 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 @matcher_name = matcher_name @receiver = receiver @message = message @value_proc = block end
Public Instance Methods
actual_delta()
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 355 def actual_delta @actual_after - @actual_before end
changed?()
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 351 def changed? @actual_before != @actual_after end
perform_change(event_proc)
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 345 def perform_change(event_proc) @actual_before = evaluate_value_proc event_proc.call @actual_after = evaluate_value_proc end
value_representation()
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 334 def value_representation @value_representation ||= if @message "##{@message}" elsif (value_block_snippet = extract_value_block_snippet) "`#{value_block_snippet}`" else 'result' end end
Private Instance Methods
evaluate_value_proc()
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 361 def evaluate_value_proc value_proc = @value_proc || lambda { @receiver.__send__(@message) } 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
extract_value_block_snippet()
click to toggle source
# File lib/rspec/matchers/built_in/change.rb, line 375 def extract_value_block_snippet return nil unless @value_proc Expectations::BlockSnippetExtractor.try_extracting_single_line_body_of(@value_proc, @matcher_name) end