]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/matchers/operator_matcher_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 / matchers / operator_matcher_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3 require 'spec/expectations/differs/default'
4
5 describe "should ==" do
6   
7   it "should delegate message to target" do
8     subject = "apple"
9     subject.should_receive(:==).with("apple").and_return(true)
10     subject.should == "apple"
11   end
12   
13   it "should fail when target.==(actual) returns false" do
14     subject = "apple"
15     Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n     got: "apple" (using ==)], "orange", "apple")
16     subject.should == "orange"
17   end
18
19 end
20
21 describe "should_not ==" do
22   
23   it "should delegate message to target" do
24     subject = "orange"
25     subject.should_receive(:==).with("apple").and_return(false)
26     subject.should_not == "apple"
27   end
28   
29   it "should fail when target.==(actual) returns false" do
30     subject = "apple"
31     Spec::Expectations.should_receive(:fail_with).with(%[expected not: == "apple",\n         got:    "apple"], "apple", "apple")
32     subject.should_not == "apple"
33   end
34
35 end
36
37 describe "should ===" do
38   
39   it "should delegate message to target" do
40     subject = "apple"
41     subject.should_receive(:===).with("apple").and_return(true)
42     subject.should === "apple"
43   end
44   
45   it "should fail when target.===(actual) returns false" do
46     subject = "apple"
47     subject.should_receive(:===).with("orange").and_return(false)
48     Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n     got: "apple" (using ===)], "orange", "apple")
49     subject.should === "orange"
50   end
51   
52 end
53
54 describe "should_not ===" do
55   
56   it "should delegate message to target" do
57     subject = "orange"
58     subject.should_receive(:===).with("apple").and_return(false)
59     subject.should_not === "apple"
60   end
61   
62   it "should fail when target.===(actual) returns false" do
63     subject = "apple"
64     subject.should_receive(:===).with("apple").and_return(true)
65     Spec::Expectations.should_receive(:fail_with).with(%[expected not: === "apple",\n         got:     "apple"], "apple", "apple")
66     subject.should_not === "apple"
67   end
68
69 end
70
71 describe "should =~" do
72   
73   it "should delegate message to target" do
74     subject = "foo"
75     subject.should_receive(:=~).with(/oo/).and_return(true)
76     subject.should =~ /oo/
77   end
78   
79   it "should fail when target.=~(actual) returns false" do
80     subject = "fu"
81     subject.should_receive(:=~).with(/oo/).and_return(false)
82     Spec::Expectations.should_receive(:fail_with).with(%[expected: /oo/,\n     got: "fu" (using =~)], /oo/, "fu")
83     subject.should =~ /oo/
84   end
85
86 end
87
88 describe "should_not =~" do
89   
90   it "should delegate message to target" do
91     subject = "fu"
92     subject.should_receive(:=~).with(/oo/).and_return(false)
93     subject.should_not =~ /oo/
94   end
95   
96   it "should fail when target.=~(actual) returns false" do
97     subject = "foo"
98     subject.should_receive(:=~).with(/oo/).and_return(true)
99     Spec::Expectations.should_receive(:fail_with).with(%[expected not: =~ /oo/,\n         got:    "foo"], /oo/, "foo")
100     subject.should_not =~ /oo/
101   end
102
103 end
104
105 describe "should >" do
106   
107   it "should pass if > passes" do
108     4.should > 3
109   end
110
111   it "should fail if > fails" do
112     Spec::Expectations.should_receive(:fail_with).with(%[expected: > 5,\n     got:   4], 5, 4)
113     4.should > 5
114   end
115
116 end
117
118 describe "should >=" do
119   
120   it "should pass if >= passes" do
121     4.should > 3
122     4.should >= 4
123   end
124
125   it "should fail if > fails" do
126     Spec::Expectations.should_receive(:fail_with).with(%[expected: >= 5,\n     got:    4], 5, 4)
127     4.should >= 5
128   end
129
130 end
131
132 describe "should <" do
133   
134   it "should pass if < passes" do
135     4.should < 5
136   end
137
138   it "should fail if > fails" do
139     Spec::Expectations.should_receive(:fail_with).with(%[expected: < 3,\n     got:   4], 3, 4)
140     4.should < 3
141   end
142
143 end
144
145 describe "should <=" do
146   
147   it "should pass if <= passes" do
148     4.should <= 5
149     4.should <= 4
150   end
151
152   it "should fail if > fails" do
153     Spec::Expectations.should_receive(:fail_with).with(%[expected: <= 3,\n     got:    4], 3, 4)
154     4.should <= 3
155   end
156
157 end
158