changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/expectations/extensions/object.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1module 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
67end
68
69class Object
70 include Spec::Expectations::ObjectExpectations
71end