assertions-eb 1.7.2

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.
data/lib/assertions.rb ADDED
@@ -0,0 +1,376 @@
1
+ #!/usr/bin/env ruby
2
+ module Test
3
+ module Unit
4
+
5
+ #
6
+ # Some useful extra assertions.
7
+ # Require 'assertions', and Test::Unit::Assertions will have
8
+ # the additional assertions.
9
+ #
10
+ module Assertions
11
+ public
12
+
13
+ #
14
+ # ====Description:
15
+ # This assertion passes if and only if block contains an assertion
16
+ # that fails (but which is suppressed from propagating outside of
17
+ # block and so will not cause the test to fail).
18
+ # If the assertion passes, the failed assertion is written to
19
+ # stdout. This method is (only?) useful when testing other assertions.
20
+ #
21
+ # ====Example:
22
+ # assert_fail do
23
+ # assert_equal(5, 4)
24
+ # end
25
+ #
26
+ # ====Parameters:
27
+ # [message = ""]
28
+ # An optional additional message that will be displayed if the
29
+ # assertion fails.
30
+ # [&block]
31
+ # This block should contain an assertion that fails.
32
+ #
33
+ def assert_fail(message = "", &block)
34
+ full_message = build_message(message,
35
+ "Failed assertion was expected, but it did not occur.")
36
+
37
+ assert_block(full_message) do
38
+ begin
39
+ yield
40
+ false
41
+ rescue AssertionFailedError => e
42
+ true
43
+ end
44
+ end
45
+ end
46
+
47
+ #
48
+ # ====Description:
49
+ # This assertion passes if and only if boolean is false or nil.
50
+ #
51
+ # ====Parameters:
52
+ # [boolean]
53
+ # This must be false or nil or the assertion to pass
54
+ # [message = ""]
55
+ # An optional additional message that will be displayed if the
56
+ # assertion fails.
57
+ #
58
+ def assert_not(boolean, message = "")
59
+ full_message = build_message(message,
60
+ "<?> incorrectly is true.",
61
+ boolean)
62
+ assert_block(full_message) do
63
+ !boolean
64
+ end
65
+ end
66
+
67
+ #
68
+ # ====Description:
69
+ # This is a convenience wrapper around assert_operator. It asserts that
70
+ # the value is greater than zero
71
+ #
72
+ # ====Example:
73
+ # assert_positive(12)
74
+ #
75
+ # ====Parameters:
76
+ # [value]
77
+ # The number whose positiveness we wish to determine
78
+ # [message = ""]
79
+ # An optional additional message that will be displayed if the
80
+ # assertion fails.
81
+ #
82
+ def assert_positive(value, message = "")
83
+ assert_operator(value, :>, 0, message)
84
+ end
85
+
86
+ #
87
+ # ====Description:
88
+ # This is a convenience wrapper around assert_operator. It asserts that
89
+ # the value is less than zero
90
+ #
91
+ # ====Example:
92
+ # assert_negative(-5)
93
+ #
94
+ # ====Parameters:
95
+ # [value]
96
+ # The number whose negativeness we wish to determine
97
+ # [message = ""]
98
+ # An optional additional message that will be displayed if the
99
+ # assertion fails.
100
+ #
101
+ def assert_negative(value, message = "")
102
+ assert_operator(value, :<, 0, message)
103
+ end
104
+
105
+ #
106
+ # ====Description:
107
+ # This is a convenience wrapper around assert_operator. It asserts that
108
+ # lhs > rhs.
109
+ #
110
+ # ====Example:
111
+ # assert_greater_than(5, 4)
112
+ #
113
+ # ====Parameters:
114
+ # [lhs]
115
+ # The left-hand side of the comparison.
116
+ # [rhs]
117
+ # The right-hand side of the comparison.
118
+ # [message = ""]
119
+ # An optional additional message that will be displayed if the
120
+ # assertion fails.
121
+ #
122
+ def assert_greater_than(lhs, rhs, message = "")
123
+ assert_operator(lhs, :>, rhs, message)
124
+ end
125
+ alias assert_gt assert_greater_than
126
+
127
+ #
128
+ # ====Description:
129
+ # This is a convenience wrapper around assert_operator. It asserts that
130
+ # lhs >= rhs.
131
+ #
132
+ # ====Example:
133
+ # assert_greater_than_or_equal_to(5, 5)
134
+ #
135
+ # ====Parameters:
136
+ # [lhs]
137
+ # The left-hand side of the comparison.
138
+ # [rhs]
139
+ # The right-hand side of the comparison.
140
+ # [message = ""]
141
+ # An optional additional message that will be displayed if the
142
+ # assertion fails.
143
+ #
144
+ def assert_greater_than_or_equal_to(lhs, rhs, message = "")
145
+ assert_operator(lhs, :>=, rhs, message)
146
+ end
147
+ alias assert_ge assert_greater_than_or_equal_to
148
+
149
+ #
150
+ # ====Description:
151
+ # Will tell you if the elements in an Enum are sorted (ascending)
152
+ #
153
+ # ====Example:
154
+ # assert_sorted([1,2,3,4])
155
+ #
156
+ # ====Parameters:
157
+ # [enum]
158
+ # The enumeration to check for sortedness.
159
+ # [message = ""]
160
+ # An optional additional message that will be displayed if the
161
+ # assertion fails.
162
+ def assert_sorted(enum, message = "")
163
+ raise ArgumentError.new("enum must be enumerable") unless enum.is_a?(Enumerable)
164
+ assert_equal enum.clone.sort{|a,b| a <=> b }, enum
165
+ end
166
+
167
+ #
168
+ # ====Description:
169
+ # Will tell you if the elements in an Enum are sorted (ascending)
170
+ #
171
+ # ====Example:
172
+ # assert_sorted_desc([4,3,2,1])
173
+ #
174
+ # ====Parameters:
175
+ # [enum]
176
+ # The enumeration to check for sortedness.
177
+ # [message = ""]
178
+ # An optional additional message that will be displayed if the
179
+ # assertion fails.
180
+ def assert_sorted_desc(enum, message = "")
181
+ raise ArgumentError.new("enum must be enumerable") unless enum.is_a?(Enumerable)
182
+ assert_equal enum.clone.sort{|a,b| b <=> a }, enum
183
+ end
184
+
185
+
186
+ private
187
+ def check_enum_for_key_sortability(key, enum)
188
+ raise ArgumentError.new("key must be symbol or string") unless (key.is_a?(String) || key.is_a?(Symbol))
189
+ raise ArgumentError.new("enum must be enumerable") unless enum.is_a?(Enumerable)
190
+ raise ArgumentError.new("enum's elements don't respond to the key") unless enum.all?{ |x| (x.is_a?(Hash) && x.has_key?(key)) || x.respond_to?(key) }
191
+ end
192
+
193
+ public
194
+ #
195
+ # ====Description:
196
+ # Will tell you if the elements in an Enum are sorted (ascending)
197
+ # based on a key corresponding to a key in a hash or method on a
198
+ # class.
199
+ #
200
+ # ====Example:
201
+ # assert_sorted_by :bar, [{:bar => 1}, {:bar => 2}]
202
+ #
203
+ # ====Parameters:
204
+ # [key]
205
+ # A string or symbol to use to get a value on an object in 'enum'
206
+ # [enum]
207
+ # The enumeration to check for sortedness.
208
+ # [message = ""]
209
+ # An optional additional message that will be displayed if the
210
+ # assertion fails.
211
+ def assert_sorted_by(key, enum, message = "")
212
+ check_enum_for_key_sortability(key, enum)
213
+ assert_sorted enum.map{ |x| x.is_a?(Hash) ? x[key] : x.send(key) }
214
+ end
215
+
216
+ #
217
+ # ====Description:
218
+ # Will tell you if the elements in an Enum are sorted (descending)
219
+ # based on a key corresponding to a key in a hash or method on a
220
+ # class.
221
+ #
222
+ # ====Example:
223
+ # assert_sorted_by_desc :bar, [{:bar => 2}, {:bar => 1}]
224
+ #
225
+ # ====Parameters:
226
+ # [key]
227
+ # A string or symbol to use to get a value on an object in 'enum'
228
+ # [enum]
229
+ # The enumeration to check for sortedness.
230
+ # [message = ""]
231
+ # An optional additional message that will be displayed if the
232
+ # assertion fails.
233
+ def assert_sorted_by_desc(key, enum, message = "")
234
+ check_enum_for_key_sortability(key, enum)
235
+ assert_sorted_desc enum.map{ |x| x.is_a?(Hash) ? x[key] : x.send(key) }
236
+ end
237
+
238
+ #
239
+ # ====Description:
240
+ # Find out if a something is between two other things when compared.
241
+ # It asserts that lhs1 < rhs < lhs2 or lhs1 > rhs > lhs2
242
+ #
243
+ # ====Example:
244
+ # assert_between(Date.yesterday, Date.tomorrow, Date.today)
245
+ #
246
+ # ====Parameters:
247
+ # [lhs1]
248
+ # One of the things to compare against
249
+ # [lhs2]
250
+ # The other thing to compare against
251
+ # [rhs]
252
+ # The thing being tested for between-ness
253
+ # [message = ""]
254
+ # An optional additional message that will be displayed if the
255
+ # assertion fails.
256
+ #
257
+ def assert_between(lhs1, lhs2, rhs, message="")
258
+ if lhs1 == lhs2
259
+ full_message = build_message(message, "Gave the same value for both sides of range. <?> was not equal to <?>", rhs, lhs1)
260
+
261
+ assert_block(full_message) { lhs1 == rhs }
262
+ else
263
+ lower = lhs1 < lhs2 ? lhs1 : lhs2
264
+ higher = lhs1 < lhs2 ? lhs2 : lhs1
265
+ full_message = build_message(message, "<?> was not between <?> and <?>", rhs, lower, higher)
266
+ assert_block(full_message) { lower < rhs && rhs < higher }
267
+ end
268
+ end
269
+
270
+ #
271
+ # ====Description:
272
+ # This is a convenience wrapper around assert_operator. It asserts that
273
+ # lhs < rhs.
274
+ #
275
+ # ====Example:
276
+ # assert_less_than(4, 5)
277
+ #
278
+ # ====Parameters:
279
+ # [lhs]
280
+ # The left-hand side of the comparison.
281
+ # [rhs]
282
+ # The right-hand side of the comparison.
283
+ # [message = ""]
284
+ # An optional additional message that will be displayed if the
285
+ # assertion fails.
286
+ #
287
+ def assert_less_than(lhs, rhs, message = "")\
288
+ assert_operator(lhs, :<, rhs, message)
289
+ end
290
+ alias assert_lt assert_less_than
291
+
292
+ #
293
+ # ====Description:
294
+ # This is a convenience wrapper around assert_operator. It asserts that
295
+ # lhs <= rhs.
296
+ #
297
+ # ====Example:
298
+ # assert_less_than_or_equal_to(4, 4)
299
+ #
300
+ # ====Parameters:
301
+ # [lhs]
302
+ # The left-hand side of the comparison.
303
+ # [rhs]
304
+ # The right-hand side of the comparison.
305
+ # [message = ""]
306
+ # An optional additional message that will be displayed if the
307
+ # assertion fails.
308
+ #
309
+ def assert_less_than_or_equal_to(lhs, rhs, message = "")
310
+ assert_operator(lhs, :<=, rhs, message)
311
+ end
312
+ alias assert_le assert_less_than_or_equal_to
313
+
314
+ #
315
+ # ====Description:
316
+ # This assertion passes if and only if block throws an exception of
317
+ # class (or descended from class) expected_exception_class with
318
+ # message expected_exception_message.
319
+ #
320
+ # ====Example:
321
+ # assert_raise_message("Hello, exception!", RuntimeError) do
322
+ # raise "Hello, exception!"
323
+ # end
324
+ #
325
+ # ====Parameters:
326
+ # [expected_exception_message]
327
+ # The message expected to be contained in the exception thrown
328
+ # by block.
329
+ # [expected_exception_class]
330
+ # The expected class (or parent class) of the exception thrown by
331
+ # block.
332
+ # [message = ""]
333
+ # An optional additional message that will be displayed if the
334
+ # assertion fails.
335
+ # [&block]
336
+ # The block that is supposed to throw the specified exception.
337
+ #
338
+ def assert_raise_message(expected_exception_message,
339
+ expected_exception_class,
340
+ message = "",
341
+ &block)
342
+ full_message = build_message(message,
343
+ "<?> exception expected but none was thrown.",
344
+ expected_exception_class)
345
+ actual_exception = nil
346
+ assert_block(full_message) do
347
+ begin
348
+ yield
349
+ false
350
+ rescue Exception => e
351
+ actual_exception = e
352
+ true
353
+ end
354
+ end
355
+
356
+ full_message = build_message(message,
357
+ "<?> exception expected but was\n?",
358
+ expected_exception_class,
359
+ actual_exception)
360
+
361
+ assert_block(full_message) do
362
+ actual_exception.is_a?(expected_exception_class)
363
+ end
364
+
365
+ full_message = build_message(message,
366
+ "<?> exception message expected but was\n<?>",
367
+ expected_exception_message,
368
+ actual_exception.message)
369
+ assert_block(full_message) do
370
+ expected_exception_message == actual_exception.message
371
+ end
372
+ end
373
+
374
+ end
375
+ end
376
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
3
+
4
+ class AssertBetweenTest < Test::Unit::TestCase
5
+ def test_assert_between_4_4_5_fails
6
+ assert_raise_message("Gave the same value for both sides of range. <5> was not equal to <4>",
7
+ Test::Unit::AssertionFailedError) do
8
+ assert_between 4, 4, 5
9
+ end
10
+ end
11
+
12
+ def test_assert_between_3_2_5_fails
13
+ assert_raise_message("<5> was not between <2> and <3>", Test::Unit::AssertionFailedError) do
14
+ assert_between 3, 2, 5
15
+ end
16
+ end
17
+
18
+ def test_assert_between_4_8_6_succeeds
19
+ assert_between 4, 8, 6
20
+ end
21
+
22
+ def test_assert_between_8_4_6_succeeds
23
+ assert_between 8, 4, 6
24
+ end
25
+
26
+ def test_assert_between_on_now_between_past_and_future_times_succeeds
27
+ now = Time.now
28
+ before = now - 1
29
+ after = now + 1
30
+ assert_between before, after, now
31
+ end
32
+
33
+ def test_assert_between_on_now_between_future_and_past_times_succeeds
34
+ now = Time.now
35
+ before = now - 1
36
+ after = now + 1
37
+ assert_between after, before, now
38
+ end
39
+
40
+ def test_assert_between_on_before_time_between_now_and_future_times_succeeds
41
+ now = Time.now
42
+ before = now - 1
43
+ after = now + 1
44
+ assert_raises(Test::Unit::AssertionFailedError) { assert_between after, now, before }
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertFailTest < Test::Unit::TestCase
5
+ def test_assert_fail_fails_if_the_block_has_no_failed_assertions
6
+ failed_assertion = false
7
+ begin
8
+ assert_fail do
9
+ end
10
+ rescue Test::Unit::AssertionFailedError => e
11
+ failed_assertion = true
12
+ end
13
+
14
+ flunk("assert_fail incorrectly passed") unless failed_assertion
15
+ end
16
+
17
+ def test_assert_fail_succeeds_when_the_block_fails_an_assertion
18
+ assert_fail do
19
+ assert_equal 4, 5
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertGreaterThanOrEqualToTest < Test::Unit::TestCase
5
+ def test_assert_greater_than_or_equal_to_5_4_succeeds
6
+ assert_greater_than_or_equal_to(5, 4)
7
+ end
8
+
9
+ def test_assert_greater_than_or_equal_to_4_4_succeeds
10
+ assert_greater_than_or_equal_to(4, 4)
11
+ end
12
+
13
+ def test_assert_greater_than_or_equal_to_4_5_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_greater_than_or_equal_to(4, 5) }
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertGreaterThanTest < Test::Unit::TestCase
5
+ def test_assert_greater_than_5_4_succeeds
6
+ assert_greater_than(5, 4)
7
+ end
8
+
9
+ def test_assert_greater_than_4_4_fails
10
+ assert_raises(Test::Unit::AssertionFailedError) { assert_greater_than(4, 4) }
11
+ end
12
+
13
+ def test_assert_greater_than_4_5_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_greater_than(4, 5) }
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertLessThanTest < Test::Unit::TestCase
5
+ def test_assert_less_than_4_5_succeeds
6
+ assert_less_than(4, 5)
7
+ end
8
+
9
+ def test_assert_less_than_4_4_fails
10
+ assert_raises(Test::Unit::AssertionFailedError) { assert_less_than(4, 4) }
11
+ end
12
+
13
+ def test_assert_less_than_5_4_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_less_than(5, 4) }
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertLessThanOrEqualToTest < Test::Unit::TestCase
5
+ def test_assert_less_than_or_equal_to_4_5_succeeds
6
+ assert_less_than_or_equal_to(4, 5)
7
+ end
8
+
9
+ def test_assert_less_than_or_equal_to_4_4_succeeds
10
+ assert_less_than_or_equal_to(4, 4)
11
+ end
12
+
13
+ def test_assert_less_than_or_equal_to_5_4_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_less_than_or_equal_to(5, 4) }
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertNegativeTest < Test::Unit::TestCase
5
+ def test_assert_negative_negative_1_succeeds
6
+ assert_negative(-1)
7
+ end
8
+
9
+ def test_assert_negative_negative_1_point_0_succeeds
10
+ assert_negative(-1.0)
11
+ end
12
+
13
+ def test_assert_negative_0_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_negative(0) }
15
+ end
16
+
17
+ def test_assert_positive_1_fails
18
+ assert_raises(Test::Unit::AssertionFailedError) { assert_negative(1) }
19
+ end
20
+
21
+ def test_assert_positive_1_point_0_succeeds
22
+ assert_raises(Test::Unit::AssertionFailedError) { assert_negative(1.0) }
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertNotTest < Test::Unit::TestCase
5
+ def assert_not_false_succeeds
6
+ assert_not false
7
+ end
8
+
9
+ def test_assert_not_nil_succeeds
10
+ assert_not nil
11
+ end
12
+
13
+ def test_assert_not_true_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_not true }
15
+ end
16
+
17
+ def test_assert_not_5_fails
18
+ assert_raises(Test::Unit::AssertionFailedError) { assert_not 5 }
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require (File.expand_path "../test_helper", __FILE__)
3
+
4
+ class AssertPositiveTest < Test::Unit::TestCase
5
+ def test_assert_positive_1_succeeds
6
+ assert_positive(1)
7
+ end
8
+
9
+ def test_assert_positive_1_point_0_succeeds
10
+ assert_positive(1.0)
11
+ end
12
+
13
+ def test_assert_positive_0_fails
14
+ assert_raises(Test::Unit::AssertionFailedError) { assert_positive(0) }
15
+ end
16
+
17
+ def test_assert_positive_negative_1_fails
18
+ assert_raises(Test::Unit::AssertionFailedError) { assert_positive(-1) }
19
+ end
20
+
21
+ def test_assert_positive_negative_1_point_0_succeeds
22
+ assert_raises(Test::Unit::AssertionFailedError) { assert_positive(-1.0) }
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
3
+
4
+ class AssertRaiseMessageTest < Test::Unit::TestCase
5
+ def test_assert_raise_message_on_expected_error_succeeds
6
+ assert_raise_message("hello, error!", RuntimeError) do
7
+ raise RuntimeError, "hello, error!"
8
+ end
9
+ end
10
+
11
+ def test_assert_raise_message_with_no_exception_fails
12
+ assert_raises(Test::Unit::AssertionFailedError) do
13
+ assert_raise_message("hello, error!", RuntimeError) { }
14
+ end
15
+ end
16
+
17
+ def test_assert_raise_message_with_wrong_exception_fails
18
+ assert_raises(Test::Unit::AssertionFailedError) do
19
+ assert_raise_message("hello, error!", ArgumentError) do
20
+ raise RuntimeError, "hello, error!"
21
+ end
22
+ end
23
+ end
24
+
25
+ def test_assert_raise_message_with_wrong_error_message_fails
26
+ assert_raises(Test::Unit::AssertionFailedError) do
27
+ assert_raise_message("hello, error!", RuntimeError, "test message comparison") do
28
+ raise RuntimeError, "hello, errrr!"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path("../test_helper", __FILE__)
3
+
4
+ require "foo"
5
+ require "seahawk"
6
+
7
+ class AssertSortedByDescTest < Test::Unit::TestCase
8
+ def test_assert_sorted_by_desc_number_fails
9
+ assert_raise_message("key must be symbol or string", ArgumentError) do
10
+ assert_sorted_by_desc 12, []
11
+ end
12
+ end
13
+
14
+ def test_assert_sorted_by_desc_on_number_fails
15
+ assert_raise_message("enum must be enumerable", ArgumentError) do
16
+ assert_sorted_by_desc :foo, 1
17
+ end
18
+ end
19
+
20
+ def test_assert_sorted_by_desc_on_hash_that_doesnt_respond_to_sort_key_fails
21
+ assert_raise_message("enum's elements don't respond to the key", ArgumentError) do
22
+ assert_sorted_by_desc :bar, [{:bar => 2}, {:cow => 1}]
23
+ end
24
+ end
25
+
26
+ def test_assert_sorted_by_desc_on_array_of_objects_that_dont_respond_to_sort_key_fails
27
+ assert_raise_message("enum's elements don't respond to the key", ArgumentError) do
28
+ assert_sorted_by_desc :bar, [Foo.new(3), Seahawk.new(2)]
29
+ end
30
+ end
31
+
32
+ def test_assert_sorted_by_desc_on_array_of_objects_and_hash_that_dont_respond_to_sort_key_fails
33
+ assert_raise_message("enum's elements don't respond to the key", ArgumentError) do
34
+ assert_sorted_by_desc :bar, [Foo.new(2), {:moo => 1}]
35
+ end
36
+ end
37
+
38
+ def test_assert_sorted_by_desc_on_sorted_array_with_symbol_keys_succeeds
39
+ assert_sorted_by_desc :bar, [{:bar => 3}, {:bar => 2}, {:bar => 1}]
40
+ end
41
+
42
+ def test_assert_sorted_by_desc_on_sorted_array_with_string_keys_succeeds
43
+ assert_sorted_by_desc "bar", [{"bar" => 3}, {"bar" => 2}, {"bar" => 1}]
44
+ end
45
+
46
+ def test_assert_sorted_by_desc_on_unsorted_array_fails
47
+ assert_raises(Test::Unit::AssertionFailedError) do
48
+ assert_sorted_by_desc :bar, [{:bar => 2}, {:bar => 1}, {:bar => 3}]
49
+ end
50
+ end
51
+
52
+ def test_assert_sorted_by_desc_on_sorted_array_of_objects_succeeds
53
+ foos = [Foo.new(3), Foo.new(2), Foo.new(1)]
54
+ assert_sorted_by_desc :bar, foos
55
+ end
56
+
57
+ def test_assert_sorted_by_desc_on_unsorted_array_of_objects_fails
58
+ foos = [Foo.new(3), Foo.new(1), Foo.new(2)]
59
+ assert_raises(Test::Unit::AssertionFailedError) { assert_sorted_by_desc :bar, foos }
60
+ end
61
+
62
+ def test_assert_sorted_by_desc_on_sorted_object_mash_succeeds
63
+ assert_sorted_by_desc :bar, [{:bar => 2}, Foo.new(1)]
64
+ end
65
+
66
+ def test_assert_sorted_by_desc_on_unsorted_object_mash_fails
67
+ assert_raises(Test::Unit::AssertionFailedError) do
68
+ assert_sorted_by_desc :bar, [Foo.new(1), {:bar => 2}]
69
+ end
70
+ end
71
+ end