opal 0.7.0.beta3 → 0.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +4 -0
  3. data/.travis.yml +7 -3
  4. data/.yardopts +6 -0
  5. data/CHANGELOG.md +28 -0
  6. data/Gemfile +1 -1
  7. data/README.md +3 -12
  8. data/Rakefile +4 -150
  9. data/bin/opal-mspec +1 -1
  10. data/docs/compiler_directives.md +127 -0
  11. data/examples/rack/.gitignore +1 -0
  12. data/examples/rack/app/user.rb +1 -0
  13. data/lib/mspec/opal/special_calls.rb +15 -2
  14. data/lib/opal/builder.rb +15 -8
  15. data/lib/opal/compiler.rb +75 -4
  16. data/lib/opal/erb.rb +22 -2
  17. data/lib/opal/fragment.rb +17 -5
  18. data/lib/opal/nodes/def.rb +174 -53
  19. data/lib/opal/nodes/if.rb +14 -0
  20. data/lib/opal/nodes/module.rb +0 -1
  21. data/lib/opal/nodes/rescue.rb +10 -2
  22. data/lib/opal/nodes/scope.rb +0 -17
  23. data/lib/opal/parser.rb +83 -19
  24. data/lib/opal/parser/grammar.rb +2511 -2414
  25. data/lib/opal/parser/grammar.y +71 -9
  26. data/lib/opal/parser/lexer.rb +44 -12
  27. data/lib/opal/parser/parser_scope.rb +3 -0
  28. data/lib/opal/parser/sexp.rb +7 -1
  29. data/lib/opal/paths.rb +5 -5
  30. data/lib/opal/sprockets/environment.rb +2 -10
  31. data/lib/opal/sprockets/path_reader.rb +1 -1
  32. data/lib/opal/sprockets/processor.rb +1 -0
  33. data/lib/opal/sprockets/server.rb +2 -0
  34. data/lib/opal/util.rb +7 -2
  35. data/lib/opal/version.rb +1 -1
  36. data/opal.gemspec +1 -0
  37. data/opal/README.md +1 -1
  38. data/opal/corelib/dir.rb +1 -1
  39. data/opal/corelib/enumerable.rb +3 -1
  40. data/opal/corelib/error.rb +3 -0
  41. data/opal/corelib/file.rb +2 -0
  42. data/opal/corelib/hash.rb +3 -0
  43. data/opal/corelib/io.rb +15 -1
  44. data/opal/corelib/kernel.rb +8 -0
  45. data/opal/corelib/module.rb +42 -17
  46. data/opal/corelib/runtime.js +223 -49
  47. data/opal/corelib/string.rb +1 -1
  48. data/opal/corelib/struct.rb +1 -7
  49. data/spec/README.md +8 -0
  50. data/spec/filters/bugs/language.rb +1 -0
  51. data/spec/filters/bugs/module.rb +4 -0
  52. data/spec/filters/unsupported/frozen.rb +2 -0
  53. data/spec/lib/compiler/pre_processed_conditionals_spec.rb +87 -0
  54. data/spec/lib/compiler_spec.rb +1 -67
  55. data/spec/lib/fixtures/file_with_directives.js +2 -0
  56. data/spec/lib/fixtures/required_file.js +1 -0
  57. data/spec/lib/parser/def_spec.rb +29 -16
  58. data/spec/lib/parser/variables_spec.rb +5 -5
  59. data/spec/lib/sprockets/path_reader_spec.rb +24 -8
  60. data/spec/lib/sprockets/server_spec.rb +10 -3
  61. data/spec/opal/core/date_spec.rb +14 -0
  62. data/spec/opal/core/language/versions/def_2_0_spec.rb +62 -0
  63. data/spec/opal/core/language_spec.rb +23 -0
  64. data/spec/opal/core/runtime/donate_spec.rb +53 -0
  65. data/spec/opal/stdlib/native/native_alias_spec.rb +19 -0
  66. data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
  67. data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
  68. data/spec/rubyspecs +2 -0
  69. data/stdlib/buffer.rb +1 -0
  70. data/stdlib/date.rb +18 -0
  71. data/stdlib/encoding.rb +3 -2
  72. data/stdlib/minitest.rb +780 -0
  73. data/stdlib/minitest/assertions.rb +662 -0
  74. data/stdlib/minitest/autorun.rb +12 -0
  75. data/stdlib/minitest/benchmark.rb +426 -0
  76. data/stdlib/minitest/expectations.rb +281 -0
  77. data/stdlib/minitest/hell.rb +11 -0
  78. data/stdlib/minitest/mock.rb +220 -0
  79. data/stdlib/minitest/parallel.rb +65 -0
  80. data/stdlib/minitest/pride.rb +4 -0
  81. data/stdlib/minitest/pride_plugin.rb +142 -0
  82. data/stdlib/minitest/spec.rb +310 -0
  83. data/stdlib/minitest/test.rb +293 -0
  84. data/stdlib/minitest/unit.rb +45 -0
  85. data/stdlib/native.rb +12 -3
  86. data/stdlib/nodejs/process.rb +16 -2
  87. data/stdlib/promise.rb +99 -0
  88. data/stdlib/test/unit.rb +10 -0
  89. data/stdlib/thread.rb +4 -0
  90. data/tasks/building.rake +58 -0
  91. data/tasks/documentation.rake +38 -0
  92. data/tasks/documenting.rake +37 -0
  93. data/tasks/testing.rake +102 -0
  94. metadata +57 -2
