1 require 'spec/matchers'
2 require 'spec/expectations/errors'
3 require 'spec/expectations/extensions'
4 require 'spec/expectations/handler'
8 # Spec::Expectations lets you set expectations on your objects.
11 # team.should have(11).players_on_the_field
13 # == How Expectations work.
15 # Spec::Expectations adds two methods to Object:
18 # should_not(matcher=nil)
20 # Both methods take an optional Expression Matcher (See Spec::Matchers).
22 # When +should+ receives an Expression Matcher, it calls <tt>matches?(self)</tt>. If
23 # it returns +true+, the spec passes and execution continues. If it returns
24 # +false+, then the spec fails with the message returned by <tt>matcher.failure_message</tt>.
26 # Similarly, when +should_not+ receives a matcher, it calls <tt>matches?(self)</tt>. If
27 # it returns +false+, the spec passes and execution continues. If it returns
28 # +true+, then the spec fails with the message returned by <tt>matcher.negative_failure_message</tt>.
30 # RSpec ships with a standard set of useful matchers, and writing your own
31 # matchers is quite simple. See Spec::Matchers for details.
36 # raises a Spec::Expectations::ExpectationNotMetError with message
38 # When a differ has been assigned and fail_with is passed
39 # <code>expected</code> and <code>target</code>, passes them
40 # to the differ to append a diff message to the failure message.
41 def fail_with(message, expected=nil, target=nil) # :nodoc:
42 if Array === message && message.length == 3
43 message, expected, target = message[0], message[1], message[2]
45 unless (differ.nil? || expected.nil? || target.nil?)
46 if expected.is_a?(String)
47 message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
48 elsif !target.is_a?(Proc)
49 message << "\nDiff:" << self.differ.diff_as_object(target, expected)
52 Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))