rubyunit 0.2.13 → 0.2.14
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/TestSuite.rb +3 -5
- data/lib/RubyUnit/AssertionFailure.rb +24 -0
- data/lib/RubyUnit/Assertions.rb +57 -10
- data/lib/RubyUnit/Runner.rb +1 -1
- data/lib/RubyUnit.rb +2 -1
- data/tests/AssertionFailure/TC_Class.rb +27 -0
- data/tests/AssertionFailure/TC_Instance.rb +43 -0
- data/tests/AssertionFailure/data/Class.rb +12 -0
- data/tests/AssertionFailure/data/Instance.rb +20 -0
- data/tests/RubyUnit/TC_GemInfo.rb +27 -0
- data/tests/RubyUnit/TC_RubyUnit.rb +15 -0
- data/tests/RubyUnit/data/GemInfo.rb +13 -0
- data/tests/TEST_Assertions.rb +5 -4
- data/tests/TS_AssertionFailure.rb +7 -0
- data/tests/TS_RubyUnit.rb +7 -0
- data/tests/data/Assertions.rb +18 -0
- metadata +11 -6
- data/tests/TEST_AssertionFailure.rb +0 -13
- data/tests/TEST_GemInfo.rb +0 -25
- data/tests/TEST_RubyUnit.rb +0 -13
- data/tests/data/GemInfo.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b64f6dbfe4319e46907b2011f73fdadd28eefe7a
|
4
|
+
data.tar.gz: b71d665242db3cfc15f5db95b9c4410bd5f67d38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad85169080b04079d2603d31ebd4bcd9eba77c9b62770d1418d4e6abcc16df2b942f5d72ae1e6a94d5c37e45ffcc656033e3e8dac39cf679e411cc198b31ab0
|
7
|
+
data.tar.gz: c7ff085f436ef93f1a13b07fd5b5b547906cd13690d32d9759c6c512bc5316d8b095d258c1f529b561d81fcfa1b2e87e68735e0968f6555e3247730021dbcd65
|
data/TestSuite.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# IMPORTANT
|
4
3
|
# require relative RubyUnit framework for local so that the tests are run on the build
|
5
4
|
# in this repository
|
6
5
|
path = File.dirname(__FILE__)
|
@@ -10,14 +9,13 @@ $LOAD_PATH.unshift("#{path}/tests")
|
|
10
9
|
|
11
10
|
require 'RubyUnit'
|
12
11
|
|
13
|
-
# Test
|
12
|
+
# Test Sets
|
14
13
|
|
15
14
|
# RubyUnit module => RubyUnit.rb
|
16
|
-
require '
|
17
|
-
require 'TEST_GemInfo'
|
15
|
+
require 'TS_RubyUnit'
|
18
16
|
|
19
17
|
# AssertionFailure exception => RubyUnit/AssertionFailure.rb
|
20
|
-
require '
|
18
|
+
require 'TS_AssertionFailure'
|
21
19
|
|
22
20
|
# Assertions module => RubyUnit/Assertions.rb
|
23
21
|
require 'TEST_Assertions'
|
@@ -3,8 +3,32 @@ module RubyUnit
|
|
3
3
|
# Exception that is raised when a test assertion fails.
|
4
4
|
#
|
5
5
|
class AssertionFailure < StandardError
|
6
|
+
attr_reader :data
|
7
|
+
|
6
8
|
# Error messages
|
7
9
|
FAILING = 'Failing test'
|
8
10
|
|
11
|
+
#
|
12
|
+
# Create a RubyUnit::AssertionFailure exception
|
13
|
+
#
|
14
|
+
# data::
|
15
|
+
# The data associated with the assertion
|
16
|
+
#
|
17
|
+
def initialize data = {}
|
18
|
+
raise ArgumentError, 'Data for AssertionFailure must be a Hash' unless data.is_a? Hash
|
19
|
+
@data = data
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Create a string from the assertion data
|
24
|
+
#
|
25
|
+
def info
|
26
|
+
s = "\n"
|
27
|
+
s = "#{message}\n" if message.length > 0
|
28
|
+
@data.each do |index, value|
|
29
|
+
s << "\n#{index}:\n\t#{value.inspect}"
|
30
|
+
end
|
31
|
+
s
|
32
|
+
end
|
9
33
|
end
|
10
34
|
end
|
data/lib/RubyUnit/Assertions.rb
CHANGED
@@ -82,7 +82,7 @@ module RubyUnit
|
|
82
82
|
# message::
|
83
83
|
# The message provided to be reported for a failure
|
84
84
|
#
|
85
|
-
#
|
85
|
+
# assertNil true, "This will fail" # => fail
|
86
86
|
#
|
87
87
|
def assertFalse value, message = nil
|
88
88
|
__assert (false == value), 'Failed to assert that value is EXACTLY false', message, {:value=>value}
|
@@ -98,10 +98,62 @@ module RubyUnit
|
|
98
98
|
# message::
|
99
99
|
# The message provided to be reported for a failure
|
100
100
|
#
|
101
|
-
#
|
101
|
+
# assertNil true, "This will fail" # => fail
|
102
102
|
#
|
103
103
|
def assertNil value, message = nil
|
104
|
-
__assert value
|
104
|
+
__assert value.nil?, 'Failed to assert that value is EXACTLY nil', message, {:value=>value}
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Assert that a test condition is not nil.
|
109
|
+
# * raises RubyUnit::AssertionFailure if _value_ is nil
|
110
|
+
#
|
111
|
+
# value::
|
112
|
+
# The value that is being checked by the assertion
|
113
|
+
#
|
114
|
+
# message::
|
115
|
+
# The message provided to be reported for a failure
|
116
|
+
#
|
117
|
+
# assertNotNil nil, "This will fail" # => fail
|
118
|
+
#
|
119
|
+
def assertNotNil value, message = nil
|
120
|
+
__reject value.nil?, 'Failed to assert that value is NOT nil', message, {:value=>value}
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Assert that a value is empty
|
125
|
+
# * raises RubyUnit::AssertionFailure unless _object_ responds to :empty?
|
126
|
+
# * raises RubyUnit::AssertionFailure unless _object_ is empty
|
127
|
+
#
|
128
|
+
# object::
|
129
|
+
# The object to check
|
130
|
+
#
|
131
|
+
# message::
|
132
|
+
# The message provided to be reported for a failure
|
133
|
+
#
|
134
|
+
# assertEmpty [1, 2], 'Not empty' # => fail
|
135
|
+
#
|
136
|
+
def assertEmpty object, message = nil
|
137
|
+
assertRespondTo object, :include?, message
|
138
|
+
__assert object.empty?, 'Failed to assert object is empty', message, {:object=>object}
|
139
|
+
end
|
140
|
+
|
141
|
+
#
|
142
|
+
# Assert that a value is not empty
|
143
|
+
# * raises RubyUnit::AssertionFailure unless _object_ responds to :empty?
|
144
|
+
# * raises RubyUnit::AssertionFailure if _object_ is empty
|
145
|
+
#
|
146
|
+
# object::
|
147
|
+
# The object to check
|
148
|
+
#
|
149
|
+
# message::
|
150
|
+
# The message provided to be reported for a failure
|
151
|
+
#
|
152
|
+
# assertNotInclude [1, 2, 3], 2, 'It does, so close' # => fail
|
153
|
+
#
|
154
|
+
def assertNotEmpty object, message = nil
|
155
|
+
assertRespondTo object, :include?, message
|
156
|
+
__reject object.empty?, 'Failed to assert object is NOT empty', message, {:object=>object}
|
105
157
|
end
|
106
158
|
|
107
159
|
#
|
@@ -585,6 +637,7 @@ module RubyUnit
|
|
585
637
|
rescue exception => e
|
586
638
|
assertEqual pattern, e.message if pattern.is_a? String and pattern.length > 0
|
587
639
|
assertMatch pattern, e.message if pattern.is_a? Regexp
|
640
|
+
e
|
588
641
|
end
|
589
642
|
end
|
590
643
|
end
|
@@ -612,13 +665,7 @@ module RubyUnit
|
|
612
665
|
raise ArgumentError, 'Error description must be a String' unless error.is_a? String
|
613
666
|
raise ArgumentError, 'Failure message must be String' unless message.nil? or message.is_a? String
|
614
667
|
raise ArgumentError, 'Failure data must be a Hash' unless data.is_a? Hash
|
615
|
-
|
616
|
-
error_message = "\n\n#{error}"
|
617
|
-
error_message << "\n#{message}" if not message.nil?
|
618
|
-
data.each do |index, value|
|
619
|
-
error_message << "\n#{index}:\n\t#{value.inspect}"
|
620
|
-
end
|
621
|
-
raise AssertionFailure, error_message
|
668
|
+
raise AssertionFailure.new({'Assertion Failure'=>message}.merge data), error
|
622
669
|
end
|
623
670
|
|
624
671
|
#
|
data/lib/RubyUnit/Runner.rb
CHANGED
@@ -123,7 +123,7 @@ module RubyUnit
|
|
123
123
|
puts "#{@@failures.count} Failures:\n" if @@failures.count > 0
|
124
124
|
@@failures.each_with_index do |failure, i|
|
125
125
|
puts "#{i + 1}) #{failure[0]}::#{failure[1]}(#{failure[2]})"
|
126
|
-
puts failure[3]
|
126
|
+
puts failure[3].info
|
127
127
|
puts failure[3].backtrace.join("\n")
|
128
128
|
end
|
129
129
|
|
data/lib/RubyUnit.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
module RubyUnit
|
7
7
|
# Current RubyUnit version
|
8
|
-
VERSION = '0.2.
|
8
|
+
VERSION = '0.2.14'
|
9
9
|
|
10
10
|
#
|
11
11
|
# RubyUnit::GemInfo contains data and functionality needed by the gem builder
|
@@ -35,6 +35,7 @@ Module.new do
|
|
35
35
|
#--
|
36
36
|
# TODO: add alias and call the alias so that the function doesn't break any
|
37
37
|
# functionality that may have also extended this event. Before/After?
|
38
|
+
# * Test and see if I even need to do that.
|
38
39
|
#++
|
39
40
|
#
|
40
41
|
at_exit do
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'RubyUnit/AssertionFailure'
|
2
|
+
|
3
|
+
# Data provider for RubyUnit::AssertionFailure tests
|
4
|
+
require_relative 'data/Class'
|
5
|
+
|
6
|
+
module AssertionFailureTests
|
7
|
+
#
|
8
|
+
# Test Case for RubyUnit::AssertionFailure
|
9
|
+
#
|
10
|
+
class TC_Class < RubyUnit::TestCase
|
11
|
+
include ClassTestsData
|
12
|
+
|
13
|
+
#
|
14
|
+
# Validate that RubyUnit::AssertionFailure is an Exception
|
15
|
+
#
|
16
|
+
def isExceptionTest
|
17
|
+
assertDescendent Exception, RubyUnit::AssertionFailure, 'AssertionFailure MUST be an Exception'
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Assert all required constants are defined
|
22
|
+
#
|
23
|
+
def constantTest konstant
|
24
|
+
assertConstDefined RubyUnit::AssertionFailure, konstant, 'Required constant is missing'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'RubyUnit/AssertionFailure'
|
2
|
+
|
3
|
+
# Data provider for RubyUnit::AssertionFailure tests
|
4
|
+
require_relative 'data/Instance'
|
5
|
+
|
6
|
+
module AssertionFailureTests
|
7
|
+
#
|
8
|
+
# Test Case for RubyUnit::AssertionFailure
|
9
|
+
#
|
10
|
+
class TC_Instance < RubyUnit::TestCase
|
11
|
+
include InstanceTestsData
|
12
|
+
|
13
|
+
#
|
14
|
+
# Test creation of default AssertionFailure
|
15
|
+
#
|
16
|
+
def createDefaultTest
|
17
|
+
assertNothingRaised 'Should be able to create default AssertionFailure' do
|
18
|
+
failure = RubyUnit::AssertionFailure.new
|
19
|
+
hash = {}
|
20
|
+
assertEqual hash, failure.data, 'Default data Hash should be empty'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Test the data for the AssertionFailure
|
26
|
+
#
|
27
|
+
def dataTest data
|
28
|
+
failure = RubyUnit::AssertionFailure.new(data)
|
29
|
+
assertEqual data, failure.data, 'Assertion data Hash is incorrect'
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Test the info string for the AssertionFailure
|
34
|
+
#
|
35
|
+
def infoTest data
|
36
|
+
failure = RubyUnit::AssertionFailure.new(data)
|
37
|
+
data.each do |index, value|
|
38
|
+
assertMatch /#{index}/, failure.info, "Missing index for #{index}"
|
39
|
+
assertMatch /#{value}/, failure.info, "Missing value for #{index}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AssertionFailureTests
|
2
|
+
#
|
3
|
+
# Data provider for RubyUnit::AssertionFailure class Test Case
|
4
|
+
#
|
5
|
+
module InstanceTestsData
|
6
|
+
def dataData
|
7
|
+
[
|
8
|
+
[{}],
|
9
|
+
] +
|
10
|
+
infoData
|
11
|
+
end
|
12
|
+
|
13
|
+
def infoData
|
14
|
+
[
|
15
|
+
[{ :integer=>42, :string=>'string'}],
|
16
|
+
[{'String Index'=>nil, :string=>'string'}],
|
17
|
+
]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'RubyUnit'
|
2
|
+
|
3
|
+
# Data provider for RubyUnit::GemInfo tests
|
4
|
+
require_relative 'data/GemInfo'
|
5
|
+
|
6
|
+
module RubyUnitTests
|
7
|
+
#
|
8
|
+
# Test Case for the RubyUnit::GemInfo module
|
9
|
+
#
|
10
|
+
class TC_GemInfo < RubyUnit::TestCase
|
11
|
+
include GemInfoTestsData
|
12
|
+
|
13
|
+
#
|
14
|
+
# Verify that the required constants are defined
|
15
|
+
#
|
16
|
+
def constantsDefinedTest konstant
|
17
|
+
assertConstDefined RubyUnit::GemInfo, konstant, "missing constant in GemInfo: #{konstant}"
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Verify that the list of files contains the LICENSE file
|
22
|
+
#
|
23
|
+
def validateFilesIncludesLicenseTest
|
24
|
+
assertInclude RubyUnit::GemInfo::FILES, 'LICENSE.md', 'Gem MUST be distributed with the license'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'RubyUnit'
|
2
|
+
|
3
|
+
module RubyUnitTests
|
4
|
+
#
|
5
|
+
# Test Case for the RubyUnit module
|
6
|
+
#
|
7
|
+
class TC_RubyUnit < RubyUnit::TestCase
|
8
|
+
#
|
9
|
+
# Verify that the VERSION constant is defined in the RubyUnit module
|
10
|
+
#
|
11
|
+
def versionDefinedTest
|
12
|
+
assertConstDefined RubyUnit, 'VERSION', 'Version must be defined in RubyUnit::VERSION'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/tests/TEST_Assertions.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative 'data/Assertions'
|
|
7
7
|
# Test Case for RubyUnit::Assertions module
|
8
8
|
#
|
9
9
|
class TEST_Assertions < RubyUnit::TestCase
|
10
|
+
include AssertionsData
|
10
11
|
@assertions
|
11
12
|
|
12
13
|
#
|
@@ -19,8 +20,8 @@ class TEST_Assertions < RubyUnit::TestCase
|
|
19
20
|
#
|
20
21
|
# Wrapper to rescue assertions
|
21
22
|
#
|
22
|
-
def rescue_assertion pattern = '', &block
|
23
|
-
assertRaiseExpected RubyUnit::AssertionFailure, pattern do
|
23
|
+
def rescue_assertion pattern = '', message = nil, data = {}, &block
|
24
|
+
assertRaiseExpected RubyUnit::AssertionFailure, pattern, message do
|
24
25
|
yield
|
25
26
|
end
|
26
27
|
end
|
@@ -28,8 +29,8 @@ class TEST_Assertions < RubyUnit::TestCase
|
|
28
29
|
#
|
29
30
|
# Test for default failure
|
30
31
|
#
|
31
|
-
def
|
32
|
-
rescue_assertion
|
32
|
+
def failDefaultTest
|
33
|
+
rescue_assertion /#{RubyUnit::AssertionFailure::FAILING}/ do
|
33
34
|
fail
|
34
35
|
end
|
35
36
|
end
|
data/tests/data/Assertions.rb
CHANGED
@@ -2,4 +2,22 @@
|
|
2
2
|
# Data provider for RubyUnit::TestCase class Test Case
|
3
3
|
#
|
4
4
|
module AssertionsData
|
5
|
+
#
|
6
|
+
# Create data string that will be in assertion from data list
|
7
|
+
# * This makes me really want to build RubyUnit::AssertionFailure properly
|
8
|
+
#
|
9
|
+
def data_string data = {}
|
10
|
+
error_message = ''
|
11
|
+
data.each do |index, value|
|
12
|
+
error_message << "\n#{index}:\n\t#{value.inspect}"
|
13
|
+
end
|
14
|
+
error_message
|
15
|
+
end
|
16
|
+
|
17
|
+
def failData
|
18
|
+
[
|
19
|
+
['message' ],
|
20
|
+
['message', {:string=>'test',:int=>10}],
|
21
|
+
]
|
22
|
+
end
|
5
23
|
end
|
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.2.
|
4
|
+
version: 0.2.14
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Unit testing and test-driven development are crucial parts of the software
|
14
14
|
development life cycle. This tool is intended to make development and testing in
|
@@ -34,16 +34,21 @@ files:
|
|
34
34
|
- lib/RubyUnit/Runner.rb
|
35
35
|
- lib/RubyUnit/SkippedTest.rb
|
36
36
|
- lib/RubyUnit/TestCase.rb
|
37
|
-
- tests/
|
37
|
+
- tests/AssertionFailure/TC_Class.rb
|
38
|
+
- tests/AssertionFailure/TC_Instance.rb
|
39
|
+
- tests/AssertionFailure/data/Class.rb
|
40
|
+
- tests/AssertionFailure/data/Instance.rb
|
41
|
+
- tests/RubyUnit/TC_GemInfo.rb
|
42
|
+
- tests/RubyUnit/TC_RubyUnit.rb
|
43
|
+
- tests/RubyUnit/data/GemInfo.rb
|
38
44
|
- tests/TEST_Assertions.rb
|
39
|
-
- tests/TEST_GemInfo.rb
|
40
45
|
- tests/TEST_IncompleteTest.rb
|
41
|
-
- tests/TEST_RubyUnit.rb
|
42
46
|
- tests/TEST_Runner.rb
|
43
47
|
- tests/TEST_SkippedTest.rb
|
44
48
|
- tests/TEST_TestCase.rb
|
49
|
+
- tests/TS_AssertionFailure.rb
|
50
|
+
- tests/TS_RubyUnit.rb
|
45
51
|
- tests/data/Assertions.rb
|
46
|
-
- tests/data/GemInfo.rb
|
47
52
|
- tests/data/TestCase.rb
|
48
53
|
- tests/fixture/TestCase.rb
|
49
54
|
homepage: http://github.com/RubyUnit/RubyUnit
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'RubyUnit/AssertionFailure'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Test Case for RubyUnit::AssertionFailure
|
5
|
-
#
|
6
|
-
class TEST_AssertionFailure < RubyUnit::TestCase
|
7
|
-
#
|
8
|
-
# Validate that RubyUnit::AssertionFailure is an Exception
|
9
|
-
#
|
10
|
-
def isExceptionTest
|
11
|
-
assertDescendent Exception, RubyUnit::AssertionFailure, 'AssertionFailure MUST be an Exception!'
|
12
|
-
end
|
13
|
-
end
|
data/tests/TEST_GemInfo.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'RubyUnit'
|
2
|
-
|
3
|
-
# Data provider for RubyUnit::GemInfo tests
|
4
|
-
require_relative 'data/GemInfo'
|
5
|
-
|
6
|
-
#
|
7
|
-
# Test Case for the RubyUnit::GemInfo module
|
8
|
-
#
|
9
|
-
class TEST_GemInfo < RubyUnit::TestCase
|
10
|
-
include GemInfoData
|
11
|
-
|
12
|
-
#
|
13
|
-
# Verify that the required constants are defined
|
14
|
-
#
|
15
|
-
def constantsDefinedTest konstant
|
16
|
-
assertConstDefined RubyUnit::GemInfo, konstant, "missing constant in GemInfo: #{konstant}!"
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
# Verify that the list of files contains the LICENSE file
|
21
|
-
#
|
22
|
-
def validateFilesIncludesLicenseTest
|
23
|
-
assertInclude RubyUnit::GemInfo::FILES, 'LICENSE.md', 'Gem MUST be distributed with the license!'
|
24
|
-
end
|
25
|
-
end
|
data/tests/TEST_RubyUnit.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'RubyUnit'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Test Case for the RubyUnit module
|
5
|
-
#
|
6
|
-
class TEST_RubyUnit < RubyUnit::TestCase
|
7
|
-
#
|
8
|
-
# Verify that the VERSION constant is defined in the RubyUnit module
|
9
|
-
#
|
10
|
-
def versionDefinedTest
|
11
|
-
assertConstDefined RubyUnit, 'VERSION', 'Version must be defined in RubyUnit::VERSION!'
|
12
|
-
end
|
13
|
-
end
|