@@ -0,0 +1,662 @@
1
+ require "rbconfig"
2
+ require "tempfile"
3
+ require 'stringio'
4
+
5
+ module Minitest
6
+ ##
7
+ # Minitest Assertions. All assertion methods accept a +msg+ which is
8
+ # printed if the assertion fails.
9
+ #
10
+ # Protocol: Nearly everything here boils up to +assert+, which
11
+ # expects to be able to increment an instance accessor named
12
+ # +assertions+. This is not provided by Assertions and must be
13
+ # provided by the thing including Assertions. See Minitest::Runnable
14
+ # for an example.
15
+
16
+ module Assertions
17
+ UNDEFINED = Object.new # :nodoc:
18
+
19
+ def UNDEFINED.inspect # :nodoc:
20
+ "UNDEFINED" # again with the rdoc bugs... :(
21
+ end
22
+
23
+ ##
24
+ # Returns the diff command to use in #diff. Tries to intelligently
25
+ # figure out what diff to use.
26
+
27
+ def self.diff
28
+ @diff = if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ &&
29
+ system("diff.exe", __FILE__, __FILE__)) then
30
+ "diff.exe -u"
31
+ elsif Minitest::Test.maglev? then
32
+ "diff -u"
33
+ elsif system("gdiff", __FILE__, __FILE__)
34
+ "gdiff -u" # solaris and kin suck
35
+ elsif system("diff", __FILE__, __FILE__)
36
+ "diff -u"
37
+ else
38
+ nil
39
+ end unless defined? @diff
40
+
41
+ @diff
42
+ end
43
+
44
+ ##
45
+ # Set the diff command to use in #diff.
46
+
47
+ def self.diff= o
48
+ @diff = o
49
+ end
50
+
51
+ ##
52
+ # Returns a diff between +exp+ and +act+. If there is no known
53
+ # diff command or if it doesn't make sense to diff the output
54
+ # (single line, short output), then it simply returns a basic
55
+ # comparison between the two.
56
+
57
+ def diff exp, act
58
+ expect = mu_pp_for_diff exp
59
+ butwas = mu_pp_for_diff act
60
+ result = nil
61
+
62
+ need_to_diff = false
63
+ # (expect.include?("\n") ||
64
+ # butwas.include?("\n") ||
65
+ # expect.size > 30 ||
66
+ # butwas.size > 30 ||
67
+ # expect == butwas) &&
68
+ # Minitest::Assertions.diff
69
+
70
+
71
+ return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
72
+ need_to_diff
73
+
74
+ # Tempfile.open("expect") do |a|
75
+ # a.puts expect
76
+ # a.flush
77
+ #
78
+ # Tempfile.open("butwas") do |b|
79
+ # b.puts butwas
80
+ # b.flush
81
+ #
82
+ # result = `#{Minitest::Assertions.diff} #{a.path} #{b.path}`
83
+ # result.sub!(/^\-\-\- .+/, "--- expected")
84
+ # result.sub!(/^\+\+\+ .+/, "+++ actual")
85
+ #
86
+ # if result.empty? then
87
+ # klass = exp.class
88
+ # result = [
89
+ # "No visible difference in the #{klass}#inspect output.\n",
90
+ # "You should look at the implementation of #== on ",
91
+ # "#{klass} or its members.\n",
92
+ # expect,
93
+ # ].join
94
+ # end
95
+ # end
96
+ # end
97
+
98
+ result
99
+ end
100
+
101
+ ##
102
+ # This returns a human-readable version of +obj+. By default
103
+ # #inspect is called. You can override this to use #pretty_print
104
+ # if you want.
105
+
106
+ def mu_pp obj
107
+ s = obj.inspect
108
+ s = s.encode Encoding.default_external if defined? Encoding
109
+ s
110
+ end
111
+
112
+ ##
113
+ # This returns a diff-able human-readable version of +obj+. This
114
+ # differs from the regular mu_pp because it expands escaped
115
+ # newlines and makes hex-values generic (like object_ids). This
116
+ # uses mu_pp to do the first pass and then cleans it up.
117
+
118
+ def mu_pp_for_diff obj
119
+ mu_pp(obj).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ':0xXXXXXX')
120
+ end
121
+
122
+ ##
123
+ # Fails unless +test+ is truthy.
124
+
125
+ def assert test, msg = nil
126
+ self.assertions += 1
127
+ unless test then
128
+ msg ||= "Failed assertion, no message given."
129
+ msg = msg.call if Proc === msg
130
+ raise Minitest::Assertion, msg
131
+ end
132
+ true
133
+ end
134
+
135
+ def _synchronize # :nodoc:
136
+ yield
137
+ end
138
+
139
+ ##
140
+ # Fails unless +obj+ is empty.
141
+
142
+ def assert_empty obj, msg = nil
143
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be empty" }
144
+ assert_respond_to obj, :empty?
145
+ assert obj.empty?, msg
146
+ end
147
+
148
+ E = "" # :nodoc:
149
+
150
+ ##
151
+ # Fails unless <tt>exp == act</tt> printing the difference between
152
+ # the two, if possible.
153
+ #
154
+ # If there is no visible difference but the assertion fails, you
155
+ # should suspect that your #== is buggy, or your inspect output is
156
+ # missing crucial details.
157
+ #
158
+ # For floats use assert_in_delta.
159
+ #
160
+ # See also: Minitest::Assertions.diff
161
+
162
+ def assert_equal exp, act, msg = nil
163
+ msg = message(msg, E) { diff exp, act }
164
+ assert exp == act, msg
165
+ end
166
+
167
+ ##
168
+ # For comparing Floats. Fails unless +exp+ and +act+ are within +delta+
169
+ # of each other.
170
+ #
171
+ # assert_in_delta Math::PI, (22.0 / 7.0), 0.01
172
+
173
+ def assert_in_delta exp, act, delta = 0.001, msg = nil
174
+ n = (exp - act).abs
175
+ msg = message(msg) {
176
+ "Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
177
+ }
178
+ assert delta >= n, msg
179
+ end
180
+
181
+ ##
182
+ # For comparing Floats. Fails unless +exp+ and +act+ have a relative
183
+ # error less than +epsilon+.
184
+
185
+ def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
186
+ assert_in_delta a, b, [a.abs, b.abs].min * epsilon, msg
187
+ end
188
+
189
+ ##
190
+ # Fails unless +collection+ includes +obj+.
191
+
192
+ def assert_includes collection, obj, msg = nil
193
+ msg = message(msg) {
194
+ "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}"
195
+ }
196
+ assert_respond_to collection, :include?
197
+ assert collection.include?(obj), msg
198
+ end
199
+
200
+ ##
201
+ # Fails unless +obj+ is an instance of +cls+.
202
+
203
+ def assert_instance_of cls, obj, msg = nil
204
+ msg = message(msg) {
205
+ "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}"
206
+ }
207
+
208
+ assert obj.instance_of?(cls), msg
209
+ end
210
+
211
+ ##
212
+ # Fails unless +obj+ is a kind of +cls+.
213
+
214
+ def assert_kind_of cls, obj, msg = nil
215
+ msg = message(msg) {
216
+ "Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
217
+
218
+ assert obj.kind_of?(cls), msg
219
+ end
220
+
221
+ ##
222
+ # Fails unless +matcher+ <tt>=~</tt> +obj+.
223
+
224
+ def assert_match matcher, obj, msg = nil
225
+ msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
226
+ assert_respond_to matcher, :"=~"
227
+ matcher = Regexp.new Regexp.escape matcher if String === matcher
228
+ assert matcher =~ obj, msg
229
+ end
230
+
231
+ ##
232
+ # Fails unless +obj+ is nil
233
+
234
+ def assert_nil obj, msg = nil
235
+ msg = message(msg) { "Expected #{mu_pp(obj)} to be nil" }
236
+ assert obj.nil?, msg
237
+ end
238
+
239
+ ##
240
+ # For testing with binary operators. Eg:
241
+ #
242
+ # assert_operator 5, :<=, 4
243
+
244
+ def assert_operator o1, op, o2 = UNDEFINED, msg = nil
245
+ return assert_predicate o1, op, msg if UNDEFINED == o2
246
+ msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" }
247
+ assert o1.__send__(op, o2), msg
248
+ end
249
+
250
+ ##
251
+ # Fails if stdout or stderr do not output the expected results.
252
+ # Pass in nil if you don't care about that streams output. Pass in
253
+ # "" if you require it to be silent. Pass in a regexp if you want
254
+ # to pattern match.
255
+ #
256
+ # NOTE: this uses #capture_io, not #capture_subprocess_io.
257
+ #
258
+ # See also: #assert_silent
259
+
260
+ def assert_output stdout = nil, stderr = nil
261
+ out, err = capture_io do
262
+ yield
263
+ end
264
+
265
+ err_msg = Regexp === stderr ? :assert_match : :assert_equal if stderr
266
+ out_msg = Regexp === stdout ? :assert_match : :assert_equal if stdout
267
+
268
+ y = send err_msg, stderr, err, "In stderr" if err_msg
269
+ x = send out_msg, stdout, out, "In stdout" if out_msg
270
+
271
+ (!stdout || x) && (!stderr || y)
272
+ end
273
+
274
+ ##
275
+ # For testing with predicates. Eg:
276
+ #
277
+ # assert_predicate str, :empty?
278
+ #
279
+ # This is really meant for specs and is front-ended by assert_operator:
280
+ #
281
+ # str.must_be :empty?
282
+
283
+ def assert_predicate o1, op, msg = nil
284
+ msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op}" }
285
+ assert o1.__send__(op), msg
286
+ end
287
+
288
+ ##
289
+ # Fails unless the block raises one of +exp+. Returns the
290
+ # exception matched so you can check the message, attributes, etc.
291
+
292
+ def assert_raises *exp
293
+ msg = "#{exp.pop}.\n" if String === exp.last
294
+
295
+ begin
296
+ yield
297
+ rescue Minitest::Skip => e
298
+ return e if exp.include? Minitest::Skip
299
+ raise e
300
+ rescue Exception => e
301
+ expected = exp.any? { |ex|
302
+ if ex.instance_of? Module then
303
+ e.kind_of? ex
304
+ else
305
+ e.instance_of? ex
306
+ end
307
+ }
308
+
309
+ assert expected, proc {
310
+ exception_details(e, "#{msg}#{mu_pp(exp)} exception expected, not")
311
+ }
312
+
313
+ return e
314
+ end
315
+
316
+ exp = exp.first if exp.size == 1
317
+
318
+ flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised."
319
+ end
320
+
321
+ ##
322
+ # Fails unless +obj+ responds to +meth+.
323
+
324
+ def assert_respond_to obj, meth, msg = nil
325
+ msg = message(msg) {
326
+ "Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
327
+ }
328
+ assert obj.respond_to?(meth), msg
329
+ end
330
+
331
+ ##
332
+ # Fails unless +exp+ and +act+ are #equal?
333
+
334
+ def assert_same exp, act, msg = nil
335
+ msg = message(msg) {
336
+ data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
337
+ "Expected %s (oid=%d) to be the same as %s (oid=%d)" % data
338
+ }
339
+ assert exp.equal?(act), msg
340
+ end
341
+
342
+ ##
343
+ # +send_ary+ is a receiver, message and arguments.
344
+ #
345
+ # Fails unless the call returns a true value
346
+
347
+ def assert_send send_ary, m = nil
348
+ recv, msg, *args = send_ary
349
+ m = message(m) {
350
+ "Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
351
+ assert recv.__send__(msg, *args), m
352
+ end
353
+
354
+ ##
355
+ # Fails if the block outputs anything to stderr or stdout.
356
+ #
357
+ # See also: #assert_output
358
+
359
+ def assert_silent
360
+ assert_output "", "" do
361
+ yield
362
+ end
363
+ end
364
+
365
+ ##
366
+ # Fails unless the block throws +sym+
367
+
368
+ def assert_throws sym, msg = nil
369
+ default = "Expected #{mu_pp(sym)} to have been thrown"
370
+ caught = true
371
+ catch(sym) do
372
+ begin
373
+ yield
374
+ rescue ThreadError => e # wtf?!? 1.8 + threads == suck
375
+ default += ", not \:#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
376
+ rescue ArgumentError => e # 1.9 exception
377
+ default += ", not #{e.message.split(/ /).last}"
378
+ rescue NameError => e # 1.8 exception
379
+ default += ", not #{e.name.inspect}"
380
+ end
381
+ caught = false
382
+ end
383
+
384
+ assert caught, message(msg) { default }
385
+ end
386
+
387
+ ##
388
+ # Captures $stdout and $stderr into strings:
389
+ #
390
+ # out, err = capture_io do
391
+ # puts "Some info"
392
+ # warn "You did a bad thing"
393
+ # end
394
+ #
395
+ # assert_match %r%info%, out
396
+ # assert_match %r%bad%, err
397
+ #
398
+ # NOTE: For efficiency, this method uses StringIO and does not
399
+ # capture IO for subprocesses. Use #capture_subprocess_io for
400
+ # that.
401
+
402
+ def capture_io
403
+ _synchronize do
404
+ begin
405
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
406
+
407
+ orig_stdout, orig_stderr = $stdout, $stderr
408
+ $stdout, $stderr = captured_stdout, captured_stderr
409
+
410
+ yield
411
+
412
+ return captured_stdout.string, captured_stderr.string
413
+ ensure
414
+ $stdout = orig_stdout
415
+ $stderr = orig_stderr
416
+ end
417
+ end
418
+ end
419
+
420
+ ##
421
+ # Captures $stdout and $stderr into strings, using Tempfile to
422
+ # ensure that subprocess IO is captured as well.
423
+ #
424
+ # out, err = capture_subprocess_io do
425
+ # system "echo Some info"
426
+ # system "echo You did a bad thing 1>&2"
427
+ # end
428
+ #
429
+ # assert_match %r%info%, out
430
+ # assert_match %r%bad%, err
431
+ #
432
+ # NOTE: This method is approximately 10x slower than #capture_io so
433
+ # only use it when you need to test the output of a subprocess.
434
+
435
+ def capture_subprocess_io
436
+ _synchronize do
437
+ begin
438
+ require 'tempfile'
439
+
440
+ captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
441
+
442
+ orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
443
+ $stdout.reopen captured_stdout
444
+ $stderr.reopen captured_stderr
445
+
446
+ yield
447
+
448
+ $stdout.rewind
449
+ $stderr.rewind
450
+
451
+ return captured_stdout.read, captured_stderr.read
452
+ ensure
453
+ captured_stdout.unlink
454
+ captured_stderr.unlink
455
+ $stdout.reopen orig_stdout
456
+ $stderr.reopen orig_stderr
457
+ end
458
+ end
459
+ end
460
+
461
+ ##
462
+ # Returns details for exception +e+
463
+
464
+ def exception_details e, msg
465
+ [
466
+ "#{msg}",
467
+ "Class: <#{e.class}>",
468
+ "Message: <#{e.message.inspect}>",
469
+ "---Backtrace---",
470
+ "#{Minitest::filter_backtrace(e.backtrace).join("\n")}",
471
+ "---------------",
472
+ ].join "\n"
473
+ end
474
+
475
+ ##
476
+ # Fails with +msg+
477
+
478
+ def flunk msg = nil
479
+ msg ||= "Epic Fail!"
480
+ assert false, msg
481
+ end
482
+
483
+ ##
484
+ # Returns a proc that will output +msg+ along with the default message.
485
+
486
+ def message msg = nil, ending = nil, &default
487
+ proc {
488
+ msg = msg.call.chomp(".") if Proc === msg
489
+ custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
490
+ "#{custom_message}#{default.call}#{ending || "."}"
491
+ }
492
+ end
493
+
494
+ ##
495
+ # used for counting assertions
496
+
497
+ def pass msg = nil
498
+ assert true
499
+ end
500
+
501
+ ##
502
+ # Fails if +test+ is truthy.
503
+
504
+ def refute test, msg = nil
505
+ msg ||= "Failed refutation, no message given"
506
+ not assert(! test, msg)
507
+ end
508
+
509
+ ##
510
+ # Fails if +obj+ is empty.
511
+
512
+ def refute_empty obj, msg = nil
513
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not be empty" }
514
+ assert_respond_to obj, :empty?
515
+ refute obj.empty?, msg
516
+ end
517
+
518
+ ##
519
+ # Fails if <tt>exp == act</tt>.
520
+ #
521
+ # For floats use refute_in_delta.
522
+
523
+ def refute_equal exp, act, msg = nil
524
+ msg = message(msg) {
525
+ "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}"
526
+ }
527
+ refute exp == act, msg
528
+ end
529
+
530
+ ##
531
+ # For comparing Floats. Fails if +exp+ is within +delta+ of +act+.
532
+ #
533
+ # refute_in_delta Math::PI, (22.0 / 7.0)
534
+
535
+ def refute_in_delta exp, act, delta = 0.001, msg = nil
536
+ n = (exp - act).abs
537
+ msg = message(msg) {
538
+ "Expected |#{exp} - #{act}| (#{n}) to not be <= #{delta}"
539
+ }
540
+ refute delta >= n, msg
541
+ end
542
+
543
+ ##
544
+ # For comparing Floats. Fails if +exp+ and +act+ have a relative error
545
+ # less than +epsilon+.
546
+
547
+ def refute_in_epsilon a, b, epsilon = 0.001, msg = nil
548
+ refute_in_delta a, b, a * epsilon, msg
549
+ end
550
+
551
+ ##
552
+ # Fails if +collection+ includes +obj+.
553
+
554
+ def refute_includes collection, obj, msg = nil
555
+ msg = message(msg) {
556
+ "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}"
557
+ }
558
+ assert_respond_to collection, :include?
559
+ refute collection.include?(obj), msg
560
+ end
561
+
562
+ ##
563
+ # Fails if +obj+ is an instance of +cls+.
564
+
565
+ def refute_instance_of cls, obj, msg = nil
566
+ msg = message(msg) {
567
+ "Expected #{mu_pp(obj)} to not be an instance of #{cls}"
568
+ }
569
+ refute obj.instance_of?(cls), msg
570
+ end
571
+
572
+ ##
573
+ # Fails if +obj+ is a kind of +cls+.
574
+
575
+ def refute_kind_of cls, obj, msg = nil
576
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
577
+ refute obj.kind_of?(cls), msg
578
+ end
579
+
580
+ ##
581
+ # Fails if +matcher+ <tt>=~</tt> +obj+.
582
+
583
+ def refute_match matcher, obj, msg = nil
584
+ msg = message(msg) {"Expected #{mu_pp matcher} to not match #{mu_pp obj}"}
585
+ assert_respond_to matcher, :"=~"
586
+ matcher = Regexp.new Regexp.escape matcher if String === matcher
587
+ refute matcher =~ obj, msg
588
+ end
589
+
590
+ ##
591
+ # Fails if +obj+ is nil.
592
+
593
+ def refute_nil obj, msg = nil
594
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not be nil" }
595
+ refute obj.nil?, msg
596
+ end
597
+
598
+ ##
599
+ # Fails if +o1+ is not +op+ +o2+. Eg:
600
+ #
601
+ # refute_operator 1, :>, 2 #=> pass
602
+ # refute_operator 1, :<, 2 #=> fail
603
+
604
+ def refute_operator o1, op, o2 = UNDEFINED, msg = nil
605
+ return refute_predicate o1, op, msg if UNDEFINED == o2
606
+ msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}"}
607
+ refute o1.__send__(op, o2), msg
608
+ end
609
+
610
+ ##
611
+ # For testing with predicates.
612
+ #
613
+ # refute_predicate str, :empty?
614
+ #
615
+ # This is really meant for specs and is front-ended by refute_operator:
616
+ #
617
+ # str.wont_be :empty?
618
+
619
+ def refute_predicate o1, op, msg = nil
620
+ msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op}" }
621
+ refute o1.__send__(op), msg
622
+ end
623
+
624
+ ##
625
+ # Fails if +obj+ responds to the message +meth+.
626
+
627
+ def refute_respond_to obj, meth, msg = nil
628
+ msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
629
+
630
+ refute obj.respond_to?(meth), msg
631
+ end
632
+
633
+ ##
634
+ # Fails if +exp+ is the same (by object identity) as +act+.
635
+
636
+ def refute_same exp, act, msg = nil
637
+ msg = message(msg) {
638
+ data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
639
+ "Expected %s (oid=%d) to not be the same as %s (oid=%d)" % data
640
+ }
641
+ refute exp.equal?(act), msg
642
+ end
643
+
644
+ ##
645
+ # Skips the current run. If run in verbose-mode, the skipped run
646
+ # gets listed at the end of the run but doesn't cause a failure
647
+ # exit code.
648
+
649
+ def skip msg = nil, bt = caller
650
+ msg ||= "Skipped, no message given"
651
+ @skip = true
652
+ raise Minitest::Skip, msg, bt
653
+ end
654
+
655
+ ##
656
+ # Was this testcase skipped? Meant for #teardown.
657
+
658
+ def skipped?
659
+ defined?(@skip) and @skip
660
+ end
661
+ end
662
+ end