File: ruby1.9.compatibility_tests.rb

package info (click to toggle)
ruby-jnunemaker-matchy 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: ruby: 2,939; makefile: 2
file content (541 lines) | stat: -rw-r--r-- 12,576 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# Eval this file with ruby 1.9

require 'test/unit'
require File.dirname(__FILE__) + '/../lib/matchy.rb'
class TestAThing < Test::Unit::TestCase
  
  def setup
    @obj = Object.new
  end
  
  # ==
  def test_operator_eql_eql
    1.should == 1
  end
  
  def test_operator_eql_eql_fails
    lambda {1.should == 2}.should raise_error
  end
  
  def test_operator_eql_eql_negative
    1.should_not == 2
  end
  
  def test_operator_eql_eql_negative_fails
    lambda {1.should_not == 1}.should raise_error
  end
  
  # ===
  def test_operator_eql_eql_eql
    1.should === 1
  end
  
  def test_operator_eql_eql_eql_fails
    lambda {1.should === 2}.should raise_error
  end
  
  def test_operator_eql_eql_eql_negative
    1.should_not === 2
  end
  
  def test_operator_eql_eql_eql_negative_fails
    lambda {1.should_not === 1}.should raise_error
  end
  
  # =~
  def test_operator_eql_match
    "string".should =~ /in/
  end
  
  def test_operator_eql_match_fails
    lambda {"string".should =~ /an/}.should raise_error
  end
  
  def test_operator_eql_match_negative
    "string".should_not =~ /an/
  end
  
  def test_operator_eql_match_negative_fails
    lambda {"string".should_not =~ /in/}.should raise_error
  end
  
  # <=
  def test_operator_lt_eql
    1.should <= 2
  end
  
  def test_operator_lt_eql_fails
    lambda {1.should <= 0}.should raise_error
  end
  
  def test_operator_lt_eql_negative
    1.should_not <= 0
  end
  
  def test_operator_lt_eql_negative_fails
    lambda {1.should_not <= 2}.should raise_error
  end
  
  # >=
  def test_operator_gt_eql
    1.should >= 0
  end
  
  def test_operator_gt_eql_fails
    lambda {1.should >= 2}.should raise_error
  end
  
  def test_operator_gt_eql_negative
    1.should_not >= 2
  end
  
  def test_operator_gt_eql_negative_fails
    lambda {1.should_not >= 0}.should raise_error
  end
  
  # <
  def test_operator_lt
    1.should < 2
  end
  
  def test_operator_lt_fails
    lambda {1.should < 0}.should raise_error
  end
  
  def test_operator_lt_negative
    1.should_not < 0
  end
  
  def test_operator_lt_negative_fails
    lambda {1.should_not < 2}.should raise_error
  end
  
  # >
  def test_operator_gt
    1.should > 0
  end
  
  def test_operator_gt_fails
    lambda {1.should > 2}.should raise_error
  end
  
  def test_operator_gt_negative
    1.should_not > 2
  end
  
  def test_operator_gt_negative_fails
    lambda {1.should_not > 0}.should raise_error
  end
  
  # be()
  def test_be
    1.should be(1)
  end
  
  def test_be_fails
    lambda {1.should be(2)}.should raise_error
  end
  
  def test_be_negative
    1.should_not be(2)
  end
  
  def test_be_negative_fails
    lambda {1.should_not be(1)}.should raise_error
  end
  
  # be_something
  def test_positive_be_something_method_missing_pass
    def @obj.something?
      true
    end
    @obj.should be_something
  end
  
  def test_positive_be_something_method_missing_fails
    def @obj.something?
      false
    end
    lambda {@obj.should be_something}.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_be_something_method_missing_pass
    def @obj.something?
      false
    end
    @obj.should_not be_something
  end
  
  def test_negative_be_something_method_missing_fails
    def @obj.something?
      true
    end
    lambda {@obj.should_not be_something}.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_be_something_method_missing_fail_message
    obj = "foo"
    def obj.something?
      true
    end
    matcher_obj = be_something
    obj.should matcher_obj
    
    matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with 'no args'.")
  end
  
  def test_be_something_method_missing_negative_fail_message
    obj = "foo"
    def obj.something?
      false
    end
    matcher_obj = be_something
    obj.should_not matcher_obj
    
    matcher_obj.negative_failure_message.should =~ /Expected \"foo\" to not return true for something?/
  end
  
  # be_something(arg)
  def test_positive_be_something_with_arg_method_missing_pass
    def @obj.something?(arg)
      true
    end
    @obj.should be_something(1)
  end
  
  def test_positive_be_something_with_arg_method_missing_fails
    def @obj.something?(arg)
      false
    end
    lambda {@obj.should be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_be_something_method_missing_pass
    def @obj.something?(arg)
      false
    end
    @obj.should_not be_something(1)
  end
  
  def test_negative_be_something_method_missing_fails
    def @obj.something?(arg)
      true
    end
    lambda {@obj.should_not be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_be_something_method_missing_fail_message
    obj = "foo"
    def obj.something?(arg)
      true
    end
    matcher_obj = be_something(1)
    obj.should matcher_obj
    
    matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with '1'.")
  end
  
  def test_be_something_method_missing_negative_fail_message
    obj = "foo"
    def obj.something?(arg)
      false
    end
    matcher_obj = be_something(1)
    obj.should_not matcher_obj
    
    matcher_obj.negative_failure_message.should be("Expected \"foo\" to not return true for something?, with '1'.")
  end
  
  # change
  def test_change
    var = 1
    lambda {var += 1}.should change {var}
  end
  
  def test_change_fails
    var = 1
    lambda do
      lambda { }.should change {var} 
    end.should raise_error
  end
  
  def test_change_by
    var = 1
    lambda {var += 1}.should change {var}.by(1)
  end
  
  def test_change_by_fails
    var = 1
    lambda do
      lambda {var += 2}.should change {var}.by(1) 
    end.should raise_error
  end
  
  def test_change_by_at_least
    var = 1
    lambda {var += 1}.should change {var}.by_at_least(1)
  end
  
  def test_change_by_at_least_fails
    var = 1
    lambda do
      lambda {var += 0.9}.should change {var}.by_at_least(1)
    end.should raise_error
  end
  
  def test_change_by_at_most
    var = 1
    lambda {var += 1}.should change {var}.by_at_most(1)
  end
  
  def test_change_by_at_most_fails
    var = 1
    lambda do
      lambda {var += 1.1}.should change {var}.by_at_most(1)
    end.should raise_error
  end
  
  def test_change_from_to
    var = 1
    lambda {var += 1}.should change {var}.from(1).to(2)
  end
  
  def test_change_from_to_fails
    var = 1
    lambda do
      lambda {var += 1.1}.should change {var}.from(1).to(2)
    end.should raise_error
  end
    
  # include/exclude
  def test_include
    [1,2,3,4].should include(4)
  end
  
  def test_include_fail
    lambda {
      [1,2,3,4].should include(6)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_exclude
    [1,2,3,4].should exclude(9)
  end
  
  def test_exclude_fail
    lambda {
      [1,2,3,4].should exclude(4)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_multi_include
    [1,2,3,4].should include(1,2)
  end
  
  def test_multi_include_fail
    lambda {
      [1,2,3,4].should include(6,7,8)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_multi_exclude
    [1,2,3,4].should exclude(13,14)
  end
  
  def test_multi_exclude_fail
    lambda {
      [1,2,3,4].should exclude(2,3,4)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_include
    [1,2,3,4].should_not include(9)
  end
  
  def test_negative_include_fail
    lambda {
      [1,2,3,4].should_not include(4)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_exclude
    [1,2,3,4].should_not exclude(3)
  end
  
  def test_negative_exclude_fail
    lambda {
      [1,2,3,4].should_not exclude(6,7)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_include_fail_message
    obj = include(1)
    obj.matches?([4,5,6])
    
    obj.failure_message.should be("Expected [4, 5, 6] to include [1].")
  end
  
  def test_include_negative_fail_message
    obj = include(1)
    obj.matches?([4,5,6])
    
    obj.negative_failure_message.should be("Expected [4, 5, 6] to not include [1].")
  end
  
  def test_exclude_fail_message
    obj = exclude(4)
    obj.matches?([4,5,6])
    
    obj.failure_message.should be("Expected [4, 5, 6] to exclude [4].")
  end
  
  def test_exclude_negative_fail_message
    obj = exclude(4)
    obj.matches?([4,5,6])
    
    obj.negative_failure_message.should be("Expected [4, 5, 6] to not exclude [4].")
  end
  
  # raise_error
  def test_raises_error
    lambda { raise "FAIL" }.should raise_error
  end
  
  def test_raises_error_fail
    lambda {
      lambda { "WIN" }.should raise_error
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_raise_error_negative_raises_error
    lambda { "WIN" }.should_not raise_error
  end
  
  def test_raise_error_negative_raises_error_fail
    lambda {
      lambda { raise "FAIL" }.should_not raise_error
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_raise_error_raises_specific_error
    lambda { raise TypeError }.should raise_error(TypeError)
  end
  
  def test_raise_error_raises_specific_error_fail_with_no_error
    lambda {
      lambda { "WIN" }.should raise_error(TypeError)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_raise_error_raises_specific_error_fail_with_different_error
    lambda {
      lambda { raise StandardError }.should raise_error(TypeError)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_raise_error_error_fail_message
    obj = raise_error(TypeError)
    obj.matches?(lambda { raise NameError })
    
    obj.failure_message.should =~ /Expected #<(.*)> to raise TypeError, but NameError was raised instead./
  end
  
  def test_raise_error_error_fail_message_when_no_error
    obj = raise_error(TypeError)
    obj.matches?(lambda { "moop" })
    
    obj.failure_message.should =~ /Expected #<(.*)> to raise TypeError, but none was raised./
  end
  
  def test_raise_error_error_negative_fail_message
    obj = raise_error(TypeError)
    obj.matches?(lambda { raise TypeError })
    
    obj.negative_failure_message.should =~ /Expected #<(.*)> to not raise TypeError./
  end
  
  def test_raise_error_string_argument_message
    lambda {raise "message"}.should raise_error("message")
  end
  
  def test_string_argument_message_fails_no_error
    lambda do
      lambda { 1 }.should raise_error("message")
      
    end.should raise_error
  end
  
  def test_raise_error_string_argument_message_fails_wrong_message
    lambda do
      lambda { raise "other message" }.should raise_error("message")
    end.should raise_error
  end
  
  def test_raise_error_regexp_argument_message
    lambda {raise "message"}.should raise_error(/essa/)
  end
  
  def test_raise_error_regexp_argument_message_fails_no_error
    lambda do
      lambda { 1 }.should raise_error(/essa/)
    end.should raise_error
  end
  
  def test_raise_error_regexp_argument_message_fails_wrong_message
    lambda do
      lambda { raise "other message" }.should raise_error(/abc/)
    end.should raise_error(/matching/)
  end
  
  # throw
  def test_throws_symbol
    lambda {
      throw :win
    }.should throw_symbol(:win)
  end
  
  def test_throws_symbol_fails_with_different_symbol
    lambda {
      lambda {
        throw :fail
      }.should throw_symbol(:win)
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_throws_symbol
    lambda {
      "not this time!"
    }.should_not throw_symbol(:win)
  end
  
  def test_negative_throws_symbol_fails_with_different_symbol
    
    lambda{
      lambda {
        throw :fail
      }.should_not throw_symbol(:fail)
    }.should raise_error(Test::Unit::AssertionFailedError)
  
  end
  
  def test_throw_fail_message
    obj = throw_symbol(:fail)
    obj.matches?(lambda { throw :lame })
    
    obj.failure_message.should =~ /Expected #<(.*)> to throw :fail, but :lame was thrown instead./
  end
  
  def test_throw_fail_message_when_no_symbol
    obj = throw_symbol(:fail)
    obj.matches?(lambda { "moop" })
    
    obj.failure_message.should =~ /Expected #<(.*)> to throw :fail, but no symbol was thrown./
  end
  
  def test_throw_negative_fail_message
    obj = throw_symbol(:fail)
    obj.matches?(lambda { throw :fail })
    
    obj.negative_failure_message.should =~ /Expected #<(.*)> to not throw :fail./
  end
end