rubyunit 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b282fd7aea1c73823b348dba0c1490f0c524033
4
+ data.tar.gz: 688fc628ab4914478f43ea9725fae391f95bf84f
5
+ SHA512:
6
+ metadata.gz: 0297326918d2fe02b3698824c848fa08abc21fb868f78abc5204f405723aa9885e190ee1429242faa18676e9a9b04d194334f43d56323fa8809bb9a3d83b889e
7
+ data.tar.gz: 9d5c621bd08a22bd1016ecce2a52323d29152a369f9353d16f23a330fc2be754e7072fdda1f780455c820d3fd202ab3ecc3dc661693e77524e84d30a808eabf5
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ RubyUnit
2
+ ========
3
+
4
+ * https://github.com/RubyUnit/RubyUnit
5
+
6
+ ## Description
7
+
8
+ A simple Unit Test framework for Ruby
9
+
10
+ ## TODO:
11
+
12
+ * Flesh out assertion list
13
+ * Improve error/failure handling and reporting
14
+ * Build mock object and fixture templates
15
+ * Build tests for framework
16
+ * Add comments to existing code
17
+ * Build documentation
18
+ * Build better robust data driven test functionality
19
+ * Build configuration mechanism (also need to decide what is configurable)
20
+ * Build code coverage reporting
21
+ * Implement multi-threaded testing
22
+ * Add test dependencies for test
23
+
24
+ ### Ruby Gem
25
+ * Get gem version from library
26
+ * Update summary and description to pull a doc
27
+
28
+ ### In Progress
29
+ * Create Ruby Gem from unit test framework
@@ -0,0 +1,27 @@
1
+ # Real Numbers (not complex)
2
+ module RealNumber
3
+ # determines if a number is greater than zero
4
+ def positive?
5
+ self > 0
6
+ end
7
+
8
+ # determines if a number is less than zero
9
+ def negative?
10
+ self < 0
11
+ end
12
+ end
13
+
14
+ class Integer
15
+ # mixin RealNumber into Integer
16
+ include RealNumber
17
+ end
18
+
19
+ class Float
20
+ # mixin RealNumber into Float
21
+ include RealNumber
22
+ end
23
+
24
+ class Rational
25
+ # mixin RealNumber into Rational
26
+ include RealNumber
27
+ end
@@ -0,0 +1,69 @@
1
+ require_relative 'RealNumber'
2
+
3
+ # Test for RealNumber mixin
4
+ class RealNumberTest < RubyUnit::TestCase
5
+ def positiveTest value
6
+ assert value.positive?, "#{value.class}:(#{value}) should be positive!"
7
+ end
8
+
9
+ def notPositiveTest value
10
+ assertNot value.positive?, "#{value.class}:(#{value}) should not be positive!"
11
+ end
12
+
13
+ def negativeTest value
14
+ assert value.negative?, "#{value.class}:(#{value}) should be negative!"
15
+ end
16
+
17
+ def notNegativeTest value
18
+ assertNot value.negative?, "#{value.class}:(#{value}) should not be negative!"
19
+ end
20
+ end
21
+
22
+ # Extend the class to add data providing functions
23
+ class RealNumberTest
24
+ def positiveData
25
+ [
26
+ [ Integer(1),],
27
+ [ Integer(4242),],
28
+ [Integer(100000000000),],
29
+ [Integer(424200000000),],
30
+ [ Float(0.1),],
31
+ [ Float(1.0),],
32
+ [ Float(42.42),],
33
+ [ Rational(1,42),],
34
+ [ Rational(1,1),],
35
+ [ Rational(4242,42),],
36
+ ]
37
+ end
38
+
39
+ def zeroData
40
+ [
41
+ [ Integer(0)],
42
+ [ Float(0.0)],
43
+ [Rational(0,1)],
44
+ ]
45
+ end
46
+
47
+ def negativeData
48
+ [
49
+ [ Integer(-1),],
50
+ [ Integer(-4242),],
51
+ [Integer(-100000000000),],
52
+ [Integer(-424200000000),],
53
+ [ Float(-0.1),],
54
+ [ Float(-1.0),],
55
+ [ Float(-42.42),],
56
+ [ Rational(-1,42),],
57
+ [ Rational(-1,1),],
58
+ [ Rational(-4242,42),],
59
+ ]
60
+ end
61
+
62
+ def notPositiveData
63
+ zeroData + negativeData
64
+ end
65
+
66
+ def notNegativeData
67
+ zeroData + positiveData
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ module RubyUnit
2
+ class AssertionFailure < StandardError
3
+ end
4
+ end
@@ -0,0 +1,93 @@
1
+ require 'RubyUnit/TestCase'
2
+ require 'RubyUnit/AssertionFailure'
3
+
4
+ module RubyUnit
5
+ class Runner
6
+ protected
7
+ @@test_cases = []
8
+ @@failures = []
9
+ @@errors = []
10
+ @@tests = 0
11
+ @@start = nil
12
+ @@finish = nil
13
+
14
+ class << self
15
+ public
16
+ def run
17
+ @@start = Time.new
18
+ runner = new
19
+ TestCase.descendents.each do |object|
20
+ @@test_cases << object
21
+
22
+ data_methods = object.instance_methods.grep /Data\Z/
23
+ test_methods = object.instance_methods.grep /Test\Z/
24
+
25
+ test_methods.each do |test|
26
+ data_method = "#{test.slice(0..-5)}Data".to_sym
27
+ if data_methods.include? data_method
28
+ test_case = object.new
29
+ data = test_case.send data_method
30
+
31
+ raise "Data method #{data_method} must return an array" unless data.is_a? Array
32
+ data.each do |params|
33
+ raise "Data method #{data_method} must return an array of arrays" unless data.is_a? Array
34
+ runner.run object, test, params
35
+ end
36
+ else
37
+ runner.run object, test
38
+ end
39
+ end
40
+ end
41
+ @@finish = Time.new
42
+ report
43
+ end
44
+
45
+ protected
46
+ def report
47
+ # haven't figured out what I want to do for reporting yet but I need some results
48
+ puts "Started Tests #{@@start.strftime("%Y-%m-%d %H:%M:%S")}"
49
+
50
+ puts "#{@@errors.count} Errors:\n" if @@errors.count > 0
51
+ @@errors.each_with_index do |error, i|
52
+ puts "#{i + 1}) #{error[0]}::#{error[1]}(#{error[2]})"
53
+ puts error[3].message
54
+ puts error[3].backtrace.join("\n")
55
+ end
56
+
57
+ puts "#{@@failures.count} Failures:\n" if @@failures.count > 0
58
+ @@failures.each_with_index do |failure, i|
59
+ puts "#{i + 1}) #{failure[0]}::#{failure[1]}(#{failure[2]})"
60
+ puts failure[3].message
61
+ puts failure[3].backtrace.join("\n")
62
+ end
63
+
64
+ elapsed = @@finish - @@start
65
+ inverse = Rational(elapsed.to_r.denominator,elapsed.to_r.numerator)
66
+ puts
67
+ puts "Tests Complete in #{elapsed} seconds!"
68
+ puts "%.3f tests/s, %.3f assertions/s" % [(@@tests * inverse).to_f, (TestCase.assertions * inverse).to_f]
69
+ puts "%d Tests, %d Assertions, %d Errors, %d Failures" % [@@tests, TestCase.assertions, @@errors.count, @@failures.count]
70
+ puts
71
+ end
72
+ end
73
+
74
+ public
75
+ def run object, test, params = []
76
+ raise ArgumentError, "Parameter list for #{object.class}::#{test} must be an array" unless params.is_a? Array
77
+
78
+ test_case = object.new
79
+
80
+ begin
81
+ @@tests += 1
82
+ test_case.setup
83
+ test_case.send test, *params
84
+ rescue AssertionFailure => failure
85
+ @@failures << [test_case.class.name, test, params, failure]
86
+ rescue Exception => error
87
+ @@errors << [test_case.class.name, test, params, error]
88
+ ensure
89
+ test_case.teardown
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,134 @@
1
+ require 'RubyUnit/AssertionFailure'
2
+
3
+ module RubyUnit
4
+ class TestCase
5
+ public
6
+ def setup
7
+ end
8
+
9
+ def teardown
10
+ end
11
+
12
+ private
13
+ def __assertion &block
14
+ @@assertions += 1
15
+ yield
16
+ end
17
+
18
+ protected
19
+ def fail message = nil
20
+ __assertion do
21
+ raise AssertionFailure, message
22
+ end
23
+ end
24
+
25
+ def assert expected, message = nil
26
+ __assertion do
27
+ raise AssertionFailure, message unless expected
28
+ end
29
+ end
30
+
31
+ def assertNot expected, message = nil
32
+ __assertion do
33
+ raise AssertionFailure, message if expected
34
+ end
35
+ end
36
+
37
+ def assertEqual expected, actual, message = nil
38
+ __assertion do
39
+ raise AssertionFailure, message unless expected == actual
40
+ end
41
+ end
42
+
43
+ def assertNotEqual expected, actual, message = nil
44
+ __assertion do
45
+ raise AssertionFailure, message if expected == actual
46
+ end
47
+ end
48
+
49
+ def assertMatch pattern, actual, message = nil
50
+ __assertion do
51
+ raise AssertionFailure, message unless actual =~ pattern
52
+ end
53
+ end
54
+
55
+ def assertRaiseExpected *args, &block
56
+ __assertion do
57
+ raise ArgumentError, "wrong number of arguments (#{args.count} for 2..3)" unless args.count >= 1
58
+ expected, pattern, message = args
59
+ raise ArgumentError, "expected exception must be a subclass of Exception" unless expected < Exception
60
+ raise ArgumentError, "exception message must be a Regexp or String" unless pattern.is_a? Regexp or pattern.is_a? String or pattern.nil?
61
+ raise ArguemntError, "message must be a String or nil" unless message.is_a? String or message.nil?
62
+
63
+ begin
64
+ yield
65
+ raise AssertionFailure, message
66
+ rescue expected => e
67
+ if pattern.is_a? String
68
+ assertEqual pattern, e.message
69
+ elsif pattern.is_a? Regexp
70
+ assertMatch pattern, e.message
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def assertNothingRaised message = nil, &block
77
+ __assertion do
78
+ begin
79
+ yield
80
+ rescue
81
+ raise AssertionFailure, message
82
+ end
83
+ end
84
+ end
85
+
86
+ def assertIsA klass, object, message = nil
87
+ __assertion do
88
+ raise AssertionFailure, message unless klass.is_a? Class
89
+ end
90
+ end
91
+
92
+ def assertInstanceOf klass, object, message = nil
93
+ __assertion do
94
+ assertIsA Class, klass, message
95
+ raise AssertionFailure, message unless object.instance_of? klass
96
+ end
97
+ end
98
+
99
+ def assertSame expected, actual, message = nil
100
+ __assertion do
101
+ raise AssertionFailure, message unless expected.equal? actual
102
+ end
103
+ end
104
+
105
+ def assertNotSame expected, actual, message = nil
106
+ __assertion do
107
+ raise AssertionFailure, message if expected.equal? actual
108
+ end
109
+ end
110
+
111
+ def assertConst expected, klass, konstant, message = nil
112
+ __assertion do
113
+ assertIsA Class, klass, message
114
+ value = klass.const_get konstant
115
+ assertIsA expected.class, value, message
116
+ assertEqual expected, value, message
117
+ end
118
+ end
119
+
120
+ class << self
121
+ @@assertions = 0
122
+
123
+ def descendents
124
+ ObjectSpace.each_object(Class).select do |object|
125
+ object < self
126
+ end
127
+ end
128
+
129
+ def assertions
130
+ @@assertions
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,3 @@
1
+ module RubyUnit
2
+ VERSION = '0.0.1'
3
+ end
data/lib/RubyUnit.rb ADDED
@@ -0,0 +1,13 @@
1
+ module RubyUnit
2
+ end
3
+
4
+ require 'RubyUnit/TestCase'
5
+ require 'RubyUnit/Runner'
6
+ # Automatically run test cases
7
+ Module.new do
8
+ if $ERROR_INFO.nil?
9
+ at_exit do
10
+ RubyUnit::Runner.run
11
+ end
12
+ end
13
+ end
data/test.rb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Sample Test
4
+ require_relative 'RubyUnit'
5
+ require_relative 'example/RealNumberTest'
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyunit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Clower
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Framework for Unit Testing in Ruby
14
+ email:
15
+ - matthewclower@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.md
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - example/RealNumber.rb
24
+ - example/RealNumberTest.rb
25
+ - lib/RubyUnit.rb
26
+ - lib/RubyUnit/AssertionFailure.rb
27
+ - lib/RubyUnit/Runner.rb
28
+ - lib/RubyUnit/TestCase.rb
29
+ - lib/RubyUnit/version.rb
30
+ - test.rb
31
+ homepage: http://github.com/RubyUnit/RubyUnit
32
+ licenses:
33
+ - LGPL
34
+ metadata: {}
35
+ post_install_message: Happy Testing!
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.2.2
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Unit Test Framework
55
+ test_files: []