|
1 | 1 | require 'spec_helper'
|
2 | 2 |
|
3 | 3 | describe "mock_model(RealModel)" do
|
4 |
| - |
5 | 4 | context "given a String" do
|
6 | 5 | context "that does not represent an existing constant" do
|
7 | 6 | it "class says it's name" do
|
|
121 | 120 | before(:each) do
|
122 | 121 | @model = mock_model(SubMockableModel)
|
123 | 122 | end
|
124 |
| - |
| 123 | + |
125 | 124 | it "says it is_a?(RealModel)" do
|
126 | 125 | @model.is_a?(SubMockableModel).should be(true)
|
127 | 126 | end
|
128 |
| - |
| 127 | + |
129 | 128 | it "says it is_a?(OtherModel) if RealModel is an ancestors" do
|
130 | 129 | @model.is_a?(MockableModel).should be(true)
|
131 | 130 | end
|
132 |
| - |
| 131 | + |
133 | 132 | it "can be stubbed" do
|
134 | 133 | mock_model(MockableModel, :is_a? => true).is_a?(:Foo).should be_truthy
|
135 | 134 | end
|
|
139 | 138 | before(:each) do
|
140 | 139 | @model = mock_model(SubMockableModel)
|
141 | 140 | end
|
142 |
| - |
| 141 | + |
143 | 142 | it "says it is kind_of? if RealModel is" do
|
144 | 143 | @model.kind_of?(SubMockableModel).should be(true)
|
145 | 144 | end
|
146 |
| - |
| 145 | + |
147 | 146 | it "says it is kind_of? if RealModel's ancestor is" do
|
148 | 147 | @model.kind_of?(MockableModel).should be(true)
|
149 | 148 | end
|
150 |
| - |
| 149 | + |
151 | 150 | it "can be stubbed" do
|
152 | 151 | mock_model(MockableModel, :kind_of? => true).kind_of?(:Foo).should be_truthy
|
153 | 152 | end
|
|
157 | 156 | before(:each) do
|
158 | 157 | @model = mock_model(SubMockableModel)
|
159 | 158 | end
|
160 |
| - |
| 159 | + |
161 | 160 | it "says it is instance_of? if RealModel is" do
|
162 | 161 | @model.instance_of?(SubMockableModel).should be(true)
|
163 | 162 | end
|
164 |
| - |
| 163 | + |
165 | 164 | it "does not say it instance_of? if RealModel isn't, even if it's ancestor is" do
|
166 | 165 | @model.instance_of?(MockableModel).should be(false)
|
167 | 166 | end
|
168 |
| - |
| 167 | + |
169 | 168 | it "can be stubbed" do
|
170 | 169 | mock_model(MockableModel, :instance_of? => true).instance_of?(:Foo).should be_truthy
|
171 | 170 | end
|
|
223 | 222 | @model.respond_to?("title_before_type_cast").should be(false)
|
224 | 223 | end
|
225 | 224 | end
|
226 |
| - |
| 225 | + |
227 | 226 | context "with as_null_object" do
|
228 | 227 | it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
|
229 | 228 | @model.as_null_object.respond_to?("column_a").should be(true)
|
|
247 | 246 | model = NonActiveRecordModel.new
|
248 | 247 | model.should respond_to(:to_param)
|
249 | 248 | end
|
250 |
| - |
| 249 | + |
251 | 250 | context "with as_null_object" do
|
252 | 251 | it "says it will not respond_to?(xxx_before_type_cast)" do
|
253 | 252 | model = NonActiveRecordModel.new.as_null_object
|
254 | 253 | model.respond_to?("title_before_type_cast").should be(false)
|
255 | 254 | end
|
256 | 255 | end
|
257 | 256 | end
|
258 |
| - |
| 257 | + |
259 | 258 | it "can be stubbed" do
|
260 | 259 | mock_model(MockableModel, :respond_to? => true).respond_to?(:foo).should be_truthy
|
261 | 260 | end
|
262 | 261 | end
|
263 |
| - |
| 262 | + |
264 | 263 | describe "#class" do
|
265 | 264 | it "returns the mocked model" do
|
266 | 265 | mock_model(MockableModel).class.should eq(MockableModel)
|
267 | 266 | end
|
268 |
| - |
| 267 | + |
269 | 268 | it "can be stubbed" do
|
270 | 269 | mock_model(MockableModel, :class => String).class.should be(String)
|
271 | 270 | end
|
|
275 | 274 | it "returns (model.name)_(model#to_param)" do
|
276 | 275 | mock_model(MockableModel).to_s.should == "MockableModel_#{to_param}"
|
277 | 276 | end
|
278 |
| - |
| 277 | + |
279 | 278 | it "can be stubbed" do
|
280 | 279 | mock_model(MockableModel, :to_s => "this string").to_s.should == "this string"
|
281 | 280 | end
|
|
325 | 324 | mock_model(MockableModel).should be_valid
|
326 | 325 | end
|
327 | 326 | end
|
328 |
| - |
| 327 | + |
329 | 328 | context "stubbed with false" do
|
330 | 329 | it "returns false" do
|
331 | 330 | mock_model(MockableModel, :valid? => false).should_not be_valid
|
|
0 commit comments