changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/matchers/operator_matcher_spec.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
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3require 'spec/expectations/differs/default'
4
5describe "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
19end
20
21describe "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
35end
36
37describe "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
52end
53
54describe "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
69end
70
71describe "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
86end
87
88describe "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
103end
104
105describe "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
116end
117
118describe "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
130end
131
132describe "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
143end
144
145describe "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
157end
158