1 | # Author:: Nathaniel Talbott.
|
---|
2 | # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
---|
3 | # License:: Ruby license.
|
---|
4 |
|
---|
5 | require 'test/unit/assertions'
|
---|
6 | require 'runit/error'
|
---|
7 |
|
---|
8 | module RUNIT
|
---|
9 | module Assert
|
---|
10 | include Test::Unit::Assertions
|
---|
11 |
|
---|
12 | def setup_assert
|
---|
13 | end
|
---|
14 |
|
---|
15 | def assert_no_exception(*args, &block)
|
---|
16 | assert_nothing_raised(*args, &block)
|
---|
17 | end
|
---|
18 |
|
---|
19 | # To deal with the fact that RubyUnit does not check that the
|
---|
20 | # regular expression is, indeed, a regular expression, if it is
|
---|
21 | # not, we do our own assertion using the same semantics as
|
---|
22 | # RubyUnit
|
---|
23 | def assert_match(actual_string, expected_re, message="")
|
---|
24 | _wrap_assertion {
|
---|
25 | full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re)
|
---|
26 | assert_block(full_message) {
|
---|
27 | expected_re =~ actual_string
|
---|
28 | }
|
---|
29 | Regexp.last_match
|
---|
30 | }
|
---|
31 | end
|
---|
32 |
|
---|
33 | def assert_not_nil(actual, message="")
|
---|
34 | assert(!actual.nil?, message)
|
---|
35 | end
|
---|
36 |
|
---|
37 | def assert_not_match(actual_string, expected_re, message="")
|
---|
38 | assert_no_match(expected_re, actual_string, message)
|
---|
39 | end
|
---|
40 |
|
---|
41 | def assert_matches(*args)
|
---|
42 | assert_match(*args)
|
---|
43 | end
|
---|
44 |
|
---|
45 | def assert_fail(message="")
|
---|
46 | flunk(message)
|
---|
47 | end
|
---|
48 |
|
---|
49 | def assert_equal_float(expected, actual, delta, message="")
|
---|
50 | assert_in_delta(expected, actual, delta, message)
|
---|
51 | end
|
---|
52 |
|
---|
53 | def assert_send(object, method, *args)
|
---|
54 | super([object, method, *args])
|
---|
55 | end
|
---|
56 |
|
---|
57 | def assert_exception(exception, message="", &block)
|
---|
58 | assert_raises(exception, message, &block)
|
---|
59 | end
|
---|
60 |
|
---|
61 | def assert_respond_to(method, object, message="")
|
---|
62 | if (called_internally?)
|
---|
63 | super
|
---|
64 | else
|
---|
65 | super(object, method, message)
|
---|
66 | end
|
---|
67 | end
|
---|
68 |
|
---|
69 | def called_internally?
|
---|
70 | /assertions\.rb/.match(caller[1])
|
---|
71 | end
|
---|
72 | end
|
---|
73 | end
|
---|