Sha256: 8f5749b632ead3c1d06cf31c52a5af1445d83bf04213fda6821492417f74541c
Contents?: true
Size: 1.4 KB
Versions: 9
Compression:
Stored size: 1.4 KB
Contents
module RSpec module Expectations class << self def differ @differ ||= Differ.new end # raises a RSpec::Expectations::ExpectationNotMetError with message # # When a differ has been assigned and fail_with is passed # <code>expected</code> and <code>actual</code>, passes them # to the differ to append a diff message to the failure message. def fail_with(message, expected=nil, actual=nil) # :nodoc: if !message raise ArgumentError, "Failure message is nil. Does your matcher define the " + "appropriate failure_message_for_* method to return a string?" end if actual && expected if all_strings?(actual, expected) if any_multiline_strings?(actual, expected) message << "\nDiff:" << self.differ.diff_as_string(actual, expected) end elsif no_procs?(actual, expected) message << "\nDiff:" << self.differ.diff_as_object(actual, expected) end end raise(RSpec::Expectations::ExpectationNotMetError.new(message)) end private def no_procs?(*args) args.none? {|a| Proc === a} end def all_strings?(*args) args.all? {|a| String === a} end def any_multiline_strings?(*args) all_strings?(*args) && args.any? {|a| a =~ /\n/} end end end end
Version data entries
9 entries across 9 versions & 1 rubygems