rubyunit 0.2.14 → 0.3.15

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -5
  3. data/TestSuite.rb +7 -23
  4. data/lib/RubyUnit/AssertionFailure.rb +9 -9
  5. data/lib/RubyUnit/AssertionMessage.rb +70 -0
  6. data/lib/RubyUnit/Assertions/Basic.rb +121 -0
  7. data/lib/RubyUnit/Assertions/Class.rb +196 -0
  8. data/lib/RubyUnit/Assertions/Collection.rb +80 -0
  9. data/lib/RubyUnit/Assertions/Comparison.rb +200 -0
  10. data/lib/RubyUnit/Assertions/Exception.rb +105 -0
  11. data/lib/RubyUnit/Assertions/Method.rb +157 -0
  12. data/lib/RubyUnit/Assertions.rb +9 -636
  13. data/lib/RubyUnit/Runner.rb +1 -2
  14. data/lib/RubyUnit.rb +28 -4
  15. data/tests/AssertionFailure/TC_Class.rb +2 -13
  16. data/tests/AssertionFailure/TC_Instance.rb +1 -1
  17. data/tests/AssertionFailure/data/Instance.rb +3 -3
  18. data/tests/AssertionMessage/TC_Constant.rb +20 -0
  19. data/tests/AssertionMessage/data/Constant.rb +70 -0
  20. data/tests/Assertions/TC_Basic.rb +349 -0
  21. data/tests/Assertions/TC_Class.rb +75 -0
  22. data/tests/Assertions/TC_Comparison.rb +13 -0
  23. data/tests/Assertions/data/Basic.rb +90 -0
  24. data/tests/Assertions/data/Class.rb +54 -0
  25. data/tests/Assertions/data/Comparison.rb +7 -0
  26. data/tests/Assertions/data/ObjectTypes.rb +174 -0
  27. data/tests/IncompleteTest/TC_IncompleteTest.rb +15 -0
  28. data/tests/RubyUnit/TC_RubyUnit.rb +30 -0
  29. data/tests/RubyUnit/data/RubyUnit.rb +16 -0
  30. data/tests/Runner/TC_Runner.rb +9 -0
  31. data/tests/SkippedTest/TC_SkippedTest.rb +15 -0
  32. data/tests/TS_AssertionFailure.rb +4 -2
  33. data/tests/TS_AssertionMessage.rb +9 -0
  34. data/tests/TS_Assertions.rb +67 -0
  35. data/tests/TS_IncompleteTest.rb +9 -0
  36. data/tests/TS_RubyUnit.rb +4 -2
  37. data/tests/TS_Runner.rb +9 -0
  38. data/tests/TS_SkippedTest.rb +9 -0
  39. data/tests/TS_TestCase.rb +9 -0
  40. data/tests/TestCase/TC_TestCase.rb +120 -0
  41. data/tests/TestCase/data/TestCase.rb +24 -0
  42. metadata +32 -12
  43. data/tests/AssertionFailure/data/Class.rb +0 -12
  44. data/tests/TEST_Assertions.rb +0 -37
  45. data/tests/TEST_IncompleteTest.rb +0 -13
  46. data/tests/TEST_Runner.rb +0 -7
  47. data/tests/TEST_SkippedTest.rb +0 -13
  48. data/tests/TEST_TestCase.rb +0 -122
  49. data/tests/data/Assertions.rb +0 -23
  50. data/tests/data/TestCase.rb +0 -22
  51. data/tests/fixture/TestCase.rb +0 -6
