rubyunit 0.1.8 → 0.1.9
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.
- checksums.yaml +4 -4
- data/lib/RubyUnit/AssertionFailure.rb +0 -3
- data/lib/RubyUnit/Runner.rb +1 -1
- data/lib/RubyUnit/TestCase.rb +87 -78
- data/lib/RubyUnit.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3e1a28adb333f17a61ff08881e22893ad74d765
|
4
|
+
data.tar.gz: 4dfe9ddcb22f1548a9f0455e311ec7c8519e9dd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c810ced52681035b09c75486551c58f6cf9d995104be9d67c596beb46eeaf6eb15fc3ce0ff20be5c9b120dd9dc6984918a026af02d2e3e4998397ecb8d96f6d4
|
7
|
+
data.tar.gz: e5fc0d25fe211f90efec5e600ea3f230af74bf617dc9703807a770d6eb533c5326151b3ffc4c06d02fa7e9c1c5aacc00f65b4ef14947796be24f95d224e8a8cb
|
@@ -3,9 +3,6 @@ module RubyUnit
|
|
3
3
|
# = RubyUnit::AssertionFailure
|
4
4
|
# Exception that is raised when a test assertion fails.
|
5
5
|
#
|
6
|
-
# TODO add some things to this object:
|
7
|
-
# * Excpetion info so that better reporting can be generated
|
8
|
-
#
|
9
6
|
class AssertionFailure < StandardError
|
10
7
|
end
|
11
8
|
end
|
data/lib/RubyUnit/Runner.rb
CHANGED
@@ -105,7 +105,7 @@ module RubyUnit
|
|
105
105
|
puts "#{@@failures.count} Failures:\n" if @@failures.count > 0
|
106
106
|
@@failures.each_with_index do |failure, i|
|
107
107
|
puts "#{i + 1}) #{failure[0]}::#{failure[1]}(#{failure[2]})"
|
108
|
-
puts failure[3]
|
108
|
+
puts failure[3]
|
109
109
|
puts failure[3].backtrace.join("\n")
|
110
110
|
end
|
111
111
|
|
data/lib/RubyUnit/TestCase.rb
CHANGED
@@ -26,6 +26,38 @@ module RubyUnit
|
|
26
26
|
# end
|
27
27
|
#
|
28
28
|
class TestCase
|
29
|
+
private
|
30
|
+
#
|
31
|
+
# Builds the message that will be used with the assertion
|
32
|
+
# * raises RubyUnit::AssertionFailure
|
33
|
+
# * raises ArgumentError unless error is a String
|
34
|
+
# * raises ArgumentError unless message is nil or a String
|
35
|
+
# * raises ArgumentError unless data is a Hash
|
36
|
+
#
|
37
|
+
# error::
|
38
|
+
# The assertion failure
|
39
|
+
#
|
40
|
+
# message::
|
41
|
+
# The message provided by the test for the assertion
|
42
|
+
#
|
43
|
+
# data::
|
44
|
+
# The data associated with assertion failure
|
45
|
+
#
|
46
|
+
# build_message 'Failing Test', message, {'expected' => expected, 'actual' => actual }
|
47
|
+
#
|
48
|
+
def build_message error, message, data = {} # :nodoc:
|
49
|
+
raise ArgumentError, 'Error message must be a String' unless error.is_a? String
|
50
|
+
raise ArgumentError, 'Failure message must be String' unless message.nil? or message.is_a? String
|
51
|
+
raise ArgumentError, 'Failure data must be a Hash' unless data.is_a? Hash
|
52
|
+
|
53
|
+
error_message = error
|
54
|
+
error_message << "\n#{message}" if not message.nil?
|
55
|
+
data.each do |index, value|
|
56
|
+
error_message << "\n%10s: #{value.inspect}" % index
|
57
|
+
end
|
58
|
+
raise AssertionFailure, error_message
|
59
|
+
end
|
60
|
+
|
29
61
|
public
|
30
62
|
|
31
63
|
#
|
@@ -77,43 +109,43 @@ module RubyUnit
|
|
77
109
|
#
|
78
110
|
def fail message = nil
|
79
111
|
__assertion do
|
80
|
-
|
112
|
+
build_message 'Failing test', message
|
81
113
|
end
|
82
114
|
end
|
83
115
|
|
84
116
|
#
|
85
117
|
# Assert that a test condition is true.
|
86
|
-
# * raises RubyUnit::AssertionFailure
|
118
|
+
# * raises RubyUnit::AssertionFailure if _value_ is false or nil
|
87
119
|
#
|
88
|
-
#
|
89
|
-
# The value that is being checked
|
120
|
+
# value::
|
121
|
+
# The value that is being checked by the assertion
|
90
122
|
#
|
91
123
|
# message::
|
92
124
|
# The message provided to be reported for a failure
|
93
125
|
#
|
94
|
-
# assert false "This will fail" # => fail
|
126
|
+
# assert false, "This will fail" # => fail
|
95
127
|
#
|
96
|
-
def assert
|
128
|
+
def assert value, message = nil
|
97
129
|
__assertion do
|
98
|
-
|
130
|
+
build_message 'Failed to assert that value is false or nil', message, {:value=>value} unless value
|
99
131
|
end
|
100
132
|
end
|
101
133
|
|
102
134
|
#
|
103
135
|
# Assert that a test condition is false.
|
104
|
-
# * raises RubyUnit::AssertionFailure
|
136
|
+
# * raises RubyUnit::AssertionFailure unless _value_ is false or nil
|
105
137
|
#
|
106
|
-
#
|
107
|
-
# The value that is being checked
|
138
|
+
# value::
|
139
|
+
# The value that is being checked by the assertion
|
108
140
|
#
|
109
141
|
# message::
|
110
142
|
# The message provided to be reported for a failure
|
111
143
|
#
|
112
|
-
# assertNot true "This will fail" # => fail
|
144
|
+
# assertNot true, "This will fail" # => fail
|
113
145
|
#
|
114
|
-
def assertNot
|
146
|
+
def assertNot value, message = nil
|
115
147
|
__assertion do
|
116
|
-
|
148
|
+
build_message 'Value should NOT be false or nil', message, {:value=>value} if value
|
117
149
|
end
|
118
150
|
end
|
119
151
|
|
@@ -121,55 +153,52 @@ module RubyUnit
|
|
121
153
|
# Assert that two values are equal.
|
122
154
|
# * raises RubyUnit::AssertionFailure unless _expected_ equals _actual_
|
123
155
|
#
|
124
|
-
#--
|
125
|
-
# TODO It probably makes sense to rename _expected_ here
|
126
|
-
#++
|
127
156
|
# expected::
|
128
|
-
# The value that is
|
157
|
+
# The value that is forbidden by the assertion
|
129
158
|
#
|
130
159
|
# actual::
|
131
|
-
# The value that is being checked
|
160
|
+
# The value that is being checked by the assertion
|
132
161
|
#
|
133
162
|
# message::
|
134
163
|
# The message provided to be reported for a failure
|
135
164
|
#
|
136
|
-
# assertEqual 42, 24 "This will fail" # => fail
|
165
|
+
# assertEqual 42, 24, "This will fail" # => fail
|
137
166
|
#
|
138
167
|
def assertEqual expected, actual, message = nil
|
139
168
|
__assertion do
|
140
|
-
|
169
|
+
build_message 'Failed to assert that values are equal', message, {:expected=>expected, :actual=>actual} unless expected == actual
|
141
170
|
end
|
142
171
|
end
|
143
172
|
|
144
173
|
#
|
145
174
|
# Assert that two values are NOT equal.
|
146
|
-
# * raises RubyUnit::AssertionFailure if
|
175
|
+
# * raises RubyUnit::AssertionFailure if _illegal_ equals _actual_
|
147
176
|
#
|
148
|
-
#
|
177
|
+
# illegal::
|
149
178
|
# The value that is not allowed by the assertion
|
150
179
|
#
|
151
180
|
# actual::
|
152
|
-
# The value that is being checked
|
181
|
+
# The value that is being checked by the assertion
|
153
182
|
#
|
154
183
|
# message::
|
155
184
|
# The message provided to be reported for a failure
|
156
185
|
#
|
157
|
-
# assertNotEqual 3.14, 3.14 "This will fail" # => fail
|
186
|
+
# assertNotEqual 3.14, 3.14, "This will fail" # => fail
|
158
187
|
#
|
159
|
-
def assertNotEqual
|
188
|
+
def assertNotEqual illegal, actual, message = nil
|
160
189
|
__assertion do
|
161
|
-
|
190
|
+
build_message 'Values should NOT be equal', message, {:illegal=>illegal, :actual=>actual} if illegal == actual
|
162
191
|
end
|
163
192
|
end
|
164
193
|
|
165
194
|
#
|
166
195
|
# Assert that a value matches a Regexp pattern.
|
167
|
-
# * raises RubyUnit::AssertionFailure unless
|
196
|
+
# * raises RubyUnit::AssertionFailure unless _value_ matches _pattern_
|
168
197
|
#
|
169
198
|
# pattern::
|
170
199
|
# A Regexp pattern expected by the assertion
|
171
200
|
#
|
172
|
-
#
|
201
|
+
# value::
|
173
202
|
# The value that is being checked for the assertion
|
174
203
|
#
|
175
204
|
# message::
|
@@ -177,37 +206,27 @@ module RubyUnit
|
|
177
206
|
#
|
178
207
|
# assertMatch /^Hello/, 'Goodbye!', "This will fail" # => fail
|
179
208
|
#
|
180
|
-
def assertMatch pattern,
|
209
|
+
def assertMatch pattern, value, message = nil
|
181
210
|
__assertion do
|
182
|
-
|
211
|
+
build_message 'Failed to assert value matches regular expression', message, {:pattern=>pattern, :value=>value} unless value =~ pattern
|
183
212
|
end
|
184
213
|
end
|
185
214
|
|
186
215
|
#
|
187
216
|
# Assert that a specified exception is raised.
|
188
217
|
# * raises RubyUnit::AssertionFailure unless the correct Exception is raised
|
189
|
-
# * raises ArgumentError unless
|
190
|
-
# * raises ArgumentError
|
191
|
-
#
|
192
|
-
# * raises ArgumentError if the second parameter is provided and is not a
|
193
|
-
# String, Regexp or nil
|
194
|
-
# * raises ArgumentError if the third parameter is provided and is not a
|
195
|
-
# String or nil
|
196
|
-
#
|
197
|
-
# *args::
|
198
|
-
# List of arguments passed in as [expected, pattern, message]. Additional
|
199
|
-
# parameters are ignored.
|
218
|
+
# * raises ArgumentError unless _exception_ is a descendent of the Exception class
|
219
|
+
# * raises ArgumentError if _pattern_ is not a String or Regexp
|
220
|
+
# * raises ArgumentError if _message_ is not a String or nil
|
200
221
|
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
# descendent of the Exception class.
|
222
|
+
# exception::
|
223
|
+
# The Exception class that is expected.
|
204
224
|
#
|
205
225
|
# pattern::
|
206
|
-
#
|
207
|
-
# message
|
226
|
+
# The String or Regexp that will be used to validate the Exception message
|
208
227
|
#
|
209
228
|
# message::
|
210
|
-
#
|
229
|
+
# The message provided to be reported for a failure
|
211
230
|
#
|
212
231
|
# &block::
|
213
232
|
# The code block that is expected to throw the Exception
|
@@ -216,23 +235,18 @@ module RubyUnit
|
|
216
235
|
# raise 'Invalid Retroincabulator'
|
217
236
|
# end
|
218
237
|
#
|
219
|
-
def assertRaiseExpected
|
220
|
-
raise ArgumentError, "
|
221
|
-
|
222
|
-
raise ArgumentError, "expected exception must be a subclass of Exception" unless expected < Exception
|
223
|
-
raise ArgumentError, "exception message must be a Regexp or String" unless pattern.is_a? Regexp or pattern.is_a? String or pattern.nil?
|
238
|
+
def assertRaiseExpected exception, pattern, message = nil, &block
|
239
|
+
raise ArgumentError, "Exception must be a subclass of Exception" unless exception < Exception
|
240
|
+
raise ArgumentError, "exception message must be a Regexp or String" unless pattern.is_a? Regexp or pattern.is_a? String
|
224
241
|
raise ArguemntError, "message must be a String or nil" unless message.is_a? String or message.nil?
|
225
242
|
|
226
243
|
__assertion do
|
227
244
|
begin
|
228
245
|
yield
|
229
|
-
|
230
|
-
rescue
|
231
|
-
if pattern.is_a? String
|
232
|
-
|
233
|
-
elsif pattern.is_a? Regexp
|
234
|
-
assertMatch pattern, e.message
|
235
|
-
end
|
246
|
+
build_message 'Expected exception was not raised', message, {:exception=>exception, :pattern=>pattern}
|
247
|
+
rescue exception => e
|
248
|
+
assertEqual pattern, e.message if pattern.is_a? String
|
249
|
+
assertMatch pattern, e.message if pattern.is_a? Regexp
|
236
250
|
end
|
237
251
|
end
|
238
252
|
end
|
@@ -255,8 +269,8 @@ module RubyUnit
|
|
255
269
|
__assertion do
|
256
270
|
begin
|
257
271
|
yield
|
258
|
-
rescue
|
259
|
-
|
272
|
+
rescue Exception => e
|
273
|
+
build_message 'Exception was thrown but not expected', message, {:exception=>e.message}
|
260
274
|
end
|
261
275
|
end
|
262
276
|
end
|
@@ -280,14 +294,13 @@ module RubyUnit
|
|
280
294
|
#
|
281
295
|
def assertIsA klass, object, message = nil
|
282
296
|
__assertion do
|
283
|
-
|
297
|
+
build_message 'Failed to assert object heritage', message, {:klass=>klass, :object=>object} unless object.is_a? klass
|
284
298
|
end
|
285
299
|
end
|
286
300
|
|
287
301
|
#
|
288
302
|
# Assert that an object is an instance of a specified class
|
289
|
-
# * raises RubyUnit::AssertionFailure unless _object_ is an instance of
|
290
|
-
# _klass_.
|
303
|
+
# * raises RubyUnit::AssertionFailure unless _object_ is an instance of _klass_.
|
291
304
|
#
|
292
305
|
# klass::
|
293
306
|
# The class that is expected
|
@@ -302,7 +315,7 @@ module RubyUnit
|
|
302
315
|
#
|
303
316
|
def assertInstanceOf klass, object, message = nil
|
304
317
|
__assertion do
|
305
|
-
|
318
|
+
build_message 'Failed to assert correct instance', message, {:klass=>klass, :object=>object} unless object.instance_of? klass
|
306
319
|
end
|
307
320
|
end
|
308
321
|
|
@@ -324,33 +337,29 @@ module RubyUnit
|
|
324
337
|
#
|
325
338
|
def assertSame expected, actual, message = nil
|
326
339
|
__assertion do
|
327
|
-
|
340
|
+
build_message 'Failed to assert object are the same', message, {:expected=>expected, :actual=>actual} unless expected.equal? actual
|
328
341
|
end
|
329
342
|
end
|
330
343
|
|
331
344
|
#
|
332
345
|
# Assert that two objects are not the same object
|
333
|
-
# * raises RubyUnit::AssertionFailure if
|
346
|
+
# * raises RubyUnit::AssertionFailure if _illegal_ and _actual_ are the
|
334
347
|
# same object.
|
335
348
|
#
|
336
|
-
|
337
|
-
# TODO It probably makes sense to rename this one too
|
338
|
-
#++
|
339
|
-
# expected::
|
349
|
+
# illegal::
|
340
350
|
# The expected that it shouldn't be
|
341
351
|
#
|
342
352
|
# actual::
|
343
|
-
# The object that is being checked against
|
353
|
+
# The object that is being checked against _illegal_
|
344
354
|
#
|
345
355
|
# message::
|
346
356
|
# The message provided to be reported for a failure
|
347
357
|
#
|
348
|
-
# value
|
349
|
-
# assertSame value, value, 'Imagine that!' # => fail
|
358
|
+
# assertNotSame value, value, 'Imagine that!' # => fail
|
350
359
|
#
|
351
|
-
def assertNotSame
|
360
|
+
def assertNotSame illegal, actual, message = nil
|
352
361
|
__assertion do
|
353
|
-
|
362
|
+
build_message 'Failed to assert objects are NOT the same', message, {:illegal=>illegal, :actual=>actual} if illegal.equal? actual
|
354
363
|
end
|
355
364
|
end
|
356
365
|
|
@@ -404,7 +413,7 @@ module RubyUnit
|
|
404
413
|
def assertConstDefined klass, konstant, message = nil
|
405
414
|
raise ArgumentError, 'Constant name must be given as a String' unless konstant.is_a? String
|
406
415
|
__assertion do
|
407
|
-
|
416
|
+
build_message 'Failed to assert constant is defined', message, {:klass=>klass, :konstant=>konstant} unless klass.const_defined? konstant
|
408
417
|
end
|
409
418
|
end
|
410
419
|
|
@@ -428,7 +437,7 @@ module RubyUnit
|
|
428
437
|
def assertConstNotDefined klass, konstant, message = nil
|
429
438
|
raise ArgumentError, 'Constant name must be given as a String' unless konstant.is_a? String
|
430
439
|
__assertion do
|
431
|
-
|
440
|
+
build_message 'Constant should not be defined', message, {:klass=>klass, :konstant=>konstant} if klass.const_defined? konstant
|
432
441
|
end
|
433
442
|
end
|
434
443
|
|
data/lib/RubyUnit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyunit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Clower
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Unit testing and test-driven development are crucial parts ofthe software
|
14
14
|
development life cycle. This tool is intended tomake development and testing in
|