fail_with(message, expected=nil, target=nil)
public
Show source
def fail_with(message, expected=nil, target=nil)
if message.nil?
raise ArgumentError, "Failure message is nil. Does your matcher define the " +
"appropriate failure_message_for_* method to return a string?"
end
if (Array === message) & (message.length == 3)
::Spec.warn("\n*****************************************************************\nDEPRECATION WARNING: you are using deprecated behaviour that will\nbe removed from a future version of RSpec.\n\n* Support for matchers that return arrays from failure message\nmethods is deprecated.\n* Instead, the matcher should return a string, and expose methods\nfor the expected() and actual() values.\n*****************************************************************\n"
)
message, expected, target = message[0], message[1], message[2]
end
unless (differ.nil? || expected.nil? || target.nil?)
if expected.is_a?(String)
message << "\n\n Diff:" << self.differ.diff_as_string(target.to_s, expected)
elsif expected.is_a?(Hash) && target.is_a?(Hash)
message << "\n\n Diff:" << self.differ.diff_as_hash(target, expected)
elsif !target.is_a?(Proc)
message << "\n\n Diff:" << self.differ.diff_as_object(target, expected)
end
end
Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
end