@@ -0,0 +1,200 @@
1
+ module RubyUnit
2
+ module Assertions
3
+ include AssertionMessage
4
+
5
+ #
6
+ # Assert that two values are equal.
7
+ # * raises RubyUnit::AssertionFailure unless _expected_ equals _actual_
8
+ #
9
+ # expected::
10
+ # The value that is forbidden by the assertion
11
+ #
12
+ # actual::
13
+ # The value that is being checked by the assertion
14
+ #
15
+ # message::
16
+ # The message provided to be reported for a failure
17
+ #
18
+ # assertEqual 42, 24, "This will fail" # => fail
19
+ #
20
+ def assertEqual expected, actual, message = nil
21
+ __assert (expected == actual), ASSERT_EQUAL_ERROR, message, {:expected=>expected, :actual=>actual}
22
+ end
23
+
24
+ #
25
+ # Assert that two values are NOT equal.
26
+ # * raises RubyUnit::AssertionFailure if _illegal_ equals _actual_
27
+ #
28
+ # illegal::
29
+ # The value that is not allowed by the assertion
30
+ #
31
+ # actual::
32
+ # The value that is being checked by the assertion
33
+ #
34
+ # message::
35
+ # The message provided to be reported for a failure
36
+ #
37
+ # assertNotEqual 3.14, 3.14, "This will fail" # => fail
38
+ #
39
+ def assertNotEqual illegal, actual, message = nil
40
+ __reject (illegal == actual), ASSERT_NOT_EQUAL_ERROR, message, {:illegal=>illegal, :actual=>actual}
41
+ end
42
+
43
+ #
44
+ # Assert that one value is greater than another.
45
+ # * raises RubyUnit::AssertionFailure unless _greater_ is greater than _value_
46
+ #
47
+ # greater::
48
+ # The value that should be greater
49
+ #
50
+ # value::
51
+ # The value that is being checked by the assertion
52
+ #
53
+ # message::
54
+ # The message provided to be reported for a failure
55
+ #
56
+ # assertGreaterThan 24, 42, "This will fail" # => fail
57
+ #
58
+ def assertGreaterThan greater, value, message = nil
59
+ __assert (greater > value), ASSERT_GREATERTHAN_ERROR, message, {:greater=>greater, :value=>value}
60
+ end
61
+
62
+ #
63
+ # Assert that one value is greater than another.
64
+ # * raises RubyUnit::AssertionFailure unless _greater_ is greater than or equal to _value_
65
+ #
66
+ # greater::
67
+ # The value that should be greater than or equal
68
+ #
69
+ # value::
70
+ # The value that is being checked by the assertion
71
+ #
72
+ # message::
73
+ # The message provided to be reported for a failure
74
+ #
75
+ # assertGreaterThanOrEqual 24, 42, "This will fail" # => fail
76
+ #
77
+ def assertGreaterThanOrEqual greater, value, message = nil
78
+ __assert (greater >= value), ASSERT_GREATERTHANOREQUAL_ERROR, message, {:greater=>greater, :value=>value}
79
+ end
80
+
81
+ #
82
+ # Assert that one value is less than another.
83
+ # * raises RubyUnit::AssertionFailure unless _less_ is less than _value_
84
+ #
85
+ # less::
86
+ # The value that should be less
87
+ #
88
+ # value::
89
+ # The value that is being checked by the assertion
90
+ #
91
+ # message::
92
+ # The message provided to be reported for a failure
93
+ #
94
+ # assertLessThan 42, 24, "This will fail" # => fail
95
+ #
96
+ def assertLessThan less, value, message = nil
97
+ __assert (less < value), ASSERT_LESSTHAN_ERROR, message, {:less=>less, :value=>value}
98
+ end
99
+
100
+ #
101
+ # Assert that one value is less than another.
102
+ # * raises RubyUnit::AssertionFailure unless _less_ is less than or equal to _value_
103
+ #
104
+ # less::
105
+ # The value that should be less than or equal
106
+ #
107
+ # value::
108
+ # The value that is being checked by the assertion
109
+ #
110
+ # message::
111
+ # The message provided to be reported for a failure
112
+ #
113
+ # assertLessThanOrEqual 42, 24, "This will fail" # => fail
114
+ #
115
+ def assertLessThanOrEqual less, value, message = nil
116
+ __assert (less <= value), ASSERT_LESSTHANOREQUAL_ERROR, message, {:less=>less, :value=>value}
117
+ end
118
+
119
+ #
120
+ # Assert that a value matches a Regexp pattern.
121
+ # * raises RubyUnit::AssertionFailure unless _value_ matches _pattern_
122
+ #
123
+ # pattern::
124
+ # A Regexp pattern expected by the assertion
125
+ #
126
+ # value::
127
+ # The value that is being checked for the assertion
128
+ #
129
+ # message::
130
+ # The message provided to be reported for a failure
131
+ #
132
+ # assertMatch /^Hello/, 'Goodbye!', "This will fail" # => fail
133
+ #
134
+ def assertMatch pattern, value, message = nil
135
+ pattern = [pattern] unless pattern.is_a? Array
136
+ pattern.each do |regex|
137
+ __assert (value =~ regex), ASSERT_MATCH_ERROR, message, {:pattern=>pattern, :value=>value}
138
+ end
139
+ end
140
+
141
+ #
142
+ # Assert that a value does not match a Regexp pattern.
143
+ # * raises RubyUnit::AssertionFailure if _value_ matches _pattern_
144
+ #
145
+ # pattern::
146
+ # A Regexp pattern excluded by the assertion
147
+ #
148
+ # value::
149
+ # The value that is being checked for the assertion
150
+ #
151
+ # message::
152
+ # The message provided to be reported for a failure
153
+ #
154
+ # assertMatch /^Good/, 'Goodbye!', "This will fail" # => fail
155
+ #
156
+ def assertNotMatch exclusion, value, message = nil
157
+ __reject (value =~ exclusion), ASSERT_NO_MATCH_ERROR, message, {:exclusion=>exclusion, :value=>value}
158
+ end
159
+
160
+ #
161
+ # Assert that two objects are the same object
162
+ # * raises RubyUnit::AssertionFailure unless _expected_ and _actual_ are
163
+ # the same object.
164
+ #
165
+ # expected::
166
+ # The expected object
167
+ #
168
+ # actual::
169
+ # The object that is being checked against _expected_
170
+ #
171
+ # message::
172
+ # The message provided to be reported for a failure
173
+ #
174
+ # assertSame '42', 42, 'Not even close.' # => fail
175
+ #
176
+ def assertSame expected, actual, message = nil
177
+ __assert (expected.equal? actual), ASSERT_SAME_ERROR, message, {:expected=>expected, :actual=>actual}
178
+ end
179
+
180
+ #
181
+ # Assert that two objects are not the same object
182
+ # * raises RubyUnit::AssertionFailure if _illegal_ and _actual_ are the
183
+ # same object.
184
+ #
185
+ # illegal::
186
+ # The expected that it shouldn't be
187
+ #
188
+ # actual::
189
+ # The object that is being checked against _illegal_
190
+ #
191
+ # message::
192
+ # The message provided to be reported for a failure
193
+ #
194
+ # assertNotSame value, value, 'Imagine that!' # => fail
195
+ #
196
+ def assertNotSame illegal, actual, message = nil
197
+ __reject (illegal.equal? actual), ASSERT_NOT_SAME_ERROR, message, {:illegal=>illegal, :actual=>actual}
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,105 @@
1
+ module RubyUnit
2
+ module Assertions
3
+ include AssertionMessage
4
+
5
+ #
6
+ # Assert that no exception is raised.
7
+ # * raises RubyUnit::AssertionFailure if any exception is raised
8
+ #
9
+ # message::
10
+ # The message provided to be reported for a failure
11
+ #
12
+ # &block::
13
+ # The code block that is executed
14
+ #
15
+ # assertNothingRaised 'Not expecting an exception!' do
16
+ # # do something
17
+ # end
18
+ #
19
+ def assertNothingRaised message = nil, &block
20
+ __wrap_assertion do
21
+ begin
22
+ yield
23
+ rescue Exception => e
24
+ build_message ASSERT_NOTHING_RAISED_ERROR, message, {:exception=>e.message}
25
+ end
26
+ end
27
+ end
28
+
29
+ #
30
+ # Assert that a specified exception message is raised.
31
+ # * raises RubyUnit::AssertionFailure unless the correct Exception message is raised
32
+ #
33
+ # pattern::
34
+ # The String or Regexp that will be used to validate the Exception message
35
+ #
36
+ # message::
37
+ # The message provided to be reported for a failure
38
+ #
39
+ # &block::
40
+ # The code block that is expected to throw the Exception
41
+ #
42
+ # assertRaiseMessage /^Invalid/, 'Expecting an exception!' do
43
+ # # do something
44
+ # end
45
+ #
46
+ def assertRaiseMessage pattern, message = nil, &block
47
+ assertRaiseExpected Exception, pattern, message, &block
48
+ end
49
+
50
+ #
51
+ # Assert that a specified exception type is raised.
52
+ # * raises RubyUnit::AssertionFailure unless the correct Exception type is raised
53
+ #
54
+ # e::
55
+ # The Exception class that is expected.
56
+ #
57
+ # message::
58
+ # The message provided to be reported for a failure
59
+ #
60
+ # &block::
61
+ # The code block that is expected to throw the Exception
62
+ #
63
+ # assertRaiseKindOf StandardError, 'Expecting an exception!' do # => fail
64
+ # # do something
65
+ # end
66
+ #
67
+ def assertRaiseKindOf e, message = nil, &block
68
+ assertRaiseExpected e, '', message, &block
69
+ end
70
+
71
+ #
72
+ # Assert that a specified exception is raised.
73
+ # * raises RubyUnit::AssertionFailure unless the correct Exception is raised
74
+ #
75
+ # exception::
76
+ # The Exception class that is expected.
77
+ #
78
+ # pattern::
79
+ # The String or Regexp that will be used to validate the Exception message
80
+ #
81
+ # message::
82
+ # The message provided to be reported for a failure
83
+ #
84
+ # &block::
85
+ # The code block that is expected to throw the Exception
86
+ #
87
+ # assertRaiseExpected StandardError, /^Invalid/, 'Expecting an exception!' do
88
+ # raise StandardError, 'Invalid Retroincabulator'
89
+ # end
90
+ #
91
+ def assertRaiseExpected exception, pattern, message = nil &block
92
+ __validate_exception pattern, exception
93
+ __wrap_assertion do
94
+ begin
95
+ yield
96
+ build_message ASSERT_RAISE_EXPECTED_ERROR, message, {:exception=>exception, :pattern=>pattern}
97
+ rescue exception => e
98
+ assertEqual pattern, e.message if pattern.is_a? String and pattern.length > 0
99
+ assertMatch pattern, e.message if pattern.is_a? Regexp
100
+ e
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,157 @@
1
+ module RubyUnit
2
+ module Assertions
3
+ include AssertionMessage
4
+
5
+ #
6
+ # Assert that an object responds to particular method
7
+ # * raises RubyUnit::AssertionFailure unless _object_ responds to _method_
8
+ #
9
+ # object::
10
+ # The object to check
11
+ #
12
+ # method::
13
+ # The method to assert on the object
14
+ #
15
+ # message::
16
+ # The message provided to be reported for a failure
17
+ #
18
+ # assertRespondTo /^Regexp/, :length, 'It does not, so... no' # => fail
19
+ #
20
+ def assertRespondTo object, method, message = nil
21
+ __assert (object.respond_to? method), ASSERT_RESPOND_TO_ERROR, message, {:object=>object, :method=>method}
22
+ end
23
+
24
+ #
25
+ # Assert that an object does not respond to a particular method
26
+ # * raises RubyUnit::AssertionFailure if _object_ responds to _method_
27
+ #
28
+ # object::
29
+ # The object to check
30
+ #
31
+ # method::
32
+ # The method to assert on the object
33
+ #
34
+ # message::
35
+ # The message provided to be reported for a failure
36
+ #
37
+ # assertNotRespondTo 25, :integer?, 'It does, so close' # => fail
38
+ #
39
+ def assertNotRespondTo object, method, message = nil
40
+ __assert (object.respond_to? method), ASSERT_NOT_RESPOND_TO_ERROR, message, {:object=>object, :method=>method}
41
+ end
42
+
43
+ #
44
+ # Assert that an object has defined the specified method.
45
+ # * raises RubyUnit::AssertionFailure unless _klass_ has defined _method_
46
+ #
47
+ # klass::
48
+ # The object to check for _method_
49
+ #
50
+ # method::
51
+ # The method to check
52
+ #
53
+ # message::
54
+ # The message provided to be reported for a failure
55
+ #
56
+ # assertMethod String, :integer?, 'Nope' # => fail
57
+ #
58
+ def assertMethod klass, method, message = nil
59
+ assertInclude klass.methods, method, message
60
+ end
61
+
62
+ #
63
+ # Assert that an object has not defined the specified method.
64
+ # * raises RubyUnit::AssertionFailure if _klass_ has defined _method_
65
+ #
66
+ # klass::
67
+ # The object to check for _method_
68
+ #
69
+ # method::
70
+ # The method to check
71
+ #
72
+ # message::
73
+ # The message provided to be reported for a failure
74
+ #
75
+ # assertNotMethod Integer, :integer?, 'Nope' # => fail
76
+ #
77
+ def assertNotMethod klass, not_method, message = nil
78
+ assertNotInclude klass.methods, not_method, message
79
+ end
80
+
81
+ #
82
+ # Assert that an object has defined the specified instance method.
83
+ # * raises RubyUnit::AssertionFailure unless _klass_ has defined _instance_method_
84
+ #
85
+ # klass::
86
+ # The object to check for _instance_method_
87
+ #
88
+ # method::
89
+ # The method to check
90
+ #
91
+ # message::
92
+ # The message provided to be reported for a failure
93
+ #
94
+ # assertInstanceMethod String, :integer?, 'Nope' # => fail
95
+ #
96
+ def assertInstanceMethod klass, instance_method, message = nil
97
+ assertInclude klass.instance_methods, instance_method, message
98
+ end
99
+
100
+ #
101
+ # Assert that an object has not defined the specified instance method.
102
+ # * raises RubyUnit::AssertionFailure unless _klass_ has defined _not_instance_method_
103
+ #
104
+ # klass::
105
+ # The object to check for _not_instance_method_
106
+ #
107
+ # method::
108
+ # The method to check
109
+ #
110
+ # message::
111
+ # The message provided to be reported for a failure
112
+ #
113
+ # assertNotInstanceMethod Integer, :integer?, 'Nope' # => fail
114
+ #
115
+ def assertNotInstanceMethod klass, not_instance_method, message = nil
116
+ assertNotInclude klass.instance_methods, not_instance_method, message
117
+ end
118
+
119
+ #
120
+ # Assert that an Class has defined the specified class method.
121
+ # * raises RubyUnit::AssertionFailure unless _klass_ has defined _class_method_
122
+ #
123
+ # klass::
124
+ # The object to check for _class_method_
125
+ #
126
+ # method::
127
+ # The method to check
128
+ #
129
+ # message::
130
+ # The message provided to be reported for a failure
131
+ #
132
+ # assertClassMethod String, :integer?, 'Nope' # => fail
133
+ #
134
+ def assertClassMethod klass, class_method, message = nil
135
+ assertInclude klass.singleton_methods, class_method, message
136
+ end
137
+
138
+ #
139
+ # Assert that an Class has not defined the specified class method.
140
+ # * raises RubyUnit::AssertionFailure unless _klass_ has defined _not_class_method_
141
+ #
142
+ # klass::
143
+ # The object to check for _not_class_method_
144
+ #
145
+ # method::
146
+ # The method to check
147
+ #
148
+ # message::
149
+ # The message provided to be reported for a failure
150
+ #
151
+ # assertNotClassMethod String, :new, 'Nope' # => fail
152
+ #
153
+ def assertNotClassMethod klass, not_class_method, message = nil
154
+ assertNotInclude klass.singleton_methods, not_class_method, message
155
+ end
156
+ end
157
+ end