on-test-spec 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,459 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+ require 'test/spec/rails'
3
+
4
+ module TestingAssertionsThemselves
5
+ class << self
6
+ def setup
7
+ $TEST_SPEC_TESTCASE = TestingAssertionsThemselves
8
+ TestingAssertionsThemselves.assertions = []
9
+ end
10
+
11
+ attr_accessor :assertions
12
+
13
+ def assert(*args)
14
+ TestingAssertionsThemselves.assertions << [:assert, args]
15
+ end
16
+
17
+ def assert_equal(*args)
18
+ TestingAssertionsThemselves.assertions << [:assert_equal, args]
19
+ end
20
+
21
+ def last_assertion
22
+ TestingAssertionsThemselves.assertions.last
23
+ end
24
+ end
25
+ end
26
+
27
+ module AssertionAssertions
28
+ def assert_assert_success(message=nil)
29
+ assertion = TestingAssertionsThemselves.last_assertion
30
+
31
+ assert_equal :assert, assertion[0]
32
+ assert assertion[1][0]
33
+ assert_equal(message, assertion[2][1]) if message
34
+ end
35
+
36
+ def assert_assert_failure(message=nil)
37
+ assertion = TestingAssertionsThemselves.last_assertion
38
+
39
+ assert_equal :assert, assertion[0]
40
+ assert !assertion[1][0]
41
+ assert_equal(message, assertion[1][1]) if message
42
+ end
43
+
44
+ def assert_assert_equal_success(message=nil)
45
+ assertion = TestingAssertionsThemselves.last_assertion
46
+
47
+ assert_equal :assert_equal, assertion[0]
48
+ assert_equal assertion[1][0], assertion[1][1]
49
+ assert_equal(message, assertion[1][2]) if message
50
+ end
51
+
52
+ def assert_assert_equal_failure(message=nil)
53
+ assertion = TestingAssertionsThemselves.last_assertion
54
+
55
+ assert_equal :assert_equal, assertion[0]
56
+ assert_not_equal assertion[1][0], assertion[1][1]
57
+ assert_equal(message, assertion[1][2]) if message
58
+ end
59
+ end
60
+
61
+ class Pony
62
+ class << self
63
+ attr_accessor :count
64
+ end
65
+ end
66
+
67
+ describe "Differ expectations" do
68
+ include AssertionAssertions
69
+ attr_accessor :controller
70
+
71
+ before do
72
+ TestingAssertionsThemselves.setup
73
+ end
74
+
75
+ it "should succeed when the expected difference occurs on a local variable" do
76
+ count = 1
77
+ lambda {
78
+ count = 2
79
+ }.should.differ('count')
80
+ assert_assert_equal_success
81
+ end
82
+
83
+ it "should succeed when the expected difference occurs on an instance variable in the current scope" do
84
+ @count = 1
85
+ lambda {
86
+ @count = 2
87
+ }.should.differ('@count')
88
+ assert_assert_equal_success
89
+ end
90
+
91
+ it "should succeed when the expected difference occurs on a class in the current scope" do
92
+ Pony.count = 1
93
+ lambda {
94
+ Pony.count = 2
95
+ }.should.differ('Pony.count')
96
+ assert_assert_equal_success
97
+ end
98
+
99
+ it "should succeed when the difference is explicitly stated" do
100
+ Pony.count = 1
101
+ lambda {
102
+ Pony.count = 3
103
+ }.should.differ('Pony.count', +2)
104
+ assert_assert_equal_success
105
+ end
106
+
107
+ it "should fail when the expected difference does not occur" do
108
+ Pony.count = 1
109
+ lambda {
110
+ Pony.count = 3
111
+ }.should.differ('Pony.count')
112
+ assert_assert_equal_failure('"Pony.count" didn\'t change by 1')
113
+ end
114
+
115
+ it "should fail when the explicitly stated difference does not occur" do
116
+ Pony.count = 1
117
+ lambda {
118
+ Pony.count = 3
119
+ }.should.differ('Pony.count', +5)
120
+ assert_assert_equal_failure('"Pony.count" didn\'t change by 5')
121
+ end
122
+
123
+ it "should return the return value of the block" do
124
+ Pony.count = 3
125
+ result = lambda {
126
+ Pony.count += 1
127
+ }.should.differ('Pony.count', 1)
128
+ assert_equal 4, result, "differ didn't return the block result"
129
+ end
130
+
131
+ it "should succeed when multiple expected differences occur" do
132
+ count = 1
133
+ Pony.count = 1
134
+ lambda {
135
+ count = 2
136
+ Pony.count = 2
137
+ }.should.differ('Pony.count', +1, 'count', +1)
138
+
139
+ TestingAssertionsThemselves.assertions.each do |assertion, args|
140
+ assert_equal :assert_equal, assertion
141
+ assert_equal args[0], args[1]
142
+ end
143
+ end
144
+
145
+ it "should fail when first of the expected differences does not occur" do
146
+ count = 1
147
+ Pony.count = 1
148
+ lambda {
149
+ count += 4
150
+ }.should.differ('Pony.count', +2, 'count', +4)
151
+
152
+ assertion, args = TestingAssertionsThemselves.assertions.first
153
+ assert_equal :assert_equal, assertion
154
+ assert_not_equal(args[0], args[1])
155
+ assert_equal '"Pony.count" didn\'t change by 2', args[2]
156
+
157
+ assertion, args = TestingAssertionsThemselves.assertions.second
158
+ assert_equal :assert_equal, assertion
159
+ assert_equal(args[0], args[1])
160
+ end
161
+
162
+ it "should fail when second of the expected differences does not occur" do
163
+ count = 1
164
+ Pony.count = 1
165
+ lambda {
166
+ Pony.count += 2
167
+ }.should.differ('Pony.count', +2, 'count', +4)
168
+
169
+ assertion, args = TestingAssertionsThemselves.assertions.first
170
+ assert_equal :assert_equal, assertion
171
+ assert_equal(args[0], args[1])
172
+
173
+ assertion, args = TestingAssertionsThemselves.assertions.second
174
+ assert_equal :assert_equal, assertion
175
+ assert_not_equal(args[0], args[1])
176
+ assert_equal '"count" didn\'t change by 4', args[2]
177
+ end
178
+ end
179
+
180
+ describe "NotDiffer expectations" do
181
+ include AssertionAssertions
182
+ attr_accessor :controller
183
+
184
+ before do
185
+ TestingAssertionsThemselves.setup
186
+ end
187
+
188
+ it "should succeed when no difference occurs on a local variable" do
189
+ count = 1
190
+ lambda {
191
+ }.should.not.differ('count')
192
+ assert_assert_equal_success
193
+ end
194
+
195
+ it "should succeed when no difference occurs on an instance variable in the current scope" do
196
+ @count = 1
197
+ lambda {
198
+ }.should.not.differ('@count')
199
+ assert_assert_equal_success
200
+ end
201
+
202
+ it "should succeed when no difference occurs on a class in the current scope" do
203
+ Pony.count = 1
204
+ lambda {
205
+ }.should.not.differ('Pony.count')
206
+ assert_assert_equal_success
207
+ end
208
+
209
+ it "should fail when a difference occurs" do
210
+ Pony.count = 1
211
+ lambda {
212
+ Pony.count = 3
213
+ }.should.not.differ('Pony.count')
214
+ assert_assert_equal_failure('"Pony.count" changed by 2, expected no change')
215
+ end
216
+
217
+ it "should return the return value of the block" do
218
+ Pony.count = 3
219
+ result = lambda {
220
+ Pony.count += 1
221
+ }.should.not.differ('Pony.count')
222
+ assert_equal 4, result, "differ didn't return the block result"
223
+ end
224
+
225
+ it "should succeed when multiple expected differences do not occur" do
226
+ count = 1
227
+ Pony.count = 1
228
+ lambda {
229
+ }.should.not.differ('Pony.count', 'count')
230
+
231
+ TestingAssertionsThemselves.assertions.each do |assertion, args|
232
+ assert_equal :assert_equal, assertion
233
+ assert_equal args[0], args[1]
234
+ end
235
+ end
236
+
237
+ it "should fail when first of the expected differences does occur" do
238
+ count = 1
239
+ Pony.count = 1
240
+ lambda {
241
+ Pony.count += 2
242
+ }.should.not.differ('Pony.count', 'count')
243
+
244
+ assertion, args = TestingAssertionsThemselves.assertions.first
245
+ assert_equal :assert_equal, assertion
246
+ assert_not_equal(args[0], args[1])
247
+ assert_equal '"Pony.count" changed by 2, expected no change', args[2]
248
+
249
+ assertion, args = TestingAssertionsThemselves.assertions.second
250
+ assert_equal :assert_equal, assertion
251
+ assert_equal(args[0], args[1])
252
+ end
253
+
254
+ it "should fail when second of the expected differences does occur" do
255
+ count = 1
256
+ Pony.count = 1
257
+ lambda {
258
+ count += 4
259
+ }.should.not.differ('Pony.count', 'count')
260
+
261
+ assertion, args = TestingAssertionsThemselves.assertions.first
262
+ assert_equal :assert_equal, assertion
263
+ assert_equal(args[0], args[1])
264
+
265
+ assertion, args = TestingAssertionsThemselves.assertions.second
266
+ assert_equal :assert_equal, assertion
267
+ assert_not_equal(args[0], args[1])
268
+ assert_equal '"count" changed by 4, expected no change', args[2]
269
+ end
270
+ end
271
+
272
+
273
+ describe "Record expectations" do
274
+ include AssertionAssertions
275
+ attr_accessor :controller
276
+
277
+ before do
278
+ TestingAssertionsThemselves.setup
279
+ end
280
+
281
+ it "should succeed when equal_set assertions are correct" do
282
+ [].should.equal_set []
283
+ assert_assert_success
284
+
285
+ [stub(:id => 1)].should.equal_set [stub(:id => 1)]
286
+ assert_assert_success
287
+
288
+ [stub(:id => 1), stub(:id => 1)].should.equal_set [stub(:id => 1), stub(:id => 1)]
289
+ assert_assert_success
290
+
291
+ [stub(:id => 1), stub(:id => 2)].should.equal_set [stub(:id => 1), stub(:id => 2)]
292
+ assert_assert_success
293
+
294
+ [stub(:id => 2)].should.not.equal_set [stub(:id => 1)]
295
+ assert_assert_success
296
+
297
+ [stub(:id => 1), stub(:id => 2)].should.not.equal_set [stub(:id => 1)]
298
+ assert_assert_success
299
+
300
+ [stub(:id => 1)].should.not.equal_set [stub(:id => 1), stub(:id => 2)]
301
+ assert_assert_success
302
+
303
+ # equal_set ignores order
304
+ [stub(:id => 1), stub(:id => 2)].should.equal_set [stub(:id => 2), stub(:id => 1)]
305
+ assert_assert_success
306
+ end
307
+
308
+ it "should fail when equal_set assertions are not correct" do
309
+ [].should.not.equal_set []
310
+ assert_assert_failure("[] has the same records as []")
311
+
312
+ [stub(:id => 1), stub(:id => 1)].should.equal_set [stub(:id => 1)]
313
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[1]] does not have the same records as [Mocha::Mock[1]]")
314
+
315
+ [stub(:id => 1), stub(:id => 2)].should.equal_set [stub(:id => 1), stub(:id => 1), stub(:id => 2)]
316
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] does not have the same records as [Mocha::Mock[1], Mocha::Mock[1], Mocha::Mock[2]]")
317
+
318
+ [stub(:id => 1), stub(:id => 2), stub(:id => 1)].should.equal_set [stub(:id => 1), stub(:id => 2), stub(:id => 2)]
319
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2], Mocha::Mock[1]] does not have the same records as [Mocha::Mock[1], Mocha::Mock[2], Mocha::Mock[2]]")
320
+
321
+ [stub(:id => 1)].should.not.equal_set [stub(:id => 1)]
322
+ assert_assert_failure("[Mocha::Mock[1]] has the same records as [Mocha::Mock[1]]")
323
+
324
+ [stub(:id => 1), stub(:id => 2)].should.not.equal_set [stub(:id => 1), stub(:id => 2)]
325
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] has the same records as [Mocha::Mock[1], Mocha::Mock[2]]")
326
+
327
+ [stub(:id => 2)].should.equal_set [stub(:id => 1)]
328
+ assert_assert_failure("[Mocha::Mock[2]] does not have the same records as [Mocha::Mock[1]]")
329
+
330
+ [stub(:id => 1), stub(:id => 2)].should.equal_set [stub(:id => 1)]
331
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] does not have the same records as [Mocha::Mock[1]]")
332
+
333
+ [stub(:id => 1)].should.equal_set [stub(:id => 1), stub(:id => 2)]
334
+ assert_assert_failure("[Mocha::Mock[1]] does not have the same records as [Mocha::Mock[1], Mocha::Mock[2]]")
335
+ end
336
+
337
+ it "should succeed when equal_list assertions are correct" do
338
+ [].should.equal_list []
339
+ assert_assert_success
340
+
341
+ [stub(:id => 1)].should.equal_list [stub(:id => 1)]
342
+ assert_assert_success
343
+
344
+ [stub(:id => 1), stub(:id => 1)].should.equal_list [stub(:id => 1), stub(:id => 1)]
345
+ assert_assert_success
346
+
347
+ [stub(:id => 1), stub(:id => 2)].should.equal_list [stub(:id => 1), stub(:id => 2)]
348
+ assert_assert_success
349
+
350
+ [stub(:id => 2)].should.not.equal_list [stub(:id => 1)]
351
+ assert_assert_success
352
+
353
+ [stub(:id => 1), stub(:id => 2)].should.not.equal_list [stub(:id => 1)]
354
+ assert_assert_success
355
+
356
+ [stub(:id => 1)].should.not.equal_list [stub(:id => 1), stub(:id => 2)]
357
+ assert_assert_success
358
+
359
+ # equal_list does not ignore order
360
+ [stub(:id => 1), stub(:id => 2)].should.not.equal_list [stub(:id => 2), stub(:id => 1)]
361
+ assert_assert_success
362
+ end
363
+
364
+ it "should fail when equal_list assertions are not correct" do
365
+ [].should.not.equal_list []
366
+ assert_assert_failure("[] has the same records as []")
367
+
368
+ [stub(:id => 1), stub(:id => 1)].should.equal_list [stub(:id => 1)]
369
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[1]] does not have the same records as [Mocha::Mock[1]]")
370
+
371
+ [stub(:id => 1), stub(:id => 2)].should.equal_list [stub(:id => 1), stub(:id => 1), stub(:id => 2)]
372
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] does not have the same records as [Mocha::Mock[1], Mocha::Mock[1], Mocha::Mock[2]]")
373
+
374
+ [stub(:id => 1), stub(:id => 2), stub(:id => 1)].should.equal_list [stub(:id => 1), stub(:id => 2), stub(:id => 2)]
375
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2], Mocha::Mock[1]] does not have the same records as [Mocha::Mock[1], Mocha::Mock[2], Mocha::Mock[2]]")
376
+
377
+ [stub(:id => 1)].should.not.equal_list [stub(:id => 1)]
378
+ assert_assert_failure("[Mocha::Mock[1]] has the same records as [Mocha::Mock[1]]")
379
+
380
+ [stub(:id => 1), stub(:id => 2)].should.not.equal_list [stub(:id => 1), stub(:id => 2)]
381
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] has the same records as [Mocha::Mock[1], Mocha::Mock[2]]")
382
+
383
+ [stub(:id => 2)].should.equal_list [stub(:id => 1)]
384
+ assert_assert_failure("[Mocha::Mock[2]] does not have the same records as [Mocha::Mock[1]]")
385
+
386
+ [stub(:id => 1), stub(:id => 2)].should.equal_list [stub(:id => 1)]
387
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] does not have the same records as [Mocha::Mock[1]]")
388
+
389
+ [stub(:id => 1)].should.equal_list [stub(:id => 1), stub(:id => 2)]
390
+ assert_assert_failure("[Mocha::Mock[1]] does not have the same records as [Mocha::Mock[1], Mocha::Mock[2]]")
391
+
392
+ # equal_list does not ignore order
393
+ [stub(:id => 1), stub(:id => 2)].should.equal_list [stub(:id => 2), stub(:id => 1)]
394
+ assert_assert_failure("[Mocha::Mock[1], Mocha::Mock[2]] does not have the same records as [Mocha::Mock[2], Mocha::Mock[1]]")
395
+ end
396
+ end
397
+
398
+ class TestController
399
+ def request
400
+ unless @request
401
+ @request ||= Object.new
402
+ def @request.env
403
+ @env ||= {}
404
+ end
405
+ end
406
+ @request
407
+ end
408
+ end
409
+
410
+ describe "Redirection expectations" do
411
+ include AssertionAssertions
412
+ attr_accessor :controller
413
+
414
+ before do
415
+ TestingAssertionsThemselves.setup
416
+
417
+ @controller = TestController.new
418
+ @controller.stubs(:url_for).returns(@url)
419
+
420
+ @matcher = stub('matcher')
421
+ self.stubs(:should).returns(@matcher)
422
+ @matcher.stubs(:redirect_to)
423
+
424
+ @url = 'new_session_url'
425
+ end
426
+
427
+ it "should set the request env HTTP_REFERER before executing the proc" do
428
+ @controller.expects(:url_for).with(@url).returns(@url)
429
+ lambda {}.should.redirect_back_to(@url)
430
+ assert_equal @url, controller.request.env['HTTP_REFERER']
431
+ end
432
+
433
+ it "should call the `redirect_to' matcher with the url _after_ executing the proc" do
434
+ def @matcher.redirect_to(*args)
435
+ raise "Oh noes, should not be called yet!"
436
+ end
437
+
438
+ lambda {
439
+ def @matcher.redirect_to(*args)
440
+ @called = true
441
+ end
442
+ }.should.redirect_back_to(@url)
443
+
444
+ assert @matcher.instance_variable_get(:@called)
445
+ end
446
+
447
+ it "should work with regular url options as well" do
448
+ @controller.expects(:url_for).with(:action => :new).returns(@url)
449
+ @matcher.expects(:redirect_to).with(@url)
450
+
451
+ lambda {}.should.redirect_back_to(:action => :new)
452
+ assert_equal @url, controller.request.env['HTTP_REFERER']
453
+ end
454
+
455
+ it "should return the result of calling the block" do
456
+ result = lambda { "called block" }.should.redirect_back_to(@url)
457
+ assert_equal "called block", result
458
+ end
459
+ end
@@ -0,0 +1,102 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+ require 'test/spec/rails/macros'
3
+
4
+ describe "Authorization::TestGenerator, concerning generation" do
5
+ before do
6
+ @test = mock('Test')
7
+ @generator = Test::Spec::Rails::Macros::Authorization::TestGenerator.new(@test, :access_denied?, true, 'Expected access to be denied')
8
+ end
9
+
10
+ it "should generate a test description for a GET" do
11
+ @test.expects(:it).with("should disallow GET on `index'")
12
+ @generator.get(:index)
13
+ end
14
+
15
+ it "should generate a test description for a POST with params" do
16
+ @test.expects(:it).with("should disallow POST on `create\' {:venue=>{:name=>\"Bitterzoet\"}}")
17
+ @generator.post(:create, :venue => { :name => "Bitterzoet" })
18
+ end
19
+
20
+ it "should raise a NoMethodError when you disallow an unknown HTTP verb" do
21
+ lambda {
22
+ @generator.unknown :index
23
+ }.should.raise(NoMethodError)
24
+ end
25
+ end
26
+
27
+ class Immediate
28
+ def self.it(description, &block)
29
+ block.call
30
+ end
31
+ end
32
+
33
+ describe "Authorization::TestGenerator, concerning test contents" do
34
+ before do
35
+ @generator = Test::Spec::Rails::Macros::Authorization::TestGenerator.new(Immediate, :access_denied?, true, 'Expected access to be denied')
36
+ @generator.stubs(:send).with(:access_denied?).returns(true)
37
+ end
38
+
39
+ it "should send the verb and options to the controller" do
40
+ params = {:venue => {:name => "Bitterzoet"}}
41
+ @generator.stubs(:immediate_values).with(params).returns(params)
42
+ @generator.expects(:send).with(:post, :create, params)
43
+
44
+ @generator.post(:create, params)
45
+ end
46
+
47
+ it "should immediate values in params" do
48
+ params = {:name => 'bitterzoet'}
49
+
50
+ @generator.expects(:immediate_values).with(params).returns(params)
51
+ @generator.stubs(:send).returns(true)
52
+
53
+ @generator.post(:create, params)
54
+ end
55
+
56
+ it "should test the return value of the validation method against the expected method" do
57
+ @generator.expected = false
58
+ params = {:name => 'bitterzoet'}
59
+
60
+ @generator.expects(:immediate_values).with(params).returns(params)
61
+ @generator.stubs(:send).returns(false)
62
+
63
+ @generator.post(:create, params)
64
+ end
65
+ end
66
+
67
+ describe "Macros::Authorization" do
68
+ before do
69
+ @test_case = mock('TestCase')
70
+ @proxy = Test::Spec::Rails::Macros::Should.new(@test_case)
71
+ end
72
+
73
+ it "should return a test generator when a new disallow rule is invoked" do
74
+ generator = @proxy.disallow
75
+
76
+ generator.should.is_a(Test::Spec::Rails::Macros::Authorization::TestGenerator)
77
+ generator.test_case.should == @test_case
78
+ generator.validation_method.should == :access_denied?
79
+ generator.message.should == 'Expected access to be denied'
80
+ generator.expected.should == true
81
+ end
82
+
83
+ it "should return a test generator when a new allow rule is invoked" do
84
+ generator = @proxy.allow
85
+
86
+ generator.should.is_a(Test::Spec::Rails::Macros::Authorization::TestGenerator)
87
+ generator.test_case.should == @test_case
88
+ generator.validation_method.should == :access_denied?
89
+ generator.message.should == 'Expected access to be allowed'
90
+ generator.expected.should == false
91
+ end
92
+
93
+ it "should return a test generator when a new login_required rule is invoked" do
94
+ generator = @proxy.require_login
95
+
96
+ generator.should.is_a(Test::Spec::Rails::Macros::Authorization::TestGenerator)
97
+ generator.test_case.should == @test_case
98
+ generator.validation_method.should == :login_required?
99
+ generator.message.should == 'Expected login to be required'
100
+ generator.expected.should == true
101
+ end
102
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+ require 'test/spec/rails/macros'
3
+
4
+ describe "Macros::Proxy" do
5
+ it "should store an instance of the test case" do
6
+ test_case = mock('TestCase')
7
+ proxy = Test::Spec::Rails::Macros::Proxy.new(test_case)
8
+ proxy.test_case.should == test_case
9
+ end
10
+ end
11
+
12
+ describe "Macros::Should" do
13
+ it "should store an instance of the test_case" do
14
+ test_case = mock('TestCase')
15
+ proxy = Test::Spec::Rails::Macros::Should.new(test_case)
16
+ proxy.test_case.should == test_case
17
+ end
18
+ end
19
+
20
+ class Case
21
+ extend Test::Spec::Rails::Macros::ClassMethods
22
+ include Test::Spec::Rails::Macros::InstanceMethods
23
+
24
+ def events(name)
25
+ "fixture: #{name.inspect}"
26
+ end
27
+ end
28
+
29
+ describe "A test case with support for macros" do
30
+ it "should return a Should instance" do
31
+ Case.new.should.should.be.kind_of?(Test::Spec::Rails::Macros::Should)
32
+ end
33
+
34
+ it "should know what are valid fixtures" do
35
+ Case.stubs(:fixture_table_names).returns(%w(events venues))
36
+ Case.known_fixture?(:events).should == true
37
+ Case.known_fixture?(:venues).should == true
38
+ Case.known_fixture?(:unknown).should == false
39
+ end
40
+
41
+ it "should know there are no fixtures when there are no fixture_table_names in the test" do
42
+ Case.stubs(:respond_to?).with(:fixture_table_names).returns(false)
43
+ Case.known_fixture?(:events).should == false
44
+ Case.known_fixture?(:venues).should == false
45
+ Case.known_fixture?(:unknown).should == false
46
+ end
47
+
48
+ it "should wrap know fixture methods in a lambda so they don't have to be known yet" do
49
+ Case.stubs(:fixture_table_names).returns(%w(events venues))
50
+ Case.events(:bitterzoet).should.be.kind_of?(Test::Spec::Rails::Macros::LazyValue)
51
+ Case.events(:bitterzoet).value.should == "events(:bitterzoet)"
52
+ end
53
+ end
54
+
55
+ describe "A test case instance with support for macros" do
56
+ before do
57
+ @case = Case.new
58
+ Case.stubs(:fixture_table_names).returns(%w(events))
59
+ end
60
+
61
+ it "should immediate LazyValue values in the context of the current test" do
62
+ @case.immediate_values(:name => Test::Spec::Rails::Macros::LazyValue.new('events(:bitterzoet)')).should == {
63
+ :name => 'fixture: :bitterzoet'
64
+ }
65
+ end
66
+
67
+ it "should immediate Proc values" do
68
+ @case.immediate_values(:name => Proc.new { 42 }).should == { :name => 42 }
69
+ end
70
+
71
+ it "should not change actual values" do
72
+ @case.immediate_values(:name => 42).should == { :name => 42 }
73
+ end
74
+
75
+ it "should immediate nested values" do
76
+ @case.immediate_values(:venue => { :name => Proc.new { 'bitterzoet' } }).should == {:venue => {:name => 'bitterzoet'}}
77
+ end
78
+ end