etest-unit 0.7.1 → 0.7.2

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.
data/lib/etest-unit.rb CHANGED
@@ -6,6 +6,8 @@ require File.dirname(__FILE__) + "/module_ext"
6
6
  require "test/unit/ui/console/testrunner"
7
7
 
8
8
  module Etest
9
+ class Error < ArgumentError; end
10
+
9
11
  class TestRunner < Test::Unit::UI::Console::TestRunner
10
12
  def setup_mediator
11
13
  super
@@ -26,21 +28,52 @@ module Etest
26
28
  end
27
29
  end
28
30
 
31
+ class TestSuiteCreator < Test::Unit::TestSuiteCreator
32
+ attr :tests, true
33
+
34
+ private
35
+
36
+ def collect_test_names
37
+ return super if tests.empty?
38
+
39
+ public_instance_methods = @test_case.public_instance_methods(true).map(&:to_s)
40
+ method_names = tests.map(&:to_s)
41
+
42
+ missing_tests = method_names - public_instance_methods
43
+ unless missing_tests.empty?
44
+ raise Error, "Missing test(s): #{missing_tests.join(", ")}"
45
+ end
46
+
47
+ send("sort_test_names_in_#{@test_case.test_order}_order", method_names)
48
+ end
49
+ end
50
+
29
51
  class TestCase < Test::Unit::TestCase
30
- def self.etest=(etest)
31
- include @etest = etest
52
+ module ClassMethods
53
+ def etest=(etest)
54
+ @etest = etest
55
+ include etest
56
+ end
57
+
58
+ attr :tests, true
32
59
  end
60
+
61
+ extend ClassMethods
33
62
 
34
63
  def self.suite
35
- suite = super
64
+ suite_creator = Etest::TestSuiteCreator.new(self)
65
+ suite_creator.tests = tests
66
+ suite = suite_creator.create
36
67
  suite.name = @etest.name
37
68
  suite
38
69
  end
39
70
  end
40
71
 
41
- def self.run(etest)
72
+ def self.run(etest, *tests)
42
73
  test_case_klass = Class.new(TestCase)
74
+
43
75
  test_case_klass.etest = etest
76
+ test_case_klass.tests = tests
44
77
  TestRunner.new(test_case_klass).start
45
78
  end
46
79
  end
@@ -48,49 +81,3 @@ end
48
81
  class Test::Unit::TestSuite
49
82
  attr :name, true
50
83
  end
51
-
52
- __END__
53
-
54
- def self.autorun
55
- auto_run
56
- end
57
-
58
- def self.auto_run
59
- #
60
- # find all modules that are not named /::Etest$/, and try to load
61
- # the respective Etest module.
62
- etests = Module.instances.map { |mod|
63
- #next if mod.name =~ /\bEtest$/
64
- next if mod.name == "Object"
65
-
66
- Module.by_name "#{mod.name}::Etest"
67
- }.compact.uniq.sort_by(&:name)
68
-
69
- run(*etests)
70
- end
71
-
72
- def self.run(*etests)
73
- #
74
- # convert all Etest modules into a test case
75
- test_cases = etests.map { |etest|
76
- STDERR.puts "Running: #{etest}"
77
- to_test_case etest
78
- }
79
-
80
- MiniTest::Test.run_etests(*test_cases)
81
- end
82
-
83
- #
84
- # convert an Etest moodule into a MiniTest testcase
85
- def self.to_test_case(mod)
86
- klass = Class.new TestCase
87
- klass.send :include, mod
88
- klass.send :include, Assertions
89
-
90
- Kernel.silent do
91
- mod.const_set("TestCase", klass)
92
- end
93
- klass
94
- end
95
- end
96
-
@@ -1,3 +1,3 @@
1
1
  module Etest
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
data/lib/module_ext.rb CHANGED
@@ -12,9 +12,9 @@ end
12
12
  class Module
13
13
  #
14
14
  # reloads the module, and runs the module's etests.
15
- def etest
15
+ def etest(*args)
16
16
  reload if respond_to?(:reload)
17
- ::Etest.run self.const_get("Etest")
17
+ ::Etest.run self.const_get("Etest"), *args
18
18
  end
19
19
 
20
20
  #
data/test/etest_test.rb CHANGED
@@ -5,16 +5,23 @@ Dir.chdir(DIRNAME)
5
5
  ETEST_TEST=true
6
6
 
7
7
  require "etest-unit"
8
+ require "expectation"
8
9
 
9
10
  # ---------------------------------------------------------------------
10
11
 
12
+ $etest_stats = Hash.new(0)
13
+
11
14
  module String::Etest
12
- def test_camelize
15
+ def test_underscore
16
+ $etest_stats[:underscore] += 1
17
+
13
18
  assert_equal "x", "X".underscore
14
19
  assert_equal "xa_la_nder", "XaLaNder".underscore
15
20
  end
16
21
 
17
- def test_underscore
22
+ def test_camelize
23
+ $etest_stats[:camelize] += 1
24
+
18
25
  assert_equal "X", "x".camelize
19
26
  assert_equal "XaLaNder", "xa_la_nder".camelize
20
27
  end
@@ -22,16 +29,32 @@ end
22
29
 
23
30
  module Fixnum::Etest
24
31
  def test_success
25
- $etests_did_run = true
32
+ $etest_stats[:success] += 1
33
+
26
34
  assert true
27
35
  end
28
36
  end
29
37
 
30
- String.etest
38
+ begin
39
+ String.etest
40
+ Fixnum.etest
41
+ expect! $etest_stats => { :underscore => 1, :camelize => 1, :success => 1 }
42
+
43
+ Fixnum.etest
44
+ expect! $etest_stats => { :underscore => 1, :camelize => 1, :success => 2 }
45
+
46
+ String.etest :test_camelize, :test_underscore
47
+ expect! $etest_stats => { :underscore => 2, :camelize => 2, :success => 2 }
31
48
 
32
- $etests_did_run = false
33
- Fixnum.etest
34
- exit(0) if $etests_did_run
49
+ begin
50
+ String.etest :test_camelize, :nosuchtest
51
+ expect! false
52
+ rescue Etest::Error
53
+ end
54
+
55
+ expect! $etest_stats => { :underscore => 2, :camelize => 2, :success => 2 }
56
+ rescue ArgumentError
57
+ STDERR.puts "#{$!}; in #{$!.backtrace.first}"
58
+ exit 1
59
+ end
35
60
 
36
- STDERR.puts "Etests didn't run"
37
- exit(1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etest-unit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 2430133208310339074
56
+ hash: 26857399825278854
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements: