citrusbyte-contest 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/contest.rb +15 -2
- data/test/all_test.rb +16 -0
- metadata +1 -1
data/lib/contest.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
require "test/unit"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# Test::Unit loads a default test if the suite is empty, and the only
|
4
|
+
# purpose of that test is to fail. As having empty contexts is a common
|
5
|
+
# practice, we decided to overwrite TestSuite#empty? in order to
|
6
|
+
# allow them. Having a failure when no tests have been defined seems
|
7
|
+
# counter-intuitive.
|
8
|
+
class Test::Unit::TestSuite
|
9
|
+
def empty?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
5
13
|
|
14
|
+
# We added setup, test and context as class methods, and the instance
|
15
|
+
# method setup now iterates on the setup blocks. Note that all setup
|
16
|
+
# blocks must be defined with the block syntax. Adding a setup instance
|
17
|
+
# method defeats the purpose of this library.
|
18
|
+
class Test::Unit::TestCase
|
6
19
|
def self.setup(&block)
|
7
20
|
setup_blocks << block
|
8
21
|
end
|
data/test/all_test.rb
CHANGED
@@ -39,3 +39,19 @@ class FooTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
class BarTest < Test::Unit::TestCase
|
44
|
+
setup do
|
45
|
+
@value = 1
|
46
|
+
end
|
47
|
+
|
48
|
+
context "some context" do
|
49
|
+
setup do
|
50
|
+
@value += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
test "another truth" do
|
54
|
+
assert_equal 2, @value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|