GUnit 0.3.2 → 0.3.3
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/VERSION +1 -1
- data/gunit.gemspec +2 -2
- data/lib/gunit/assertions.rb +1 -2
- data/lib/gunit/test_case.rb +19 -31
- data/lib/gunit/test_response.rb +4 -4
- data/lib/gunit/test_runner.rb +7 -7
- data/lib/gunit/verification.rb +7 -14
- data/test/unit/assertions_test.rb +4 -4
- data/test/unit/test_case_test.rb +59 -10
- data/test/unit/verification_test.rb +14 -52
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/gunit.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{GUnit}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Greg Sterndale"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-03}
|
13
13
|
s.description = %q{GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is the shizzle.}
|
14
14
|
s.email = %q{gsterndale@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/gunit/assertions.rb
CHANGED
data/lib/gunit/test_case.rb
CHANGED
@@ -38,8 +38,8 @@ module GUnit
|
|
38
38
|
at_exit { subclass.autorun }
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.autorun=(
|
42
|
-
@@autorun = !
|
41
|
+
def self.autorun=(bool)
|
42
|
+
@@autorun = !bool.nil? && bool
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.autorun?
|
@@ -65,7 +65,7 @@ module GUnit
|
|
65
65
|
|
66
66
|
def self.test_methods(prefix=TEST_METHOD_PREFIX)
|
67
67
|
method_names = instance_methods.find_all{|method| method =~ /\A#{prefix}/ && ! GUnit::TestCase.instance_methods.include?(method) }
|
68
|
-
method_names.map!{|
|
68
|
+
method_names.map!{|method_name| method_name.to_sym }
|
69
69
|
end
|
70
70
|
|
71
71
|
def self.context_for_method(method_name)
|
@@ -73,11 +73,7 @@ module GUnit
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def self.context(*args, &blk)
|
76
|
-
new_context =
|
77
|
-
GUnit::Context.new(args.first, &blk)
|
78
|
-
else
|
79
|
-
GUnit::Context.new(args.first)
|
80
|
-
end
|
76
|
+
new_context = GUnit::Context.new(args.first, &blk)
|
81
77
|
new_context.parent = current_context
|
82
78
|
@@context_stack << new_context
|
83
79
|
current_context.run(self)
|
@@ -85,41 +81,26 @@ module GUnit
|
|
85
81
|
end
|
86
82
|
|
87
83
|
def self.setup(*args, &blk)
|
88
|
-
setup =
|
89
|
-
GUnit::Setup.new(args.first, &blk)
|
90
|
-
else
|
91
|
-
GUnit::Setup.new(args.first)
|
92
|
-
end
|
84
|
+
setup = GUnit::Setup.new(args.first, &blk)
|
93
85
|
current_context.setups << setup
|
94
86
|
end
|
95
87
|
|
96
88
|
def self.exercise(*args, &blk)
|
97
|
-
exercise =
|
98
|
-
GUnit::Exercise.new(args.first, &blk)
|
99
|
-
else
|
100
|
-
GUnit::Exercise.new(args.first)
|
101
|
-
end
|
89
|
+
exercise = GUnit::Exercise.new(args.first, &blk)
|
102
90
|
current_context.exercise = exercise
|
103
91
|
end
|
104
92
|
|
105
93
|
def self.teardown(*args, &blk)
|
106
|
-
teardown =
|
107
|
-
GUnit::Teardown.new(args.first, &blk)
|
108
|
-
else
|
109
|
-
GUnit::Teardown.new(args.first)
|
110
|
-
end
|
94
|
+
teardown = GUnit::Teardown.new(args.first, &blk)
|
111
95
|
current_context.teardowns << teardown
|
112
96
|
end
|
113
97
|
|
114
98
|
def self.verify(*args, &blk)
|
115
99
|
test_method_name = message_to_unique_test_method_name(args.first)
|
116
100
|
define_method(test_method_name) do
|
117
|
-
verification =
|
118
|
-
GUnit::Verification.new(args.first, &blk)
|
119
|
-
else
|
120
|
-
GUnit::Verification.new(args.first)
|
121
|
-
end
|
101
|
+
verification = GUnit::Verification.new(args.first, &blk)
|
122
102
|
verification.run(self)
|
103
|
+
GUnit::PassResponse.new(verification.message)
|
123
104
|
end
|
124
105
|
@@method_count += 1
|
125
106
|
@@test_method_contexts[test_method_name] = current_context
|
@@ -143,13 +124,20 @@ module GUnit
|
|
143
124
|
self.run_excercise
|
144
125
|
response = self.send(self.method_name.to_sym)
|
145
126
|
self.run_teardowns
|
146
|
-
|
127
|
+
rescue GUnit::NothingToDo => e
|
128
|
+
response = ToDoResponse.new(e.message, e.backtrace)
|
129
|
+
rescue GUnit::AssertionFailure => e
|
130
|
+
response = FailResponse.new(e.message, e.backtrace)
|
131
|
+
rescue ::Exception => e
|
132
|
+
response = ExceptionResponse.new(e.message, e.backtrace)
|
133
|
+
ensure
|
134
|
+
return response
|
147
135
|
end
|
148
136
|
|
149
137
|
protected
|
150
138
|
|
151
139
|
def run_setups
|
152
|
-
self.context.all_setups.each {|
|
140
|
+
self.context.all_setups.each {|setup| setup.run(self) }
|
153
141
|
end
|
154
142
|
|
155
143
|
def run_excercise
|
@@ -157,7 +145,7 @@ module GUnit
|
|
157
145
|
end
|
158
146
|
|
159
147
|
def run_teardowns
|
160
|
-
self.context.all_teardowns.reverse.each {|
|
148
|
+
self.context.all_teardowns.reverse.each {|teardown| teardown.run(self) } if self.context
|
161
149
|
end
|
162
150
|
|
163
151
|
def self.current_context
|
data/lib/gunit/test_response.rb
CHANGED
@@ -9,12 +9,12 @@ module GUnit
|
|
9
9
|
|
10
10
|
# FailResponse.new("my message")
|
11
11
|
def initialize(*args)
|
12
|
-
self.message = args.find{|
|
13
|
-
self.backtrace = args.find{|
|
12
|
+
self.message = args.find{|arg| arg.is_a?(String) } || self.class::DEFAULT_MESSAGE
|
13
|
+
self.backtrace = args.find{|arg| arg.is_a?(Array) } || []
|
14
14
|
end
|
15
15
|
|
16
|
-
def backtrace=(
|
17
|
-
@backtrace =
|
16
|
+
def backtrace=(traces=[])
|
17
|
+
@backtrace = traces
|
18
18
|
discover_file_name
|
19
19
|
discover_line_number
|
20
20
|
@backtrace
|
data/lib/gunit/test_runner.rb
CHANGED
@@ -80,19 +80,19 @@ module GUnit
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def passes
|
83
|
-
@responses.find_all{|
|
83
|
+
@responses.find_all{|response| response.is_a? PassResponse }
|
84
84
|
end
|
85
85
|
|
86
86
|
def fails
|
87
|
-
@responses.find_all{|
|
87
|
+
@responses.find_all{|response| response.is_a? FailResponse }
|
88
88
|
end
|
89
89
|
|
90
90
|
def exceptions
|
91
|
-
@responses.find_all{|
|
91
|
+
@responses.find_all{|response| response.is_a? ExceptionResponse }
|
92
92
|
end
|
93
93
|
|
94
94
|
def to_dos
|
95
|
-
@responses.find_all{|
|
95
|
+
@responses.find_all{|response| response.is_a? ToDoResponse }
|
96
96
|
end
|
97
97
|
|
98
98
|
protected
|
@@ -109,7 +109,7 @@ module GUnit
|
|
109
109
|
|
110
110
|
def print_responses_summary
|
111
111
|
@io.puts ""
|
112
|
-
@responses.select{|
|
112
|
+
@responses.select{|response| !response.is_a?(GUnit::PassResponse) }.each do |response|
|
113
113
|
@io.print self.class.response_color(response)
|
114
114
|
@io.print "#{response.message} (#{response.file_name}:#{response.line_number})\n"
|
115
115
|
@io.print DEFAULT_COLOR
|
@@ -118,8 +118,8 @@ module GUnit
|
|
118
118
|
end
|
119
119
|
|
120
120
|
# Flatten array of TestSuites and TestCases into a single dimensional array of TestCases
|
121
|
-
def test_cases(
|
122
|
-
|
121
|
+
def test_cases(test_suites_cases=self.tests)
|
122
|
+
test_suites_cases.map do |test|
|
123
123
|
case test
|
124
124
|
when GUnit::TestSuite
|
125
125
|
test_cases(test.tests)
|
data/lib/gunit/verification.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module GUnit
|
2
|
-
|
2
|
+
|
3
|
+
class NothingToDo < StandardError
|
4
|
+
end
|
5
|
+
|
3
6
|
class Verification
|
4
7
|
attr_writer :message
|
5
8
|
attr_accessor :task
|
@@ -13,19 +16,9 @@ module GUnit
|
|
13
16
|
end
|
14
17
|
|
15
18
|
def run(binding=self)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
bound_task.call
|
20
|
-
PassResponse.new
|
21
|
-
else
|
22
|
-
ToDoResponse.new(self.message, Kernel.caller)
|
23
|
-
end
|
24
|
-
rescue GUnit::AssertionFailure => e
|
25
|
-
FailResponse.new(e.message, e.backtrace)
|
26
|
-
rescue ::Exception => e
|
27
|
-
ExceptionResponse.new(e.message, e.backtrace)
|
28
|
-
end
|
19
|
+
raise GUnit::NothingToDo.new(self.message) unless @task.is_a?(Proc) # Kernel.caller
|
20
|
+
bound_task = @task.bind(binding)
|
21
|
+
bound_task.call
|
29
22
|
end
|
30
23
|
|
31
24
|
def message
|
@@ -98,7 +98,7 @@ class FooTest < Test::Unit::TestCase
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
101
|
+
def test_assert_raises_string_message_block
|
102
102
|
block = Proc.new { raise "boom" }
|
103
103
|
expected = "boom"
|
104
104
|
message = "my message here"
|
@@ -106,7 +106,7 @@ class FooTest < Test::Unit::TestCase
|
|
106
106
|
assert result === true
|
107
107
|
end
|
108
108
|
|
109
|
-
def
|
109
|
+
def test_assert_raises_class_message_block
|
110
110
|
block = Proc.new { raise StandardError }
|
111
111
|
expected = StandardError
|
112
112
|
message = "my message here"
|
@@ -114,14 +114,14 @@ class FooTest < Test::Unit::TestCase
|
|
114
114
|
assert result === true
|
115
115
|
end
|
116
116
|
|
117
|
-
def
|
117
|
+
def test_assert_raises_string_block
|
118
118
|
block = Proc.new { raise "boom" }
|
119
119
|
expected = "boom"
|
120
120
|
result = @foo1.assert_raises expected, &block
|
121
121
|
assert result === true
|
122
122
|
end
|
123
123
|
|
124
|
-
def
|
124
|
+
def test_assert_raises_block_only
|
125
125
|
block = Proc.new { raise "boom" }
|
126
126
|
result = @foo1.assert_raises &block
|
127
127
|
assert result === true
|
data/test/unit/test_case_test.rb
CHANGED
@@ -82,11 +82,13 @@ class GUnit::TestCaseTest < Test::Unit::TestCase
|
|
82
82
|
assert_equal method_count + 1, MyClassTest.instance_methods.length
|
83
83
|
assert dynamic_method_name.to_s =~ /#{MyClassTest::TEST_METHOD_PREFIX}/
|
84
84
|
assert MyClassTest.instance_methods.include?(dynamic_method_name.to_s)
|
85
|
-
|
86
|
-
|
87
|
-
verification.expects(:run).returns(todo)
|
85
|
+
message = 'The truth'
|
86
|
+
verification = mock(:message => message, :run => true)
|
88
87
|
GUnit::Verification.expects(:new).with(args).returns(verification)
|
89
|
-
|
88
|
+
response = MyClassTest.new.send(dynamic_method_name)
|
89
|
+
assert response.is_a?(GUnit::TestResponse)
|
90
|
+
assert response.is_a?(GUnit::PassResponse)
|
91
|
+
assert_equal message, response.message
|
90
92
|
end
|
91
93
|
|
92
94
|
def test_verify_with_block_creates_instance_method
|
@@ -97,12 +99,14 @@ class GUnit::TestCaseTest < Test::Unit::TestCase
|
|
97
99
|
assert_equal method_count + 1, MyClassTest.instance_methods.length
|
98
100
|
assert dynamic_method_name.to_s =~ /#{MyClassTest::TEST_METHOD_PREFIX}/
|
99
101
|
assert MyClassTest.new.respond_to?(dynamic_method_name)
|
100
|
-
|
101
|
-
|
102
|
-
verification.expects(:run).returns(pass)
|
102
|
+
message = 'The truth'
|
103
|
+
verification = mock(:message => message, :run => true)
|
103
104
|
# TODO how to set expectation that blk is passed to new() ???
|
104
|
-
GUnit::Verification.expects(:new).
|
105
|
-
|
105
|
+
GUnit::Verification.expects(:new).returns(verification)
|
106
|
+
response = MyClassTest.new.send(dynamic_method_name)
|
107
|
+
assert response.is_a?(GUnit::TestResponse)
|
108
|
+
assert response.is_a?(GUnit::PassResponse)
|
109
|
+
assert_equal message, response.message
|
106
110
|
end
|
107
111
|
|
108
112
|
def test_run_runs_setups
|
@@ -142,7 +146,52 @@ class GUnit::TestCaseTest < Test::Unit::TestCase
|
|
142
146
|
@my_test_case3.run
|
143
147
|
assert_equal "zip", @my_test_case3.instance_variable_get("@foo")
|
144
148
|
end
|
145
|
-
|
149
|
+
|
150
|
+
def test_run_with_test_method_raising_assertion_failure
|
151
|
+
exception_message = 'Whoops'
|
152
|
+
exception = GUnit::AssertionFailure.new(exception_message)
|
153
|
+
verify_message = "The truth"
|
154
|
+
verification = mock
|
155
|
+
verification.expects(:run).raises(exception)
|
156
|
+
dynamic_method_name = MyClassTest.verify(verify_message)
|
157
|
+
GUnit::Verification.expects(:new).with(verify_message).returns(verification)
|
158
|
+
@my_test_case4 = MyClassTest.new(dynamic_method_name)
|
159
|
+
response = @my_test_case4.run
|
160
|
+
assert response.is_a?(GUnit::TestResponse)
|
161
|
+
assert response.is_a?(GUnit::FailResponse)
|
162
|
+
assert_equal exception_message, response.message
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_run_with_test_method_raising_nothing_to_do_exception
|
166
|
+
exception_message = 'Nothin here'
|
167
|
+
exception = GUnit::NothingToDo.new(exception_message)
|
168
|
+
verify_message = "The truth"
|
169
|
+
verification = mock
|
170
|
+
verification.expects(:run).raises(exception)
|
171
|
+
dynamic_method_name = MyClassTest.verify(verify_message)
|
172
|
+
GUnit::Verification.expects(:new).with(verify_message).returns(verification)
|
173
|
+
@my_test_case5 = MyClassTest.new(dynamic_method_name)
|
174
|
+
response = @my_test_case5.run
|
175
|
+
assert response.is_a?(GUnit::TestResponse)
|
176
|
+
assert response.is_a?(GUnit::ToDoResponse)
|
177
|
+
assert_equal exception_message, response.message
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_run_with_test_method_raising_random_exception
|
181
|
+
exception_message = 'Whoops'
|
182
|
+
exception = ::StandardError.new(exception_message)
|
183
|
+
verify_message = "The truth"
|
184
|
+
verification = mock
|
185
|
+
verification.expects(:run).raises(exception)
|
186
|
+
dynamic_method_name = MyClassTest.verify(verify_message)
|
187
|
+
GUnit::Verification.expects(:new).with(verify_message).returns(verification)
|
188
|
+
@my_test_case5 = MyClassTest.new(dynamic_method_name)
|
189
|
+
response = @my_test_case5.run
|
190
|
+
assert response.is_a?(GUnit::TestResponse)
|
191
|
+
assert response.is_a?(GUnit::ExceptionResponse)
|
192
|
+
assert_equal exception_message, response.message
|
193
|
+
end
|
194
|
+
|
146
195
|
def test_test_methods
|
147
196
|
assert MyClassTest.test_methods.include?(:test_one)
|
148
197
|
assert MyClassTest.test_methods.include?(:test_two)
|
@@ -52,46 +52,34 @@ class GUnit::VerificationTest < Test::Unit::TestCase
|
|
52
52
|
def test_run_with_task_called_returns_true
|
53
53
|
@verification1.task = lambda { true }
|
54
54
|
response = @verification1.run
|
55
|
-
assert response
|
56
|
-
assert response.is_a?(GUnit::PassResponse)
|
55
|
+
assert response === true
|
57
56
|
end
|
58
57
|
|
59
58
|
def test_run_with_task_called_returns_false
|
60
59
|
@verification1.task = lambda { false }
|
61
60
|
response = @verification1.run
|
62
|
-
assert response
|
63
|
-
assert response.is_a?(GUnit::PassResponse)
|
61
|
+
assert response === false
|
64
62
|
end
|
65
63
|
|
66
64
|
def test_run_with_task_is_false
|
67
65
|
@verification1.task = false
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
assert_raise GUnit::NothingToDo do
|
67
|
+
@verification1.run
|
68
|
+
end
|
71
69
|
end
|
72
70
|
|
73
71
|
def test_run_with_task_is_nil
|
74
72
|
message = 'Not dun yet'
|
75
|
-
stack = ["./samples/../lib/gunit/verification.rb:25:in `test_not_dun_yet'",
|
76
|
-
"./samples/../lib/gunit/verification.rb:25:in `test_not_dun_yet'",
|
77
|
-
"./samples/../lib/gunit/test_case.rb:38:in `send'",
|
78
|
-
"./samples/../lib/gunit/test_case.rb:38:in `run'",
|
79
|
-
"./samples/../lib/gunit/test_suite.rb:21:in `run'",
|
80
|
-
"./samples/../lib/gunit/test_suite.rb:16:in `each'",
|
81
|
-
"./samples/../lib/gunit/test_suite.rb:16:in `run'",
|
82
|
-
"./samples/../lib/gunit/test_runner.rb:44:in `run'",
|
83
|
-
"./samples/../lib/gunit/test_runner.rb:41:in `each'",
|
84
|
-
"./samples/../lib/gunit/test_runner.rb:41:in `run'",
|
85
|
-
"samples/foo_sample.rb:177"]
|
86
|
-
to_do_response = GUnit::ToDoResponse.new(message, stack)
|
87
73
|
@verification1.message = message
|
88
74
|
@verification1.task = nil
|
89
|
-
GUnit::
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
75
|
+
assert_raise GUnit::NothingToDo do
|
76
|
+
@verification1.run
|
77
|
+
end
|
78
|
+
begin
|
79
|
+
@verification1.run
|
80
|
+
rescue GUnit::NothingToDo => exception
|
81
|
+
assert_equal message, exception.message
|
82
|
+
end
|
95
83
|
end
|
96
84
|
|
97
85
|
def test_run_with_binding
|
@@ -103,31 +91,5 @@ class GUnit::VerificationTest < Test::Unit::TestCase
|
|
103
91
|
@verification1.run(obj)
|
104
92
|
assert_equal "zip", obj.instance_variable_get("@foo")
|
105
93
|
end
|
106
|
-
|
107
|
-
def test_run_with_assertion_failure_exception
|
108
|
-
message = "boooooooom"
|
109
|
-
backtrace = ['ohnoes']
|
110
|
-
assertion_failure = GUnit::AssertionFailure.new(message)
|
111
|
-
assertion_failure.expects(:backtrace).at_least_once.returns(backtrace)
|
112
|
-
@verification1.task = lambda { raise assertion_failure }
|
113
|
-
response = @verification1.run
|
114
|
-
assert response.is_a?(GUnit::TestResponse)
|
115
|
-
assert response.is_a?(GUnit::FailResponse)
|
116
|
-
assert_equal message, response.message
|
117
|
-
assert_equal backtrace, response.backtrace
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_run_with_random_exception
|
121
|
-
message = "boooooooom"
|
122
|
-
backtrace = ['ohnoes']
|
123
|
-
exception = Exception.new(message)
|
124
|
-
exception.set_backtrace(backtrace)
|
125
|
-
@verification1.task = lambda { raise exception }
|
126
|
-
response = @verification1.run
|
127
|
-
assert response.is_a?(GUnit::TestResponse)
|
128
|
-
assert response.is_a?(GUnit::ExceptionResponse)
|
129
|
-
assert_equal message, response.message
|
130
|
-
assert_equal backtrace, response.backtrace
|
131
|
-
end
|
132
|
-
|
94
|
+
|
133
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: GUnit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Sterndale
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|