mcmire-matchy 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,7 @@
1
+ dir = File.dirname(__FILE__)
2
+ Dir[File.expand_path("#{dir}/*.rb")].uniq.each do |file|
3
+ if file =~ /\/test_\w+\.rb$/
4
+ puts file
5
+ require file
6
+ end
7
+ end
@@ -0,0 +1,541 @@
1
+ # Eval this file with ruby 1.9
2
+
3
+ require 'test/unit'
4
+ require File.dirname(__FILE__) + '/../lib/matchy.rb'
5
+ class TestAThing < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @obj = Object.new
9
+ end
10
+
11
+ # ==
12
+ def test_operator_eql_eql
13
+ 1.should == 1
14
+ end
15
+
16
+ def test_operator_eql_eql_fails
17
+ lambda {1.should == 2}.should raise_error
18
+ end
19
+
20
+ def test_operator_eql_eql_negative
21
+ 1.should_not == 2
22
+ end
23
+
24
+ def test_operator_eql_eql_negative_fails
25
+ lambda {1.should_not == 1}.should raise_error
26
+ end
27
+
28
+ # ===
29
+ def test_operator_eql_eql_eql
30
+ 1.should === 1
31
+ end
32
+
33
+ def test_operator_eql_eql_eql_fails
34
+ lambda {1.should === 2}.should raise_error
35
+ end
36
+
37
+ def test_operator_eql_eql_eql_negative
38
+ 1.should_not === 2
39
+ end
40
+
41
+ def test_operator_eql_eql_eql_negative_fails
42
+ lambda {1.should_not === 1}.should raise_error
43
+ end
44
+
45
+ # =~
46
+ def test_operator_eql_match
47
+ "string".should =~ /in/
48
+ end
49
+
50
+ def test_operator_eql_match_fails
51
+ lambda {"string".should =~ /an/}.should raise_error
52
+ end
53
+
54
+ def test_operator_eql_match_negative
55
+ "string".should_not =~ /an/
56
+ end
57
+
58
+ def test_operator_eql_match_negative_fails
59
+ lambda {"string".should_not =~ /in/}.should raise_error
60
+ end
61
+
62
+ # <=
63
+ def test_operator_lt_eql
64
+ 1.should <= 2
65
+ end
66
+
67
+ def test_operator_lt_eql_fails
68
+ lambda {1.should <= 0}.should raise_error
69
+ end
70
+
71
+ def test_operator_lt_eql_negative
72
+ 1.should_not <= 0
73
+ end
74
+
75
+ def test_operator_lt_eql_negative_fails
76
+ lambda {1.should_not <= 2}.should raise_error
77
+ end
78
+
79
+ # >=
80
+ def test_operator_gt_eql
81
+ 1.should >= 0
82
+ end
83
+
84
+ def test_operator_gt_eql_fails
85
+ lambda {1.should >= 2}.should raise_error
86
+ end
87
+
88
+ def test_operator_gt_eql_negative
89
+ 1.should_not >= 2
90
+ end
91
+
92
+ def test_operator_gt_eql_negative_fails
93
+ lambda {1.should_not >= 0}.should raise_error
94
+ end
95
+
96
+ # <
97
+ def test_operator_lt
98
+ 1.should < 2
99
+ end
100
+
101
+ def test_operator_lt_fails
102
+ lambda {1.should < 0}.should raise_error
103
+ end
104
+
105
+ def test_operator_lt_negative
106
+ 1.should_not < 0
107
+ end
108
+
109
+ def test_operator_lt_negative_fails
110
+ lambda {1.should_not < 2}.should raise_error
111
+ end
112
+
113
+ # >
114
+ def test_operator_gt
115
+ 1.should > 0
116
+ end
117
+
118
+ def test_operator_gt_fails
119
+ lambda {1.should > 2}.should raise_error
120
+ end
121
+
122
+ def test_operator_gt_negative
123
+ 1.should_not > 2
124
+ end
125
+
126
+ def test_operator_gt_negative_fails
127
+ lambda {1.should_not > 0}.should raise_error
128
+ end
129
+
130
+ # be()
131
+ def test_be
132
+ 1.should be(1)
133
+ end
134
+
135
+ def test_be_fails
136
+ lambda {1.should be(2)}.should raise_error
137
+ end
138
+
139
+ def test_be_negative
140
+ 1.should_not be(2)
141
+ end
142
+
143
+ def test_be_negative_fails
144
+ lambda {1.should_not be(1)}.should raise_error
145
+ end
146
+
147
+ # be_something
148
+ def test_positive_be_something_method_missing_pass
149
+ def @obj.something?
150
+ true
151
+ end
152
+ @obj.should be_something
153
+ end
154
+
155
+ def test_positive_be_something_method_missing_fails
156
+ def @obj.something?
157
+ false
158
+ end
159
+ lambda {@obj.should be_something}.should raise_error(Test::Unit::AssertionFailedError)
160
+ end
161
+
162
+ def test_negative_be_something_method_missing_pass
163
+ def @obj.something?
164
+ false
165
+ end
166
+ @obj.should_not be_something
167
+ end
168
+
169
+ def test_negative_be_something_method_missing_fails
170
+ def @obj.something?
171
+ true
172
+ end
173
+ lambda {@obj.should_not be_something}.should raise_error(Test::Unit::AssertionFailedError)
174
+ end
175
+
176
+ def test_be_something_method_missing_fail_message
177
+ obj = "foo"
178
+ def obj.something?
179
+ true
180
+ end
181
+ matcher_obj = be_something
182
+ obj.should matcher_obj
183
+
184
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with 'no args'.")
185
+ end
186
+
187
+ def test_be_something_method_missing_negative_fail_message
188
+ obj = "foo"
189
+ def obj.something?
190
+ false
191
+ end
192
+ matcher_obj = be_something
193
+ obj.should_not matcher_obj
194
+
195
+ matcher_obj.negative_failure_message.should =~ /Expected \"foo\" to not return true for something?/
196
+ end
197
+
198
+ # be_something(arg)
199
+ def test_positive_be_something_with_arg_method_missing_pass
200
+ def @obj.something?(arg)
201
+ true
202
+ end
203
+ @obj.should be_something(1)
204
+ end
205
+
206
+ def test_positive_be_something_with_arg_method_missing_fails
207
+ def @obj.something?(arg)
208
+ false
209
+ end
210
+ lambda {@obj.should be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
211
+ end
212
+
213
+ def test_negative_be_something_method_missing_pass
214
+ def @obj.something?(arg)
215
+ false
216
+ end
217
+ @obj.should_not be_something(1)
218
+ end
219
+
220
+ def test_negative_be_something_method_missing_fails
221
+ def @obj.something?(arg)
222
+ true
223
+ end
224
+ lambda {@obj.should_not be_something(1)}.should raise_error(Test::Unit::AssertionFailedError)
225
+ end
226
+
227
+ def test_be_something_method_missing_fail_message
228
+ obj = "foo"
229
+ def obj.something?(arg)
230
+ true
231
+ end
232
+ matcher_obj = be_something(1)
233
+ obj.should matcher_obj
234
+
235
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with '1'.")
236
+ end
237
+
238
+ def test_be_something_method_missing_negative_fail_message
239
+ obj = "foo"
240
+ def obj.something?(arg)
241
+ false
242
+ end
243
+ matcher_obj = be_something(1)
244
+ obj.should_not matcher_obj
245
+
246
+ matcher_obj.negative_failure_message.should be("Expected \"foo\" to not return true for something?, with '1'.")
247
+ end
248
+
249
+ # change
250
+ def test_change
251
+ var = 1
252
+ lambda {var += 1}.should change {var}
253
+ end
254
+
255
+ def test_change_fails
256
+ var = 1
257
+ lambda do
258
+ lambda { }.should change {var}
259
+ end.should raise_error
260
+ end
261
+
262
+ def test_change_by
263
+ var = 1
264
+ lambda {var += 1}.should change {var}.by(1)
265
+ end
266
+
267
+ def test_change_by_fails
268
+ var = 1
269
+ lambda do
270
+ lambda {var += 2}.should change {var}.by(1)
271
+ end.should raise_error
272
+ end
273
+
274
+ def test_change_by_at_least
275
+ var = 1
276
+ lambda {var += 1}.should change {var}.by_at_least(1)
277
+ end
278
+
279
+ def test_change_by_at_least_fails
280
+ var = 1
281
+ lambda do
282
+ lambda {var += 0.9}.should change {var}.by_at_least(1)
283
+ end.should raise_error
284
+ end
285
+
286
+ def test_change_by_at_most
287
+ var = 1
288
+ lambda {var += 1}.should change {var}.by_at_most(1)
289
+ end
290
+
291
+ def test_change_by_at_most_fails
292
+ var = 1
293
+ lambda do
294
+ lambda {var += 1.1}.should change {var}.by_at_most(1)
295
+ end.should raise_error
296
+ end
297
+
298
+ def test_change_from_to
299
+ var = 1
300
+ lambda {var += 1}.should change {var}.from(1).to(2)
301
+ end
302
+
303
+ def test_change_from_to_fails
304
+ var = 1
305
+ lambda do
306
+ lambda {var += 1.1}.should change {var}.from(1).to(2)
307
+ end.should raise_error
308
+ end
309
+
310
+ # include/exclude
311
+ def test_include
312
+ [1,2,3,4].should include(4)
313
+ end
314
+
315
+ def test_include_fail
316
+ lambda {
317
+ [1,2,3,4].should include(6)
318
+ }.should raise_error(Test::Unit::AssertionFailedError)
319
+ end
320
+
321
+ def test_exclude
322
+ [1,2,3,4].should exclude(9)
323
+ end
324
+
325
+ def test_exclude_fail
326
+ lambda {
327
+ [1,2,3,4].should exclude(4)
328
+ }.should raise_error(Test::Unit::AssertionFailedError)
329
+ end
330
+
331
+ def test_multi_include
332
+ [1,2,3,4].should include(1,2)
333
+ end
334
+
335
+ def test_multi_include_fail
336
+ lambda {
337
+ [1,2,3,4].should include(6,7,8)
338
+ }.should raise_error(Test::Unit::AssertionFailedError)
339
+ end
340
+
341
+ def test_multi_exclude
342
+ [1,2,3,4].should exclude(13,14)
343
+ end
344
+
345
+ def test_multi_exclude_fail
346
+ lambda {
347
+ [1,2,3,4].should exclude(2,3,4)
348
+ }.should raise_error(Test::Unit::AssertionFailedError)
349
+ end
350
+
351
+ def test_negative_include
352
+ [1,2,3,4].should_not include(9)
353
+ end
354
+
355
+ def test_negative_include_fail
356
+ lambda {
357
+ [1,2,3,4].should_not include(4)
358
+ }.should raise_error(Test::Unit::AssertionFailedError)
359
+ end
360
+
361
+ def test_negative_exclude
362
+ [1,2,3,4].should_not exclude(3)
363
+ end
364
+
365
+ def test_negative_exclude_fail
366
+ lambda {
367
+ [1,2,3,4].should_not exclude(6,7)
368
+ }.should raise_error(Test::Unit::AssertionFailedError)
369
+ end
370
+
371
+ def test_include_fail_message
372
+ obj = include(1)
373
+ obj.matches?([4,5,6])
374
+
375
+ obj.failure_message.should be("Expected [4, 5, 6] to include [1].")
376
+ end
377
+
378
+ def test_include_negative_fail_message
379
+ obj = include(1)
380
+ obj.matches?([4,5,6])
381
+
382
+ obj.negative_failure_message.should be("Expected [4, 5, 6] to not include [1].")
383
+ end
384
+
385
+ def test_exclude_fail_message
386
+ obj = exclude(4)
387
+ obj.matches?([4,5,6])
388
+
389
+ obj.failure_message.should be("Expected [4, 5, 6] to exclude [4].")
390
+ end
391
+
392
+ def test_exclude_negative_fail_message
393
+ obj = exclude(4)
394
+ obj.matches?([4,5,6])
395
+
396
+ obj.negative_failure_message.should be("Expected [4, 5, 6] to not exclude [4].")
397
+ end
398
+
399
+ # raise_error
400
+ def test_raises_error
401
+ lambda { raise "FAIL" }.should raise_error
402
+ end
403
+
404
+ def test_raises_error_fail
405
+ lambda {
406
+ lambda { "WIN" }.should raise_error
407
+ }.should raise_error(Test::Unit::AssertionFailedError)
408
+ end
409
+
410
+ def test_raise_error_negative_raises_error
411
+ lambda { "WIN" }.should_not raise_error
412
+ end
413
+
414
+ def test_raise_error_negative_raises_error_fail
415
+ lambda {
416
+ lambda { raise "FAIL" }.should_not raise_error
417
+ }.should raise_error(Test::Unit::AssertionFailedError)
418
+ end
419
+
420
+ def test_raise_error_raises_specific_error
421
+ lambda { raise TypeError }.should raise_error(TypeError)
422
+ end
423
+
424
+ def test_raise_error_raises_specific_error_fail_with_no_error
425
+ lambda {
426
+ lambda { "WIN" }.should raise_error(TypeError)
427
+ }.should raise_error(Test::Unit::AssertionFailedError)
428
+ end
429
+
430
+ def test_raise_error_raises_specific_error_fail_with_different_error
431
+ lambda {
432
+ lambda { raise StandardError }.should raise_error(TypeError)
433
+ }.should raise_error(Test::Unit::AssertionFailedError)
434
+ end
435
+
436
+ def test_raise_error_error_fail_message
437
+ obj = raise_error(TypeError)
438
+ obj.matches?(lambda { raise NameError })
439
+
440
+ obj.failure_message.should =~ /Expected #<(.*)> to raise TypeError, but NameError was raised instead./
441
+ end
442
+
443
+ def test_raise_error_error_fail_message_when_no_error
444
+ obj = raise_error(TypeError)
445
+ obj.matches?(lambda { "moop" })
446
+
447
+ obj.failure_message.should =~ /Expected #<(.*)> to raise TypeError, but none was raised./
448
+ end
449
+
450
+ def test_raise_error_error_negative_fail_message
451
+ obj = raise_error(TypeError)
452
+ obj.matches?(lambda { raise TypeError })
453
+
454
+ obj.negative_failure_message.should =~ /Expected #<(.*)> to not raise TypeError./
455
+ end
456
+
457
+ def test_raise_error_string_argument_message
458
+ lambda {raise "message"}.should raise_error("message")
459
+ end
460
+
461
+ def test_string_argument_message_fails_no_error
462
+ lambda do
463
+ lambda { 1 }.should raise_error("message")
464
+
465
+ end.should raise_error
466
+ end
467
+
468
+ def test_raise_error_string_argument_message_fails_wrong_message
469
+ lambda do
470
+ lambda { raise "other message" }.should raise_error("message")
471
+ end.should raise_error
472
+ end
473
+
474
+ def test_raise_error_regexp_argument_message
475
+ lambda {raise "message"}.should raise_error(/essa/)
476
+ end
477
+
478
+ def test_raise_error_regexp_argument_message_fails_no_error
479
+ lambda do
480
+ lambda { 1 }.should raise_error(/essa/)
481
+ end.should raise_error
482
+ end
483
+
484
+ def test_raise_error_regexp_argument_message_fails_wrong_message
485
+ lambda do
486
+ lambda { raise "other message" }.should raise_error(/abc/)
487
+ end.should raise_error(/matching/)
488
+ end
489
+
490
+ # throw
491
+ def test_throws_symbol
492
+ lambda {
493
+ throw :win
494
+ }.should throw_symbol(:win)
495
+ end
496
+
497
+ def test_throws_symbol_fails_with_different_symbol
498
+ lambda {
499
+ lambda {
500
+ throw :fail
501
+ }.should throw_symbol(:win)
502
+ }.should raise_error(Test::Unit::AssertionFailedError)
503
+ end
504
+
505
+ def test_negative_throws_symbol
506
+ lambda {
507
+ "not this time!"
508
+ }.should_not throw_symbol(:win)
509
+ end
510
+
511
+ def test_negative_throws_symbol_fails_with_different_symbol
512
+
513
+ lambda{
514
+ lambda {
515
+ throw :fail
516
+ }.should_not throw_symbol(:fail)
517
+ }.should raise_error(Test::Unit::AssertionFailedError)
518
+
519
+ end
520
+
521
+ def test_throw_fail_message
522
+ obj = throw_symbol(:fail)
523
+ obj.matches?(lambda { throw :lame })
524
+
525
+ obj.failure_message.should =~ /Expected #<(.*)> to throw :fail, but :lame was thrown instead./
526
+ end
527
+
528
+ def test_throw_fail_message_when_no_symbol
529
+ obj = throw_symbol(:fail)
530
+ obj.matches?(lambda { "moop" })
531
+
532
+ obj.failure_message.should =~ /Expected #<(.*)> to throw :fail, but no symbol was thrown./
533
+ end
534
+
535
+ def test_throw_negative_fail_message
536
+ obj = throw_symbol(:fail)
537
+ obj.matches?(lambda { throw :fail })
538
+
539
+ obj.negative_failure_message.should =~ /Expected #<(.*)> to not throw :fail./
540
+ end
541
+ end