jeremymcanally-context 0.5 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/context.gemspec +1 -1
- data/lib/context/lifecycle.rb +7 -1
- data/lib/context/version.rb +1 -1
- data/test/test_lifecycle.rb +35 -1
- metadata +1 -1
data/context.gemspec
CHANGED
data/lib/context/lifecycle.rb
CHANGED
@@ -12,6 +12,8 @@ class Test::Unit::TestCase
|
|
12
12
|
send("before_#{period}_callbacks") << block
|
13
13
|
end
|
14
14
|
|
15
|
+
alias :setup :before
|
16
|
+
|
15
17
|
# Add logic to run after the tests (i.e., a +teardown+ method)
|
16
18
|
#
|
17
19
|
# after do
|
@@ -21,6 +23,8 @@ class Test::Unit::TestCase
|
|
21
23
|
def after(period = :each, &block)
|
22
24
|
send("after_#{period}_callbacks") << block
|
23
25
|
end
|
26
|
+
|
27
|
+
alias :teardown :after
|
24
28
|
|
25
29
|
def gather_callbacks(callback_type, period) # :nodoc:
|
26
30
|
callbacks = superclass.respond_to?(:gather_callbacks) ? superclass.gather_callbacks(callback_type, period) : []
|
@@ -41,13 +45,15 @@ class Test::Unit::TestCase
|
|
41
45
|
child.after_all_callbacks = []
|
42
46
|
|
43
47
|
child.class_eval do
|
44
|
-
def setup
|
48
|
+
def setup(&block)
|
45
49
|
super
|
50
|
+
|
46
51
|
run_each_callbacks :before
|
47
52
|
end
|
48
53
|
|
49
54
|
def teardown
|
50
55
|
super
|
56
|
+
|
51
57
|
run_each_callbacks :after
|
52
58
|
end
|
53
59
|
end
|
data/lib/context/version.rb
CHANGED
data/test/test_lifecycle.rb
CHANGED
@@ -25,7 +25,7 @@ class TestLifecycle < Test::Unit::TestCase
|
|
25
25
|
sample_test = context "lifecycle" do
|
26
26
|
attr_reader :inherited_before_each_var, :inherited_before_each_var_2, :inherited_after_each_var,
|
27
27
|
:after_each_var, :inherited_before_all_var, :inherited_after_all_var, :before_all_var, :after_all_var,
|
28
|
-
:superclass_before_each_var, :superclass_after_each_var, :superclass_before_all_var, :superclass_after_all_var
|
28
|
+
:superclass_before_each_var, :superclass_after_each_var, :superclass_before_all_var, :superclass_after_all_var, :one, :two
|
29
29
|
|
30
30
|
before do
|
31
31
|
@inherited_before_each_var = 3
|
@@ -127,4 +127,38 @@ class TestLifecycle < Test::Unit::TestCase
|
|
127
127
|
assert_equal 1, @test.after_all_var
|
128
128
|
end
|
129
129
|
end
|
130
|
+
|
131
|
+
# Test that we aren't stomping on defined seutp method
|
132
|
+
context "With setup/teardown methods" do
|
133
|
+
before do
|
134
|
+
@result = Test::Unit::TestResult.new
|
135
|
+
@test = sample_test.new("test_lifecycle_foo")
|
136
|
+
|
137
|
+
@test.class.setup do
|
138
|
+
@one = 1
|
139
|
+
end
|
140
|
+
|
141
|
+
@test.class.teardown do
|
142
|
+
@two = 10
|
143
|
+
end
|
144
|
+
|
145
|
+
@test.run(@result) { |inherited_after_each_var, v| }
|
146
|
+
end
|
147
|
+
|
148
|
+
it "runs setup method block a la Shoulda" do
|
149
|
+
assert_equal 1, @test.one
|
150
|
+
end
|
151
|
+
|
152
|
+
it "runs setup method block and regular callbacks" do
|
153
|
+
assert_equal 3, @test.inherited_before_each_var
|
154
|
+
end
|
155
|
+
|
156
|
+
it "runs teardown method block a la Shoulda" do
|
157
|
+
assert_equal 10, @test.two
|
158
|
+
end
|
159
|
+
|
160
|
+
it "runs teardown method block and regular callbacks" do
|
161
|
+
assert_equal 1, @test.after_each_var
|
162
|
+
end
|
163
|
+
end
|
130
164
|
end
|