miniunit 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,15 @@
1
+ === 1.2.1 / 2008-06-10
2
+
3
+ * 7 minor enhancements:
4
+
5
+ * Added deprecations everywhere in test/unit.
6
+ * Added test_order to TestCase. :random on mini, :sorted on test/unit (for now).
7
+ * Big cleanup in test/unit for rails. Thanks Jeremy Kemper!
8
+ * Minor readability cleanup.
9
+ * Pushed setup/run/teardown down to testcase allowing specialized testcases.
10
+ * Removed pp. Tests run 2x faster. :/
11
+ * Renamed deprecation methods and moved to test/unit/deprecate.rb.
12
+
1
13
  === 1.2.0 / 2008-06-09
2
14
 
3
15
  * 2 major enhancements:
@@ -9,6 +9,7 @@ lib/mini/spec.rb
9
9
  lib/mini/test.rb
10
10
  lib/test/unit.rb
11
11
  lib/test/unit/assertions.rb
12
+ lib/test/unit/deprecate.rb
12
13
  lib/test/unit/error.rb
13
14
  lib/test/unit/testcase.rb
14
15
  test/test_mini_mock.rb
@@ -32,7 +32,8 @@ class Module
32
32
  end
33
33
 
34
34
  Object.infect_with_assertions(:must, :wont,
35
- /^(must|wont)$|wont_(throw)|must_(block|not?_|nothing)/,
35
+ /^(must|wont)$|wont_(throw)|
36
+ must_(block|not?_|nothing|raise$)/x,
36
37
  /(must_throw)s/ => '\1',
37
38
  /(?!not)_same/ => '_be_same_as',
38
39
  /_in_/ => '_be_within_',
@@ -36,15 +36,8 @@ module Mini
36
36
  end
37
37
 
38
38
  module Assertions
39
- begin
40
- require 'pp'
41
- def mu_pp(obj)
42
- PP.pp(obj, '').chomp
43
- end
44
- rescue LoadError
45
- def mu_pp(obj)
46
- obj.inspect
47
- end
39
+ def mu_pp(obj)
40
+ obj.inspect
48
41
  end
49
42
 
50
43
  def _assertions= n
@@ -284,7 +277,7 @@ module Mini
284
277
  end
285
278
 
286
279
  class Test
287
- VERSION = "1.2.0"
280
+ VERSION = "1.2.1"
288
281
 
289
282
  attr_reader :report, :failures, :errors
290
283
 
@@ -366,19 +359,9 @@ module Mini
366
359
  inst = suite.new test
367
360
  inst._assertions = 0
368
361
  @@out.puts "\n#{test}: " if $DEBUG
369
- result = '.'
370
- begin
371
- inst.setup
372
- inst.__send__ test
373
- rescue Exception => e
374
- result = puke(suite, test, e)
375
- ensure
376
- begin
377
- inst.teardown
378
- rescue Exception => e
379
- result = puke(suite, test, e)
380
- end
381
- end
362
+
363
+ result = inst.run(self)
364
+
382
365
  @@out.print result
383
366
  @@out.puts if $DEBUG
384
367
  @test_count += 1
@@ -392,6 +375,23 @@ module Mini
392
375
  class TestCase
393
376
  attr_reader :name
394
377
 
378
+ def run runner
379
+ result = '.'
380
+ begin
381
+ self.setup
382
+ self.__send__ self.name
383
+ rescue Exception => e
384
+ result = runner.puke(self.class, self.name, e)
385
+ ensure
386
+ begin
387
+ self.teardown
388
+ rescue Exception => e
389
+ result = runner.puke(self.class, self.name, e)
390
+ end
391
+ end
392
+ result
393
+ end
394
+
395
395
  def initialize name
396
396
  @name = name
397
397
  end
@@ -406,12 +406,25 @@ module Mini
406
406
  @@test_suites[klass] = true
407
407
  end
408
408
 
409
+ def self.test_order
410
+ :random
411
+ end
412
+
409
413
  def self.test_suites
410
414
  @@test_suites.keys.sort_by { |ts| ts.name }
411
415
  end
412
416
 
413
417
  def self.test_methods
414
- public_instance_methods(true).grep(/^test/).sort.map { |m| m.to_s }
418
+ methods = public_instance_methods(true).grep(/^test/).map { |m|
419
+ m.to_s
420
+ }.sort
421
+
422
+ if self.test_order == :random then
423
+ max = methods.size
424
+ methods = methods.sort_by { rand(max) }
425
+ end
426
+
427
+ methods
415
428
  end
416
429
 
417
430
  def setup; end
@@ -1,21 +1,4 @@
1
1
  require 'mini/test'
2
-
3
- module Test
4
- module Unit # was ::Mini::Test, but rails' horrid code forced my hand
5
- if defined? TestCase then
6
- warn "ARGH! someone defined Test::Unit::TestCase rather than requiring"
7
- remove_const :TestCase
8
- end
9
-
10
- TestCase = ::Mini::Test::TestCase
11
- AssertionFailedError = ::Mini::Assertion
12
-
13
- class TestCase
14
- alias :method_name :name # so lame
15
- end
16
- end
17
- end
18
-
19
- require 'test/unit/assertions' # brings in deprecated methods
2
+ require 'test/unit/testcase' # pull in deprecated functionality
20
3
 
21
4
  Mini::Test.autorun
@@ -1,15 +1,17 @@
1
1
  require 'mini/test'
2
- require 'test/unit'
2
+ require 'test/unit/deprecate'
3
3
 
4
+ module Test; end
4
5
  module Test::Unit # patch up bastards that that extend improperly.
5
6
  if defined? Assertions then
6
7
  warn "ARGH! someone defined Test::Unit::Assertions rather than requiring"
7
8
  CRAP_ASSERTIONS = Assertions
8
9
  remove_const :Assertions
9
10
 
11
+ # this will break on junit and rubinius... *sigh*
10
12
  ObjectSpace.each_object(Module) do |offender|
11
13
  offender.send :include, ::Mini::Assertions if offender < CRAP_ASSERTIONS
12
- end rescue :fuck_you_then!
14
+ end rescue nil
13
15
 
14
16
  Test::Unit::TestCase.send :include, CRAP_ASSERTIONS
15
17
  end
@@ -17,55 +19,31 @@ module Test::Unit # patch up bastards that that extend improperly.
17
19
  Assertions = ::Mini::Assertions
18
20
 
19
21
  module Assertions
20
- def self.included x
21
- x.send :include, Test::Unit::CRAP_ASSERTIONS
22
+ def self.included mod
23
+ mod.send :include, Test::Unit::CRAP_ASSERTIONS
22
24
  end if defined? Test::Unit::CRAP_ASSERTIONS
23
25
  end
24
26
  end
25
27
 
26
- class Module # define deprecation api
27
- DEPS = Hash.new { |h,k| h[k] = {} }
28
-
29
- def deprecation_warning old, new = nil, kaller = nil
30
- kaller ||= caller[1]
31
- unless DEPS[old][kaller] then
32
- msg = "#{self}##{old} deprecated. "
33
- msg += new ? "Use ##{new}" : "No replacement is provided"
34
- msg += ". From #{kaller}."
35
- warn msg
36
- end
37
- DEPS[old][kaller] = true
38
- end
39
-
40
- def deprecate old, new
41
- class_eval <<-EOM
42
- def #{old} *args, &block
43
- cls, clr = self.class, caller.first
44
- self.class.deprecation_warning #{old.inspect}, #{new.inspect}, clr
45
- #{new}(*args, &block)
46
- end
47
- EOM
48
- end
49
- end
50
-
51
28
  module Test::Unit
52
29
  module Assertions # deprecations
53
- deprecate :assert_nothing_thrown, :assert_nothing_raised # drop 2009-06-01
54
- deprecate :assert_raise, :assert_raises # drop 2010-06-01
55
- deprecate :assert_not_equal, :refute_equal # drop 2009-06-01
56
- deprecate :assert_no_match, :refute_match # drop 2009-06-01
57
- deprecate :assert_not_nil, :refute_nil # drop 2009-06-01
58
- deprecate :assert_not_same, :refute_same # drop 2009-06-01
59
-
60
- def assert_nothing_raised _ = :ignored # drop 2009-06-01
61
- self.class.deprecation_warning :assert_nothing_raised
30
+ tu_deprecate :assert_nothing_thrown, :assert_nothing_raised # 2009-06-01
31
+ tu_deprecate :assert_raise, :assert_raises # 2010-06-01
32
+ tu_deprecate :assert_not_equal, :refute_equal # 2009-06-01
33
+ tu_deprecate :assert_no_match, :refute_match # 2009-06-01
34
+ tu_deprecate :assert_not_nil, :refute_nil # 2009-06-01
35
+ tu_deprecate :assert_not_same, :refute_same # 2009-06-01
36
+
37
+ def assert_nothing_raised _ = :ignored # 2009-06-01
38
+ self.class.tu_deprecation_warning :assert_nothing_raised
62
39
  self._assertions += 1
63
40
  yield
64
41
  rescue => e
65
42
  raise Mini::Assertion, exception_details(e, "Exception raised:")
66
43
  end
67
44
 
68
- def build_message(user_message, template_message, *args) # drop 2009-06-01
45
+ def build_message(user_message, template_message, *args) # 2009-06-01
46
+ self.class.tu_deprecation_warning :build_message
69
47
  user_message ||= ''
70
48
  user_message += ' ' unless user_message.empty?
71
49
  msg = template_message.split(/<\?>/).zip(args.map { |o| o.inspect })
@@ -0,0 +1,24 @@
1
+ class Module # define deprecation api
2
+ DEPS = Hash.new { |h,k| h[k] = {} }
3
+
4
+ def tu_deprecation_warning old, new = nil, kaller = nil
5
+ kaller ||= caller[1]
6
+ unless DEPS[old][kaller] then
7
+ msg = "#{self}##{old} deprecated. "
8
+ msg += new ? "Use ##{new}" : "No replacement is provided"
9
+ msg += ". From #{kaller}."
10
+ warn msg
11
+ end
12
+ DEPS[old][kaller] = true
13
+ end
14
+
15
+ def tu_deprecate old, new
16
+ class_eval <<-EOM
17
+ def #{old} *args, &block
18
+ cls, clr = self.class, caller.first
19
+ self.class.tu_deprecation_warning #{old.inspect}, #{new.inspect}, clr
20
+ #{new}(*args, &block)
21
+ end
22
+ EOM
23
+ end
24
+ end
@@ -1,7 +1,10 @@
1
+ require 'test/unit/deprecate'
2
+
1
3
  # rails currently needs this file and this one method.
2
4
  module Test::Unit
3
5
  class Error
4
6
  def message
7
+ self.class.tu_deprecation_warning :message # 2009-06-01
5
8
  "you're a loser"
6
9
  end
7
10
  end
@@ -1,2 +1,25 @@
1
- # don't define anything, this is just so we don't get the real one
2
- warn "require 'test/unit/testcase' has been deprecated"
1
+ require 'mini/test'
2
+ require 'test/unit/deprecate'
3
+
4
+ warn "require 'test/unit/testcase' has been deprecated" unless
5
+ caller.first =~ /test.unit.rb/
6
+
7
+ module Test; end
8
+ module Test::Unit # was ::Mini::Test, but rails' horrid code forced my hand
9
+ if defined? TestCase then
10
+ warn "ARGH! someone defined Test::Unit::TestCase rather than requiring"
11
+ remove_const :TestCase
12
+ end
13
+
14
+ AssertionFailedError = ::Mini::Assertion
15
+
16
+ class TestCase < ::Mini::Test::TestCase
17
+ tu_deprecate :method_name, :name # 2009-06-01
18
+
19
+ def self.test_order # 2009-06-01
20
+ :sorted
21
+ end
22
+ end
23
+ end
24
+
25
+ require 'test/unit/assertions' # brings in deprecated methods
@@ -11,6 +11,7 @@ end
11
11
  class TestMiniTest < Mini::Test::TestCase
12
12
 
13
13
  def setup
14
+ srand 42
14
15
  Mini::Test::TestCase.reset
15
16
  @tu = Mini::Test.new
16
17
  @output = StringIO.new("")
@@ -162,6 +163,8 @@ Finished in 0.00
162
163
  assert true
163
164
  end
164
165
  #{if options[:failing]; "def test_failure; assert false; end"; end}
166
+
167
+ test_order = :sorted # helps the tests stay clean
165
168
  end
166
169
  CODE
167
170
  end
@@ -465,14 +468,6 @@ class TestMiniTestTestCase < Mini::Test::TestCase
465
468
  assert_equal "bye!\n", err
466
469
  end
467
470
 
468
- def test_message
469
- @assertion_count = 0
470
-
471
- assert_equal "blah2.", @tc.message(nil, "blah2")
472
- assert_equal "blah2.", @tc.message("", "blah2")
473
- assert_equal "blah1.\nblah2.", @tc.message("blah1", "blah2")
474
- end
475
-
476
471
  def test_flunk
477
472
  util_assert_triggered 'Epic Fail!' do
478
473
  @tc.flunk
@@ -485,21 +480,61 @@ class TestMiniTestTestCase < Mini::Test::TestCase
485
480
  end
486
481
  end
487
482
 
483
+ def test_message
484
+ @assertion_count = 0
485
+
486
+ assert_equal "blah2.", @tc.message(nil, "blah2")
487
+ assert_equal "blah2.", @tc.message("", "blah2")
488
+ assert_equal "blah1.\nblah2.", @tc.message("blah1", "blah2")
489
+ end
490
+
488
491
  def test_pass
489
492
  @tc.pass
490
493
  end
491
494
 
492
- def test_test_methods
495
+ def test_test_methods_sorted
493
496
  @assertion_count = 0
494
497
 
495
- # TODO: remove
496
498
  sample_test_case = util_test_case
499
+
500
+ class << sample_test_case
501
+ def test_order; :sorted end
502
+ end
503
+
497
504
  sample_test_case.instance_eval do
498
- define_method :test_one_test do
499
- assert "does not matter"
500
- end
505
+ define_method :test_test3 do assert "does not matter" end
506
+ define_method :test_test2 do assert "does not matter" end
507
+ define_method :test_test1 do assert "does not matter" end
501
508
  end
502
- assert_equal(%w(test_one_test), sample_test_case.test_methods)
509
+
510
+ expected = %w(test_test1 test_test2 test_test3)
511
+ assert_equal expected, sample_test_case.test_methods
512
+ end
513
+
514
+ def test_test_methods_random
515
+ @assertion_count = 0
516
+
517
+ sample_test_case = util_test_case
518
+
519
+ class << sample_test_case
520
+ def test_order; :random end
521
+ end
522
+
523
+ sample_test_case.instance_eval do
524
+ define_method :test_test1 do assert "does not matter" end
525
+ define_method :test_test2 do assert "does not matter" end
526
+ define_method :test_test3 do assert "does not matter" end
527
+ end
528
+
529
+ srand 42
530
+ expected = %w(test_test1 test_test2 test_test3)
531
+ max = expected.size
532
+ expected = expected.sort_by { rand(max) }
533
+
534
+ srand 42
535
+ result = sample_test_case.test_methods
536
+
537
+ assert_equal expected, result
503
538
  end
504
539
 
505
540
  def test_refute
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miniunit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-09 00:00:00 -07:00
12
+ date: 2008-06-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,7 @@ files:
44
44
  - lib/mini/test.rb
45
45
  - lib/test/unit.rb
46
46
  - lib/test/unit/assertions.rb
47
+ - lib/test/unit/deprecate.rb
47
48
  - lib/test/unit/error.rb
48
49
  - lib/test/unit/testcase.rb
49
50
  - test/test_mini_mock.rb