]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/expectations/extensions/object.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / expectations / extensions / object.rb
1 module Spec
2   module Expectations
3     # rspec adds #should and #should_not to every Object (and,
4     # implicitly, every Class).
5     module ObjectExpectations
6       # :call-seq:
7       #   should(matcher)
8       #   should == expected
9       #   should === expected
10       #   should =~ expected
11       #
12       #   receiver.should(matcher)
13       #     => Passes if matcher.matches?(receiver)
14       #
15       #   receiver.should == expected #any value
16       #     => Passes if (receiver == expected)
17       #
18       #   receiver.should === expected #any value
19       #     => Passes if (receiver === expected)
20       #
21       #   receiver.should =~ regexp
22       #     => Passes if (receiver =~ regexp)
23       #
24       # See Spec::Matchers for more information about matchers
25       #
26       # == Warning
27       #
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)
33         else
34           ExpectationMatcherHandler.handle_matcher(self, matcher, &block)
35         end
36       end
37
38       # :call-seq:
39       #   should_not(matcher)
40       #   should_not == expected
41       #   should_not === expected
42       #   should_not =~ expected
43       #
44       #   receiver.should_not(matcher)
45       #     => Passes unless matcher.matches?(receiver)
46       #
47       #   receiver.should_not == expected
48       #     => Passes unless (receiver == expected)
49       #
50       #   receiver.should_not === expected
51       #     => Passes unless (receiver === expected)
52       #
53       #   receiver.should_not =~ regexp
54       #     => Passes unless (receiver =~ regexp)
55       #
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)
60         else
61           NegativeExpectationMatcherHandler.handle_matcher(self, matcher, &block)
62         end
63       end
64
65     end
66   end
67 end
68
69 class Object
70   include Spec::Expectations::ObjectExpectations
71 end