]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/expectations/extensions/object_spec.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / expectations / extensions / object_spec.rb
1 require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
3 describe Object, "#should" do
4   before(:each) do
5     @target = "target"
6     @matcher = mock("matcher")
7     @matcher.stub!(:matches?).and_return(true)
8     @matcher.stub!(:failure_message)
9   end
10   
11   it "should accept and interact with a matcher" do
12     @matcher.should_receive(:matches?).with(@target).and_return(true)    
13     @target.should @matcher
14   end
15   
16   it "should ask for a failure_message when matches? returns false" do
17     @matcher.should_receive(:matches?).with(@target).and_return(false)
18     @matcher.should_receive(:failure_message).and_return("the failure message")
19     lambda {
20       @target.should @matcher
21     }.should fail_with("the failure message")
22   end
23   
24   it "should raise error if it receives false directly" do
25     lambda {
26       @target.should false
27     }.should raise_error(Spec::Expectations::InvalidMatcherError)
28   end
29   
30   it "should raise error if it receives false (evaluated)" do
31     lambda {
32       @target.should eql?("foo")
33     }.should raise_error(Spec::Expectations::InvalidMatcherError)
34   end
35   
36   it "should raise error if it receives true" do
37     lambda {
38       @target.should true
39     }.should raise_error(Spec::Expectations::InvalidMatcherError)
40   end
41   
42   it "should raise error if it receives nil" do
43     lambda {
44       @target.should nil
45     }.should raise_error(Spec::Expectations::InvalidMatcherError)
46   end
47
48   it "should raise error if it receives no argument and it is not used as a left side of an operator" do
49     pending "Is it even possible to catch this?"
50     lambda {
51       @target.should
52     }.should raise_error(Spec::Expectations::InvalidMatcherError)
53   end
54 end
55
56 describe Object, "#should_not" do
57   before(:each) do
58     @target = "target"
59     @matcher = mock("matcher")
60   end
61   
62   it "should accept and interact with a matcher" do
63     @matcher.should_receive(:matches?).with(@target).and_return(false)
64     @matcher.stub!(:negative_failure_message)
65     
66     @target.should_not @matcher
67   end
68   
69   it "should ask for a negative_failure_message when matches? returns true" do
70     @matcher.should_receive(:matches?).with(@target).and_return(true)
71     @matcher.should_receive(:negative_failure_message).and_return("the negative failure message")
72     lambda {
73       @target.should_not @matcher
74     }.should fail_with("the negative failure message")
75   end
76
77   it "should raise error if it receives false directly" do
78     lambda {
79       @target.should_not false
80     }.should raise_error(Spec::Expectations::InvalidMatcherError)
81   end
82   
83   it "should raise error if it receives false (evaluated)" do
84     lambda {
85       @target.should_not eql?("foo")
86     }.should raise_error(Spec::Expectations::InvalidMatcherError)
87   end
88   
89   it "should raise error if it receives true" do
90     lambda {
91       @target.should_not true
92     }.should raise_error(Spec::Expectations::InvalidMatcherError)
93   end
94
95   it "should raise error if it receives nil" do
96     lambda {
97       @target.should_not nil
98     }.should raise_error(Spec::Expectations::InvalidMatcherError)
99   end
100
101   it "should raise error if it receives no argument and it is not used as a left side of an operator" do
102     pending "Is it even possible to catch this?"
103     lambda {
104       @target.should_not
105     }.should raise_error(Spec::Expectations::InvalidMatcherError)
106   end
107 end