rubyunit 0.0.5 → 0.1.6
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/README.md +16 -9
- data/example/TestSet.rb +1 -1
- data/lib/RubyUnit/AssertionFailure.rb +7 -0
- data/lib/RubyUnit/Runner.rb +58 -4
- data/lib/RubyUnit/TestCase.rb +281 -6
- data/lib/RubyUnit.rb +46 -23
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59aa4f7b242f3ddc81d73520e4325a2b025004fb
|
4
|
+
data.tar.gz: f6cb7b9b0a8445b43e2e669be8e8904eeb763473
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 875ebe75d487403a20c131f079d2b8c94aa84da7bda10a2dc7a98d33209d170906be19a975bc0133060978a7e13aaeadfbae5960f56d29673f3cc073bb5c71c0
|
7
|
+
data.tar.gz: 6dd66e51da74b120b158a90c1fe8364a1539a0af33a29f0eaa30712869af383b4a6475aa2361656bdb3989e6d1b14715d0f7fd43db3ca7e361c7331d0688a13e
|
data/README.md
CHANGED
@@ -1,27 +1,34 @@
|
|
1
1
|
RubyUnit
|
2
2
|
========
|
3
3
|
|
4
|
-
[](http://badge.fury.io/rb/rubyunit)
|
5
5
|
[](https://codeclimate.com/github/RubyUnit/RubyUnit)
|
6
6
|
[](https://codeclimate.com/github/RubyUnit/RubyUnit)
|
7
7
|
|
8
|
+
### Practical Examples
|
9
|
+
* https://github.com/matthewclower/PlayingCards
|
10
|
+
|
8
11
|
|
12
|
+
### Links
|
9
13
|
* http://rubyunit.github.io/
|
10
14
|
* https://github.com/RubyUnit/RubyUnit
|
11
15
|
|
12
16
|
|
13
|
-
|
14
|
-
* https://github.com/matthewclower/PlayingCards
|
15
|
-
|
16
|
-
## Description
|
17
|
+
### Description
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
Unit testing and test-driven development is a crucial part of the software
|
20
|
+
development life cycle. This tool is intended to make development and
|
21
|
+
testing in Ruby easier on everyone.
|
20
22
|
|
21
|
-
|
23
|
+
### Install
|
22
24
|
|
23
25
|
```bash
|
24
26
|
$ gem install rubyunit
|
25
27
|
```
|
26
28
|
|
27
|
-
|
29
|
+
### Contact
|
30
|
+
Please submit issues and feature requests to the github issue tracking page
|
31
|
+
https://github.com/RubyUnit/RubyUnit/issues
|
32
|
+
|
33
|
+
|
34
|
+
* Copyright (c) 2014, Matthew Clower
|
data/example/TestSet.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module RubyUnit
|
2
|
+
#
|
3
|
+
# = RubyUnit::AssertionFailure
|
4
|
+
# Exception that is raised when a test assertion fails.
|
5
|
+
#
|
6
|
+
# TODO add some things to this object:
|
7
|
+
# * Excpetion info so that better reporting can be generated
|
8
|
+
#
|
2
9
|
class AssertionFailure < StandardError
|
3
10
|
end
|
4
11
|
end
|
data/lib/RubyUnit/Runner.rb
CHANGED
@@ -2,18 +2,44 @@ require_relative 'TestCase'
|
|
2
2
|
require_relative 'AssertionFailure'
|
3
3
|
|
4
4
|
module RubyUnit
|
5
|
+
#
|
6
|
+
# This is the test runner.
|
7
|
+
# Done, and done.
|
8
|
+
#
|
5
9
|
class Runner
|
6
10
|
class << self
|
7
11
|
protected
|
12
|
+
#--
|
13
|
+
# Most of these variables need to be refactored. This is made so it can
|
14
|
+
# be used, but it's not very far along.
|
15
|
+
#++
|
16
|
+
# The list of Test Cases that have been run are are currently running
|
8
17
|
@@test_cases = []
|
18
|
+
# The list of RubyUnit::AssertionFailure exceptions that were caught by the
|
19
|
+
# test runner during testing
|
9
20
|
@@failures = []
|
21
|
+
# The list of non RubyUnit::AssertionFailure exceptions that were caught by
|
22
|
+
# the test runner during testing
|
10
23
|
@@errors = []
|
24
|
+
# The total number of tests that have been run
|
11
25
|
@@tests = 0
|
26
|
+
# The time the tests were started
|
12
27
|
@@start = nil
|
28
|
+
# The time the tests completed
|
13
29
|
@@finish = nil
|
30
|
+
# Whether or not the test suite still needs to be run. This is used by the
|
31
|
+
# automatic runner to determine if it must be run before the program exits.
|
14
32
|
@@autorun = true
|
15
33
|
|
16
34
|
public
|
35
|
+
#
|
36
|
+
# The static test runner
|
37
|
+
# * raises ArgumentError if any data method doesn't return an array
|
38
|
+
# * raises ArgumentError if any data method doesn't return an array of arrays
|
39
|
+
# * Returns the sum of the failure and error counts
|
40
|
+
#
|
41
|
+
# RubyUnit::Runner.run
|
42
|
+
#
|
17
43
|
def run
|
18
44
|
@@autorun = false
|
19
45
|
@@start = Time.new
|
@@ -30,9 +56,9 @@ module RubyUnit
|
|
30
56
|
test_case = object.new
|
31
57
|
data = test_case.send data_method
|
32
58
|
|
33
|
-
raise "Data method #{data_method} must return an array" unless data.is_a? Array
|
59
|
+
raise ArgumentError, "Data method #{data_method} must return an array" unless data.is_a? Array
|
34
60
|
data.each do |params|
|
35
|
-
raise "Data method #{data_method} must return an array of arrays" unless data.is_a? Array
|
61
|
+
raise ArgumentError, "Data method #{data_method} must return an array of arrays" unless data.is_a? Array
|
36
62
|
runner.run object, test, params
|
37
63
|
end
|
38
64
|
else
|
@@ -45,14 +71,26 @@ module RubyUnit
|
|
45
71
|
@@failures.count + @@errors.count
|
46
72
|
end
|
47
73
|
|
74
|
+
#
|
75
|
+
# Whether or not the test suite still needs to be run. This is used by the
|
76
|
+
# automatic runner to determine if it must be run before the program exits.
|
77
|
+
#
|
78
|
+
# RubyUnit::Runner.autorun?
|
79
|
+
#
|
48
80
|
def autorun?
|
49
81
|
@@autorun
|
50
82
|
end
|
51
83
|
|
52
84
|
protected
|
85
|
+
#
|
86
|
+
# Prints the report after testing has been completed. This mehtod is protected and
|
87
|
+
# is called by the global runner unless no tests have been run.
|
88
|
+
#
|
89
|
+
# report # => nice and simple
|
90
|
+
#
|
53
91
|
def report
|
54
92
|
# haven't figured out what I want to do for reporting yet but I need some results
|
55
|
-
puts "RubyUnit #{RubyUnit::
|
93
|
+
puts "RubyUnit #{RubyUnit::VERSION}"
|
56
94
|
puts "Started Tests #{@@start.strftime("%Y-%m-%d %H:%M:%S")}"
|
57
95
|
|
58
96
|
puts "#{@@errors.count} Errors:\n" if @@errors.count > 0
|
@@ -76,11 +114,27 @@ module RubyUnit
|
|
76
114
|
puts "%.3f tests/s, %.3f assertions/s" % [(@@tests * inverse).to_f, (TestCase.assertions * inverse).to_f]
|
77
115
|
puts "%d Tests, %d Assertions, %d Errors, %d Failures" % [@@tests, TestCase.assertions, @@errors.count, @@failures.count]
|
78
116
|
puts
|
79
|
-
|
80
117
|
end
|
81
118
|
end
|
82
119
|
|
83
120
|
public
|
121
|
+
#
|
122
|
+
# Run a test and record the results. The test object is instantiated and
|
123
|
+
# RubyUnit::TestCase.setup is called. RubyUnit::TestCase.teardown is called
|
124
|
+
# after the test has finished. This is called by the static runner.
|
125
|
+
# * raises ArgumentError unless _params_ is an Array
|
126
|
+
#
|
127
|
+
# object::
|
128
|
+
# The test case that has the test
|
129
|
+
#
|
130
|
+
# test::
|
131
|
+
# The test that is going to be run
|
132
|
+
#
|
133
|
+
# params::
|
134
|
+
# The parameters that are passed to test execution
|
135
|
+
#
|
136
|
+
# run TestCaseClass, :myTest, [param1, param2]
|
137
|
+
#
|
84
138
|
def run object, test, params = []
|
85
139
|
raise ArgumentError, "Parameter list for #{object.class}::#{test} must be an array" unless params.is_a? Array
|
86
140
|
|
data/lib/RubyUnit/TestCase.rb
CHANGED
@@ -1,60 +1,224 @@
|
|
1
1
|
require_relative 'AssertionFailure'
|
2
2
|
|
3
3
|
module RubyUnit
|
4
|
+
#
|
5
|
+
# = RubyUnit::TestCase
|
6
|
+
#
|
7
|
+
# All classes derrived from the RubyUnit::TestCase will automatically be run by
|
8
|
+
# the test runner.
|
9
|
+
# * Test methods must currently be named ending in 'Test'
|
10
|
+
# * Data methods must currently be named ending in 'Data'
|
11
|
+
# All data methods must return an array of arrays as param lists to passed to
|
12
|
+
# the corresponding test method.
|
13
|
+
# * Exceptions raised in this class are generally caught by the RubyUnit::Runner
|
14
|
+
#
|
15
|
+
# MyTest < RubyUnit::TestCase
|
16
|
+
# def simpleData
|
17
|
+
# [
|
18
|
+
# [ 1, 3],
|
19
|
+
# ['string', nil],
|
20
|
+
# ],
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def simpleTest param1, param2
|
24
|
+
# # run assertions
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
4
28
|
class TestCase
|
5
29
|
public
|
30
|
+
|
31
|
+
#
|
32
|
+
# The setup helper that is run before each test in the test case.
|
33
|
+
#
|
34
|
+
# def setup
|
35
|
+
# # create objects, set up the scenario
|
36
|
+
# end
|
37
|
+
#
|
6
38
|
def setup
|
7
39
|
end
|
8
40
|
|
41
|
+
#
|
42
|
+
# The teardown helper that is run after each test in the test case.
|
43
|
+
#
|
44
|
+
# def teardown
|
45
|
+
# # destroy objects, clean up after yourself
|
46
|
+
# end
|
47
|
+
#
|
9
48
|
def teardown
|
10
49
|
end
|
11
50
|
|
12
51
|
private
|
13
|
-
|
52
|
+
#
|
53
|
+
# The assertion wrapper is responsible for doing everything that must be done
|
54
|
+
# on each assertion.
|
55
|
+
# * keep track of the total number of assertions
|
56
|
+
#
|
57
|
+
# &block::
|
58
|
+
# The assertion which is being wrapped
|
59
|
+
#
|
60
|
+
def __assertion &block # :nodoc:
|
14
61
|
@@assertions += 1
|
15
62
|
yield
|
16
63
|
end
|
17
64
|
|
18
65
|
protected
|
66
|
+
|
67
|
+
#
|
68
|
+
# Fail the test. This is used when some conditioned outside the test warrants
|
69
|
+
# a test failure.
|
70
|
+
# * This is likely an indication of something unexpected or missing functionality
|
71
|
+
# * raises RubyUnit::AssertionFailure
|
72
|
+
#
|
73
|
+
# message::
|
74
|
+
# The message provided to be reported for a failure
|
75
|
+
#
|
76
|
+
# fail "I wasn't expecting the moon to fall into Lake Michigan" # => fail
|
77
|
+
#
|
19
78
|
def fail message = nil
|
20
79
|
__assertion do
|
21
80
|
raise AssertionFailure, message
|
22
81
|
end
|
23
82
|
end
|
24
83
|
|
84
|
+
#
|
85
|
+
# Assert that a test condition is true.
|
86
|
+
# * raises RubyUnit::AssertionFailure unless _expected_ is true
|
87
|
+
#
|
88
|
+
# expected::
|
89
|
+
# The value that is being checked for the assertion
|
90
|
+
#
|
91
|
+
# message::
|
92
|
+
# The message provided to be reported for a failure
|
93
|
+
#
|
94
|
+
# assert false "This will fail" # => fail
|
95
|
+
#
|
25
96
|
def assert expected, message = nil
|
26
97
|
__assertion do
|
27
98
|
raise AssertionFailure, message unless expected
|
28
99
|
end
|
29
100
|
end
|
30
101
|
|
102
|
+
#
|
103
|
+
# Assert that a test condition is false.
|
104
|
+
# * raises RubyUnit::AssertionFailure if _expected_ is true
|
105
|
+
#
|
106
|
+
# expected::
|
107
|
+
# The value that is being checked for the assertion
|
108
|
+
#
|
109
|
+
# message::
|
110
|
+
# The message provided to be reported for a failure
|
111
|
+
#
|
112
|
+
# assertNot true "This will fail" # => fail
|
113
|
+
#
|
31
114
|
def assertNot expected, message = nil
|
32
115
|
__assertion do
|
33
116
|
raise AssertionFailure, message if expected
|
34
117
|
end
|
35
118
|
end
|
36
119
|
|
120
|
+
#
|
121
|
+
# Assert that two values are equal.
|
122
|
+
# * raises RubyUnit::AssertionFailure unless _expected_ equals _actual_
|
123
|
+
#
|
124
|
+
#--
|
125
|
+
# TODO It probably makes sense to rename _expected_ here
|
126
|
+
#++
|
127
|
+
# expected::
|
128
|
+
# The value that is expected by the assertion
|
129
|
+
#
|
130
|
+
# actual::
|
131
|
+
# The value that is being checked for the assertion
|
132
|
+
#
|
133
|
+
# message::
|
134
|
+
# The message provided to be reported for a failure
|
135
|
+
#
|
136
|
+
# assertEqual 42, 24 "This will fail" # => fail
|
137
|
+
#
|
37
138
|
def assertEqual expected, actual, message = nil
|
38
139
|
__assertion do
|
39
140
|
raise AssertionFailure, message unless expected == actual
|
40
141
|
end
|
41
142
|
end
|
42
143
|
|
144
|
+
#
|
145
|
+
# Assert that two values are NOT equal.
|
146
|
+
# * raises RubyUnit::AssertionFailure if _expected_ equals _actual_
|
147
|
+
#
|
148
|
+
# expected::
|
149
|
+
# The value that is not allowed by the assertion
|
150
|
+
#
|
151
|
+
# actual::
|
152
|
+
# The value that is being checked for the assertion
|
153
|
+
#
|
154
|
+
# message::
|
155
|
+
# The message provided to be reported for a failure
|
156
|
+
#
|
157
|
+
# assertNotEqual 3.14, 3.14 "This will fail" # => fail
|
158
|
+
#
|
43
159
|
def assertNotEqual expected, actual, message = nil
|
44
160
|
__assertion do
|
45
161
|
raise AssertionFailure, message if expected == actual
|
46
162
|
end
|
47
163
|
end
|
48
164
|
|
165
|
+
#
|
166
|
+
# Assert that a value matches a Regexp pattern.
|
167
|
+
# * raises RubyUnit::AssertionFailure unless _actual_ matches _pattern_
|
168
|
+
#
|
169
|
+
# pattern::
|
170
|
+
# A Regexp pattern expected by the assertion
|
171
|
+
#
|
172
|
+
# actual::
|
173
|
+
# The value that is being checked for the assertion
|
174
|
+
#
|
175
|
+
# message::
|
176
|
+
# The message provided to be reported for a failure
|
177
|
+
#
|
178
|
+
# assertMatch /^Hello/, 'Goodbye!', "This will fail" # => fail
|
179
|
+
#
|
49
180
|
def assertMatch pattern, actual, message = nil
|
50
181
|
__assertion do
|
51
182
|
raise AssertionFailure, message unless actual =~ pattern
|
52
183
|
end
|
53
184
|
end
|
54
185
|
|
186
|
+
#
|
187
|
+
# Assert that a specified exception is raised.
|
188
|
+
# * raises RubyUnit::AssertionFailure unless the correct Exception is raised
|
189
|
+
# * raises ArgumentError unless the parameter count is positive
|
190
|
+
# * raises ArgumentError unless the first parameter is a descendent of the
|
191
|
+
# Exception class
|
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.
|
200
|
+
#
|
201
|
+
# expected::
|
202
|
+
# *required*: The Exception class that is expected. The Exception must be a
|
203
|
+
# descendent of the Exception class.
|
204
|
+
#
|
205
|
+
# pattern::
|
206
|
+
# _optional_: The String or Regexp that will be used to validate the Exception
|
207
|
+
# message
|
208
|
+
#
|
209
|
+
# message::
|
210
|
+
# _optional_: The message provided to be reported for a failure
|
211
|
+
#
|
212
|
+
# &block::
|
213
|
+
# The code block that is expected to throw the Exception
|
214
|
+
#
|
215
|
+
# assertRaiseExpected Exception, /^Invalid/, 'Expecting an exception!' do
|
216
|
+
# raise 'Invalid Retroincabulator'
|
217
|
+
# end
|
218
|
+
#
|
55
219
|
def assertRaiseExpected *args, &block
|
56
220
|
__assertion do
|
57
|
-
raise ArgumentError, "wrong number of arguments (#{args.count} for 2..3)" unless args.count
|
221
|
+
raise ArgumentError, "wrong number of arguments (#{args.count} for 2..3)" unless args.count > 0
|
58
222
|
expected, pattern, message = args
|
59
223
|
raise ArgumentError, "expected exception must be a subclass of Exception" unless expected < Exception
|
60
224
|
raise ArgumentError, "exception message must be a Regexp or String" unless pattern.is_a? Regexp or pattern.is_a? String or pattern.nil?
|
@@ -73,6 +237,20 @@ module RubyUnit
|
|
73
237
|
end
|
74
238
|
end
|
75
239
|
|
240
|
+
#
|
241
|
+
# Assert that no exception is raised.
|
242
|
+
# * raises RubyUnit::AssertionFailure if any exception is raised
|
243
|
+
#
|
244
|
+
# message::
|
245
|
+
# The message provided to be reported for a failure
|
246
|
+
#
|
247
|
+
# &block::
|
248
|
+
# The code block that is executed
|
249
|
+
#
|
250
|
+
# assertNothingRaised 'Not expecting an exception!' do
|
251
|
+
# # do something
|
252
|
+
# end
|
253
|
+
#
|
76
254
|
def assertNothingRaised message = nil, &block
|
77
255
|
__assertion do
|
78
256
|
begin
|
@@ -83,34 +261,121 @@ module RubyUnit
|
|
83
261
|
end
|
84
262
|
end
|
85
263
|
|
264
|
+
#
|
265
|
+
# Assert that an object is an instance of the specified class or one of
|
266
|
+
# its descendents.
|
267
|
+
# * raises RubyUnit::AssertionFailure unless _object_ is an instance of
|
268
|
+
# _klass_ or one of its descendents.
|
269
|
+
#
|
270
|
+
# klass::
|
271
|
+
# The class that is expected
|
272
|
+
#
|
273
|
+
# object::
|
274
|
+
# The object that will be checked against _klass_
|
275
|
+
#
|
276
|
+
# message::
|
277
|
+
# The message provided to be reported for a failure
|
278
|
+
#
|
279
|
+
# assertIsA String, 25, 'Nope, try again.' # => fail
|
280
|
+
#
|
86
281
|
def assertIsA klass, object, message = nil
|
87
282
|
__assertion do
|
88
|
-
raise AssertionFailure, message unless
|
283
|
+
raise AssertionFailure, message unless object.is_a? klass
|
89
284
|
end
|
90
285
|
end
|
91
286
|
|
287
|
+
#
|
288
|
+
# Assert that an object is an instance of a specified class
|
289
|
+
# * raises RubyUnit::AssertionFailure unless _object_ is an instance of
|
290
|
+
# _klass_.
|
291
|
+
#
|
292
|
+
# klass::
|
293
|
+
# The class that is expected
|
294
|
+
#
|
295
|
+
# object::
|
296
|
+
# The object that will be checked against _klass_
|
297
|
+
#
|
298
|
+
# message::
|
299
|
+
# The message provided to be reported for a failure
|
300
|
+
#
|
301
|
+
# assertInstanceOf Integer, '25', 'So close, but... No.' # => fail
|
302
|
+
#
|
92
303
|
def assertInstanceOf klass, object, message = nil
|
93
304
|
__assertion do
|
94
|
-
assertIsA Class, klass, message
|
95
305
|
raise AssertionFailure, message unless object.instance_of? klass
|
96
306
|
end
|
97
307
|
end
|
98
308
|
|
309
|
+
#
|
310
|
+
# Assert that two objects are the same object
|
311
|
+
# * raises RubyUnit::AssertionFailure unless _expected_ and _actual_ are
|
312
|
+
# the same object.
|
313
|
+
#
|
314
|
+
# expected::
|
315
|
+
# The expected object
|
316
|
+
#
|
317
|
+
# actual::
|
318
|
+
# The object that is being checked against _expected_
|
319
|
+
#
|
320
|
+
# message::
|
321
|
+
# The message provided to be reported for a failure
|
322
|
+
#
|
323
|
+
# assertSame '42', 42, 'Not even close.' # => fail
|
324
|
+
#
|
99
325
|
def assertSame expected, actual, message = nil
|
100
326
|
__assertion do
|
101
327
|
raise AssertionFailure, message unless expected.equal? actual
|
102
328
|
end
|
103
329
|
end
|
104
330
|
|
331
|
+
#
|
332
|
+
# Assert that two objects are not the same object
|
333
|
+
# * raises RubyUnit::AssertionFailure if _expected_ and _actual_ are the
|
334
|
+
# same object.
|
335
|
+
#
|
336
|
+
#--
|
337
|
+
# TODO It probably makes sense to rename this one too
|
338
|
+
#++
|
339
|
+
# expected::
|
340
|
+
# The expected that it shouldn't be
|
341
|
+
#
|
342
|
+
# actual::
|
343
|
+
# The object that is being checked against _expected_
|
344
|
+
#
|
345
|
+
# message::
|
346
|
+
# The message provided to be reported for a failure
|
347
|
+
#
|
348
|
+
# value = 42
|
349
|
+
# assertSame value, value, 'Imagine that!' # => fail
|
350
|
+
#
|
105
351
|
def assertNotSame expected, actual, message = nil
|
106
352
|
__assertion do
|
107
353
|
raise AssertionFailure, message if expected.equal? actual
|
108
354
|
end
|
109
355
|
end
|
110
356
|
|
357
|
+
#
|
358
|
+
# Assert that a constant is defined correctly in the correct class
|
359
|
+
# * raises RubyUnit::AssertionFailure unless the constant is defined in
|
360
|
+
# the specified class and it is the correct type and value
|
361
|
+
#
|
362
|
+
# expected::
|
363
|
+
# The value that is expected for the constant
|
364
|
+
#
|
365
|
+
# klass::
|
366
|
+
# The class where the constant should be defined
|
367
|
+
#
|
368
|
+
# konstant::
|
369
|
+
# The name of the constant expressed as a String so that it can be
|
370
|
+
# validated in the class
|
371
|
+
#
|
372
|
+
# message::
|
373
|
+
# The message provided to be reported for a failure
|
374
|
+
#
|
375
|
+
# assertConst 42, Numbers, 'TWENTYFOUR', 'So dyslexic.' # => fail
|
376
|
+
#
|
111
377
|
def assertConst expected, klass, konstant, message = nil
|
112
378
|
__assertion do
|
113
|
-
assertIsA Class, klass, message
|
114
379
|
value = klass.const_get konstant
|
115
380
|
assertIsA expected.class, value, message
|
116
381
|
assertEqual expected, value, message
|
@@ -118,14 +383,24 @@ module RubyUnit
|
|
118
383
|
end
|
119
384
|
|
120
385
|
class << self
|
386
|
+
private
|
387
|
+
# Tracks the total number of assertions made during the tests
|
121
388
|
@@assertions = 0
|
122
389
|
|
390
|
+
public
|
391
|
+
#
|
392
|
+
# Gets a list of all the descendents of the RubyUnit::TestCase class.
|
393
|
+
# This is important when determining the tests that have been defined.
|
394
|
+
#
|
123
395
|
def descendents
|
124
396
|
ObjectSpace.each_object(Class).select do |object|
|
125
397
|
object < self
|
126
398
|
end
|
127
399
|
end
|
128
|
-
|
400
|
+
|
401
|
+
#
|
402
|
+
# Gets the current number of assertions that have been run while testing
|
403
|
+
#
|
129
404
|
def assertions
|
130
405
|
@@assertions
|
131
406
|
end
|
data/lib/RubyUnit.rb
CHANGED
@@ -1,30 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# = RubyUnit
|
3
|
+
# A Simple Unit Test Framework for Ruby
|
4
|
+
#
|
5
|
+
# The RubyModule is the root object for all RubyUnit modules and classes.
|
6
|
+
#
|
1
7
|
module RubyUnit
|
2
|
-
|
3
|
-
VERSION = '0.
|
8
|
+
# Current RubyUnit version
|
9
|
+
VERSION = '0.1.6'
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def self.build
|
12
|
-
@@build
|
13
|
-
end
|
11
|
+
#
|
12
|
+
# RubyUnit::GemInfo contains data and functionality needed by the gem builder
|
13
|
+
# when building and distributing the RubyUnit gem.
|
14
|
+
#
|
15
|
+
module GemInfo
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
#
|
18
|
+
# Provides a list of all the files required by this gem
|
19
|
+
#
|
20
|
+
# spec.files = RubyUnit::GemInfo.files
|
21
|
+
#
|
22
|
+
def self.files
|
23
|
+
# local one-off directory
|
24
|
+
static = ['README.md', 'LICENSE']
|
25
|
+
# libraries
|
26
|
+
libs = Dir['lib/**/*.rb']
|
27
|
+
# examples
|
28
|
+
examples = Dir['example/*.rb']
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
def files
|
22
|
-
static = ['README.md', 'LICENSE']
|
23
|
-
libs = Dir['lib/**/*.rb']
|
24
|
-
examples = Dir['example/*.rb']
|
30
|
+
static + libs + examples
|
31
|
+
end
|
25
32
|
|
26
|
-
|
27
|
-
|
33
|
+
#
|
34
|
+
# Provides a longer description of the RubyUnit gem
|
35
|
+
#
|
36
|
+
# spec.description = RubyUnit::GemInfo.description
|
37
|
+
#
|
38
|
+
def self.description
|
39
|
+
'Unit testing and test-driven development is a crucial part of the software ' +
|
40
|
+
'development life cycle. This tool is intended to make development and ' +
|
41
|
+
'testing in Ruby easier on everyone.'
|
28
42
|
end
|
29
43
|
end
|
30
44
|
end
|
@@ -32,9 +46,18 @@ end
|
|
32
46
|
require_relative 'RubyUnit/TestCase'
|
33
47
|
require_relative 'RubyUnit/Runner'
|
34
48
|
|
35
|
-
# Automatically run
|
49
|
+
# Automatically Run Test Cases if they haven't been run already
|
36
50
|
Module.new do
|
51
|
+
#
|
52
|
+
# Automatically run defined Test Cases
|
53
|
+
#
|
54
|
+
#--
|
55
|
+
# TODO: add alias and call the alias so that the function doesn't break any
|
56
|
+
# functionality that may have also extended this event. Before/After?
|
57
|
+
#++
|
58
|
+
#
|
37
59
|
at_exit do
|
60
|
+
# Don't run if it there is an exception or it has already been run
|
38
61
|
if $ERROR_INFO.nil? and RubyUnit::Runner.autorun?
|
39
62
|
RubyUnit::Runner.run
|
40
63
|
end
|
metadata
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyunit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.6
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Unit testing and test-driven development is a crucial part of the software
|
14
|
+
development life cycle. This tool is intended to make development and testing in
|
15
|
+
Ruby easier on everyone.
|
14
16
|
email:
|
15
17
|
- matthewclower@gmail.com
|
16
18
|
executables: []
|
@@ -30,8 +32,10 @@ files:
|
|
30
32
|
- lib/RubyUnit/TestCase.rb
|
31
33
|
homepage: http://github.com/RubyUnit/RubyUnit
|
32
34
|
licenses:
|
35
|
+
- Ruby
|
33
36
|
- LGPL
|
34
|
-
metadata:
|
37
|
+
metadata:
|
38
|
+
Issue Tracker: https://github.com/RubyUnit/RubyUnit/issues
|
35
39
|
post_install_message: Happy Testing!
|
36
40
|
rdoc_options: []
|
37
41
|
require_paths:
|
@@ -51,5 +55,5 @@ rubyforge_project:
|
|
51
55
|
rubygems_version: 2.2.2
|
52
56
|
signing_key:
|
53
57
|
specification_version: 4
|
54
|
-
summary: Unit Test Framework
|
58
|
+
summary: A Simple Unit Test Framework
|
55
59
|
test_files: []
|