3 # rspec adds #should and #should_not to every Object (and,
4 # implicitly, every Class).
5 module ObjectExpectations
12 # receiver.should(matcher)
13 # => Passes if matcher.matches?(receiver)
15 # receiver.should == expected #any value
16 # => Passes if (receiver == expected)
18 # receiver.should === expected #any value
19 # => Passes if (receiver === expected)
21 # receiver.should =~ regexp
22 # => Passes if (receiver =~ regexp)
24 # See Spec::Matchers for more information about matchers
28 # NOTE that this does NOT support receiver.should != expected.
29 # Instead, use receiver.should_not == expected
30 def should(matcher = :default_parameter, &block)
31 if :default_parameter == matcher
32 Spec::Matchers::PositiveOperatorMatcher.new(self)
34 ExpectationMatcherHandler.handle_matcher(self, matcher, &block)
40 # should_not == expected
41 # should_not === expected
42 # should_not =~ expected
44 # receiver.should_not(matcher)
45 # => Passes unless matcher.matches?(receiver)
47 # receiver.should_not == expected
48 # => Passes unless (receiver == expected)
50 # receiver.should_not === expected
51 # => Passes unless (receiver === expected)
53 # receiver.should_not =~ regexp
54 # => Passes unless (receiver =~ regexp)
56 # See Spec::Matchers for more information about matchers
57 def should_not(matcher = :default_parameter, &block)
58 if :default_parameter == matcher
59 Spec::Matchers::NegativeOperatorMatcher.new(self)
61 NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block)
70 include Spec::Expectations::ObjectExpectations