citrusbyte-contest 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,25 +17,22 @@ end
17
17
  # of this library.
18
18
  class Test::Unit::TestCase
19
19
  def self.setup(&block)
20
- setup_blocks << block
20
+ define_method :setup do
21
+ super
22
+ instance_eval(&block)
23
+ end
21
24
  end
22
25
 
23
26
  def self.teardown(&block)
24
- teardown_blocks << block
25
- end
26
-
27
- def setup
28
- eval_blocks(:setup_blocks, self.class.ancestors.reverse)
29
- end
30
-
31
- def teardown
32
- eval_blocks(:teardown_blocks, self.class.ancestors)
27
+ define_method :teardown do
28
+ instance_eval(&block)
29
+ super
30
+ end
33
31
  end
34
32
 
35
33
  def self.context(name, &block)
36
- subclass = Class.new(self.superclass)
37
- subclass.setup_blocks.unshift(*setup_blocks)
38
- subclass.teardown_blocks.unshift(*teardown_blocks)
34
+ subclass = Class.new(self)
35
+ remove_tests(subclass)
39
36
  subclass.class_eval(&block)
40
37
  const_set(context_name(name), subclass)
41
38
  end
@@ -51,23 +48,6 @@ class Test::Unit::TestCase
51
48
 
52
49
  private
53
50
 
54
- def eval_blocks(type, ancestors)
55
- ancestors.each do |ancestor|
56
- next unless ancestor.respond_to?(type)
57
- ancestor.send(type).each do |block|
58
- instance_eval(&block)
59
- end
60
- end
61
- end
62
-
63
- def self.setup_blocks
64
- @setup_blocks ||= []
65
- end
66
-
67
- def self.teardown_blocks
68
- @teardown_blocks ||= []
69
- end
70
-
71
51
  def self.context_name(name)
72
52
  "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
73
53
  end
@@ -79,4 +59,10 @@ private
79
59
  def self.sanitize_name(name)
80
60
  name.gsub(/\W+/, ' ').strip
81
61
  end
62
+
63
+ def self.remove_tests(subclass)
64
+ subclass.public_instance_methods.grep(/^test_/).each do |meth|
65
+ subclass.send(:undef_method, meth.to_sym)
66
+ end
67
+ end
82
68
  end
@@ -79,3 +79,36 @@ class BarTest < Test::Unit::TestCase
79
79
  end
80
80
  end
81
81
  end
82
+
83
+ class TestBaz < Test::Unit::TestCase
84
+ def foo
85
+ 42
86
+ end
87
+
88
+ def setup
89
+ @value = 1
90
+ super
91
+ end
92
+
93
+ context "some context" do
94
+ def setup
95
+ super
96
+ @value += 2
97
+ end
98
+
99
+ test "a helper" do
100
+ assert_equal 42, foo
101
+ assert_equal 3, @value
102
+ end
103
+
104
+ context "another context" do
105
+ setup do
106
+ @value += 3
107
+ end
108
+
109
+ test "blah" do
110
+ assert_equal 6, @value
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,11 +1,15 @@
1
1
  require File.dirname(__FILE__) + "/../lib/contest"
2
2
 
3
3
  class Test::Unit::TestCase
4
- setup { puts "Grandparent Setup" }
4
+ def setup
5
+ puts "Grandparent Setup"
6
+ end
5
7
  end
6
8
 
7
9
  class Test::Unit::TestCase
8
- teardown { puts "Grandparent Teardown" }
10
+ def teardown
11
+ puts "Grandparent Teardown"
12
+ end
9
13
  end
10
14
 
11
15
  class MidLayerTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrusbyte-contest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski