xqsr3 0.39.1 → 0.39.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/count_word_frequencies.rb +2 -0
- data/lib/xqsr3/array_utilities/join_with_or.rb +50 -53
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -69
- data/lib/xqsr3/containers/frequency_map.rb +408 -394
- data/lib/xqsr3/containers/multi_map.rb +464 -446
- data/lib/xqsr3/conversion/bool_parser.rb +49 -54
- data/lib/xqsr3/conversion/integer_parser.rb +84 -89
- data/lib/xqsr3/diagnostics/exception_utilities.rb +127 -132
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +98 -102
- data/lib/xqsr3/diagnostics/inspect_builder.rb +83 -84
- data/lib/xqsr3/extensions/array/join_with_or.rb +2 -1
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +1 -4
- data/lib/xqsr3/extensions/enumerable/unique.rb +1 -4
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -0
- data/lib/xqsr3/extensions/hash/except.rb +1 -1
- data/lib/xqsr3/extensions/hash/has_match.rb +3 -2
- data/lib/xqsr3/extensions/hash/match.rb +3 -2
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +1 -4
- data/lib/xqsr3/extensions/io/writelines.rb +4 -7
- data/lib/xqsr3/extensions/kernel/integer.rb +7 -9
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +1 -3
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -0
- data/lib/xqsr3/extensions/string/map_option_string.rb +1 -0
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -0
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -0
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -0
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -0
- data/lib/xqsr3/extensions/string/to_bool.rb +1 -0
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -0
- data/lib/xqsr3/extensions/string/truncate.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +58 -55
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -37
- data/lib/xqsr3/hash_utilities/deep_transform.rb +63 -67
- data/lib/xqsr3/hash_utilities/key_matching.rb +72 -76
- data/lib/xqsr3/internal_/test_unit_version_.rb +10 -8
- data/lib/xqsr3/io/writelines.rb +12 -12
- data/lib/xqsr3/quality/parameter_checking.rb +406 -411
- data/lib/xqsr3/string_utilities/ends_with.rb +60 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +31 -35
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +32 -36
- data/lib/xqsr3/string_utilities/quote_if.rb +48 -57
- data/lib/xqsr3/string_utilities/starts_with.rb +60 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +77 -81
- data/lib/xqsr3/string_utilities/truncate.rb +56 -60
- data/lib/xqsr3/version.rb +2 -2
- data/test/performance/frequency_map.rb +3 -0
- data/test/scratch/test_assert_raise_with_message.rb +2 -0
- data/test/unit/array_utilities/tc_join_with_or.rb +3 -1
- data/test/unit/command_line_utilities/tc_map_option_string.rb +3 -0
- data/test/unit/containers/tc_frequency_map.rb +5 -2
- data/test/unit/containers/tc_multi_map.rb +3 -0
- data/test/unit/conversion/tc_integer_parser.rb +18 -17
- data/test/unit/conversion/tc_to_bool.rb +2 -0
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +7 -5
- data/test/unit/diagnostics/tc_exception_utilities.rb +2 -0
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +2 -0
- data/test/unit/extensions/enumerable/tc_detect_map.rb +3 -2
- data/test/unit/extensions/enumerable/tc_unique.rb +2 -0
- data/test/unit/extensions/hash/tc_deep_transform.rb +2 -0
- data/test/unit/extensions/hash/tc_except.rb +3 -1
- data/test/unit/extensions/hash/tc_hash.rb +1 -0
- data/test/unit/extensions/hash/tc_slice.rb +2 -0
- data/test/unit/extensions/integer/tc_to_s_grp.rb +2 -0
- data/test/unit/extensions/io/tc_writelines.rb +86 -0
- data/test/unit/extensions/kernel/tc_integer.rb +10 -9
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +2 -0
- data/test/unit/extensions/object/tc_inspect.rb +15 -13
- data/test/unit/extensions/string/tc_bool.tb +2 -0
- data/test/unit/extensions/string/tc_ends_with.rb +2 -0
- data/test/unit/extensions/string/tc_map_option_string.rb +2 -0
- data/test/unit/extensions/string/tc_nil_if_empty.rb +2 -0
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +2 -0
- data/test/unit/extensions/string/tc_quote_if.rb +2 -0
- data/test/unit/extensions/string/tc_starts_with.rb +2 -0
- data/test/unit/extensions/string/tc_to_symbol.rb +2 -0
- data/test/unit/extensions/string/tc_truncate.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +2 -0
- data/test/unit/hash_utilities/tc_has_match.rb +1 -0
- data/test/unit/hash_utilities/tc_match.rb +1 -0
- data/test/unit/io/tc_writelines.rb +63 -0
- data/test/unit/quality/tc_parameter_checking.rb +1 -0
- data/test/unit/string_utilities/tc_truncate.rb +2 -0
- data/test/unit/tc_version.rb +2 -0
- metadata +3 -3
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Adds a Integer 'overload' to the Kernel module
|
6
6
|
#
|
7
7
|
# Created: 21st November 2017
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -47,8 +47,6 @@
|
|
47
47
|
|
48
48
|
require 'xqsr3/conversion/integer_parser'
|
49
49
|
|
50
|
-
# ##########################################################
|
51
|
-
# ::Kernel
|
52
50
|
|
53
51
|
=begin
|
54
52
|
=end
|
@@ -62,14 +60,14 @@ module Kernel
|
|
62
60
|
# === Signature
|
63
61
|
#
|
64
62
|
# * *Parameters:*
|
65
|
-
# - +arg+ The argument to be converted (to +Fixnum+ or +Bignum+)
|
66
|
-
# - +base+ A value of 0, or between 2 and 36. Defaults to 0
|
67
|
-
# - +options+
|
68
|
-
# - +block+ An optional caller-supplied block that will be invoked with the +ArgumentError+ exception, allowing the caller to take additional action. If the block returns then its return value will be returned to the caller
|
63
|
+
# - +arg+ The argument to be converted (to +Fixnum+ or +Bignum+);
|
64
|
+
# - +base+ A value of 0, or between 2 and 36. Defaults to 0;
|
65
|
+
# - +options+ (+Hash+) Options that control the behaviour of the method;
|
66
|
+
# - +block+ An optional caller-supplied block that will be invoked with the +ArgumentError+ exception, allowing the caller to take additional action. If the block returns then its return value will be returned to the caller;
|
69
67
|
#
|
70
68
|
# * *Options:*
|
71
|
-
# - +:default+ A default value to be used when +arg+ is +nil+ or cannot be converted by (the original) +Kernel#Integer
|
72
|
-
# - +:nil+ Returns +nil+ if +arg+ is +nil+ or cannot be converted by (the original) +Kernel#Integer+. Ignored if +:default+ is specified
|
69
|
+
# - +:default+ A default value to be used when +arg+ is +nil+ or cannot be converted by (the original) +Kernel#Integer+;
|
70
|
+
# - +:nil+ Returns +nil+ if +arg+ is +nil+ or cannot be converted by (the original) +Kernel#Integer+. Ignored if +:default+ is specified;
|
73
71
|
def Integer(arg, base = 0, **options, &block)
|
74
72
|
|
75
73
|
::Xqsr3::Conversion::IntegerParser.to_integer arg, base = 0, **options, &block
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Adds a raise_with_options() method to the Kernel module
|
6
6
|
#
|
7
7
|
# Created: 12th February 2015
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -47,8 +47,6 @@
|
|
47
47
|
|
48
48
|
require 'xqsr3/diagnostics/exception_utilities'
|
49
49
|
|
50
|
-
# ##########################################################
|
51
|
-
# ::Kernel
|
52
50
|
|
53
51
|
=begin
|
54
52
|
=end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_eql
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
# Assert that +expected+ and +actual+ have the same hash key, as
|
13
|
+
# evaluated by the instance method +eq?+
|
14
|
+
def assert_eql(expected, actual, failure_message = '')
|
12
15
|
|
13
|
-
|
16
|
+
assert expected.eql?(actual), failure_message
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end # class Assertions
|
19
|
+
end # class Assertions
|
18
20
|
end # module Unit
|
19
21
|
end # module Test
|
20
22
|
|
@@ -1,19 +1,21 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_false
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
# Assert that +expression+ is +false+ (and not merely _falsey_)
|
13
|
+
def assert_false(expression, failure_message = '')
|
11
14
|
|
12
|
-
|
15
|
+
assert ::FalseClass === (expression), failure_message
|
16
|
+
end
|
13
17
|
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end # class Assertions
|
18
|
+
end # class Assertions
|
17
19
|
end # module Unit
|
18
20
|
end # module Test
|
19
21
|
|
@@ -1,19 +1,21 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_not
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
# Assert that +expression+ is _falsey_
|
13
|
+
def assert_not(expression, failure_message = '')
|
11
14
|
|
12
|
-
|
15
|
+
assert !(expression), failure_message
|
16
|
+
end
|
13
17
|
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end # class Assertions
|
18
|
+
end # class Assertions
|
17
19
|
end # module Unit
|
18
20
|
end # module Test
|
19
21
|
|
@@ -1,20 +1,22 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_not_eql
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
# Assert that +expected+ and +actual+ have different hash keys, as
|
13
|
+
# evaluated by the instance method +eq?+
|
14
|
+
def assert_not_eql(expected, actual, failure_message = '')
|
12
15
|
|
13
|
-
|
16
|
+
assert !(expected.eql?(actual)), failure_message
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end # class Assertions
|
19
|
+
end # class Assertions
|
18
20
|
end # module Unit
|
19
21
|
end # module Test
|
20
22
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
require 'xqsr3/internal_/test_unit_version_'
|
3
3
|
|
4
|
+
|
4
5
|
# :stopdoc:
|
5
6
|
|
6
7
|
module Xqsr3
|
@@ -23,93 +24,95 @@ end # module Xqsr3
|
|
23
24
|
|
24
25
|
# :startdoc:
|
25
26
|
|
27
|
+
|
26
28
|
module Test
|
27
29
|
module Unit
|
28
30
|
|
29
|
-
module Assertions
|
31
|
+
module Assertions
|
30
32
|
|
31
|
-
|
33
|
+
undef :assert_raise_with_message if self.method_defined? :assert_raise_with_message
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
# Asserts that the attached block raises an exception of one of the
|
36
|
+
# exceptions defined by +type_spec+ and/or has a message matching
|
37
|
+
# +message_spec+
|
38
|
+
#
|
39
|
+
# === Signature
|
40
|
+
#
|
41
|
+
# * *Parameters:*
|
42
|
+
# - +type_spec+ (+String+, +Regexp+, +[ String ]+, +[ Regexp ]+, +nil+) Specification of type expectation(s);
|
43
|
+
# - +message_spec+ (+String+, +Regexp+, +[ String ]+, +[ Regexp ]+, +nil+) Specification of message expectation(s);
|
44
|
+
# - +failure_message+ (+String+, +nil+) Optional message to be used if the matching fails;
|
45
|
+
# - +options+ (+Hash+) Options that control the behaviour of the method;
|
46
|
+
#
|
47
|
+
# * *Block*
|
48
|
+
# A required block containing code that is expected to raise an exception
|
49
|
+
def assert_raise_with_message(type_spec, message_spec, failure_message = nil, **options, &block)
|
47
50
|
|
48
|
-
|
51
|
+
unless block_given?
|
49
52
|
|
50
|
-
|
53
|
+
msg = "WARNING: no block_given to assert_raise_with_message() called from: #{caller[0]}"
|
51
54
|
|
52
|
-
|
55
|
+
warn "\n#{msg}"
|
53
56
|
|
54
|
-
|
55
|
-
|
57
|
+
assert false, msg
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
60
|
+
case type_spec
|
61
|
+
when ::Array, nil
|
59
62
|
|
60
|
-
|
61
|
-
|
63
|
+
;
|
64
|
+
else
|
62
65
|
|
63
|
-
|
64
|
-
|
66
|
+
type_spec = [ type_spec ]
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
case message_spec
|
70
|
+
when ::Array, nil
|
68
71
|
|
69
|
-
|
70
|
-
|
72
|
+
;
|
73
|
+
else
|
71
74
|
|
72
|
-
|
73
|
-
|
75
|
+
message_spec = [ message_spec ]
|
76
|
+
end
|
74
77
|
|
75
78
|
|
76
|
-
|
79
|
+
begin
|
77
80
|
|
78
|
-
|
81
|
+
yield
|
79
82
|
|
80
|
-
|
81
|
-
|
83
|
+
assert false, 'the block did not throw an exception as was expected'
|
84
|
+
rescue ::Xqsr3::Internal_::X_assert_raise_with_message_::AssertionFailedError_
|
82
85
|
|
83
|
-
|
84
|
-
|
86
|
+
raise
|
87
|
+
rescue Exception => x
|
85
88
|
|
86
|
-
|
89
|
+
if type_spec
|
87
90
|
|
88
|
-
|
89
|
-
|
91
|
+
assert false, "exception (#{x.class}) - message: '#{x.message}' - not of any of required types (#{type_spec.join(', ')}); #{x.class} given" unless type_spec.any? { |c| x.is_a? c}
|
92
|
+
end
|
90
93
|
|
91
|
-
|
94
|
+
if message_spec
|
92
95
|
|
93
|
-
|
96
|
+
assert false, "exception message not of any of required messages; '#{x.message}' given" unless message_spec.any? do |m|
|
94
97
|
|
95
|
-
|
96
|
-
|
98
|
+
case m
|
99
|
+
when ::Regexp
|
97
100
|
|
98
|
-
|
99
|
-
|
101
|
+
x.message =~ m
|
102
|
+
when ::String
|
100
103
|
|
101
|
-
|
102
|
-
|
104
|
+
x.message == m
|
105
|
+
else
|
103
106
|
|
104
|
-
|
107
|
+
warn "\nunsupported message_spec entry '#{m}' (#{m.class})"
|
108
|
+
end
|
105
109
|
end
|
106
110
|
end
|
107
|
-
end
|
108
111
|
|
109
|
-
|
112
|
+
assert true
|
113
|
+
end
|
110
114
|
end
|
111
|
-
end
|
112
|
-
end # class Assertions
|
115
|
+
end # module Assertions
|
113
116
|
end # module Unit
|
114
117
|
end # module Test
|
115
118
|
|
@@ -1,21 +1,23 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_subclass_of
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
# Assert that +tested_class+ is a sub-class of +parent_class+
|
13
|
+
def assert_subclass_of(parent_class, tested_class, failure_message = nil)
|
11
14
|
|
12
|
-
|
15
|
+
failure_message ||= "#{tested_class} is not a subclass of #{parent_class}"
|
13
16
|
|
14
|
-
|
17
|
+
assert(tested_class < parent_class, failure_message)
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end # class Assertions
|
20
|
+
end # class Assertions
|
19
21
|
end # module Unit
|
20
22
|
end # module Test
|
21
23
|
|
@@ -1,21 +1,23 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_superclass_of
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
# Assert that +tested_class+ is a super-class of +child_class+
|
13
|
+
def assert_superclass_of(child_class, tested_class, failure_message = nil)
|
11
14
|
|
12
|
-
|
15
|
+
failure_message ||= "#{tested_class} is not a superclass of #{child_class}"
|
13
16
|
|
14
|
-
|
17
|
+
assert(child_class < tested_class, failure_message)
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end # class Assertions
|
20
|
+
end # class Assertions
|
19
21
|
end # module Unit
|
20
22
|
end # module Test
|
21
23
|
|
@@ -1,19 +1,21 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_true
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
# Assert that +expression+ is +true+ (and not merely _truey_)
|
13
|
+
def assert_true(expression, failure_message = '')
|
11
14
|
|
12
|
-
|
15
|
+
assert ::TrueClass === (expression), failure_message
|
16
|
+
end
|
13
17
|
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end # class Assertions
|
18
|
+
end # class Assertions
|
17
19
|
end # module Unit
|
18
20
|
end # module Test
|
19
21
|
|
@@ -1,63 +1,65 @@
|
|
1
1
|
|
2
|
+
require 'test/unit/assertions'
|
3
|
+
|
4
|
+
|
2
5
|
module Test
|
3
6
|
module Unit
|
4
7
|
|
5
|
-
module Assertions
|
8
|
+
module Assertions
|
6
9
|
|
7
|
-
|
10
|
+
unless self.method_defined? :assert_type_has_instance_methods
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
# Fails unless the given +type+ responds to all of the messages
|
13
|
+
# given by +message_spec+
|
14
|
+
#
|
15
|
+
# === Signature
|
16
|
+
#
|
17
|
+
# * *Parameters:*
|
18
|
+
# - +type+ (+Class+) The type;
|
19
|
+
# - +message_spec+ (+Symbol+, +Array+, +Hash+) A specification of message(s) received by the instances of +type+. If a +Symbol+, then instances must respond to this single message. If an ::Array (all elements of which must be +Symbol+), then instances must respond to _all_ messages. If a ::Hash, then instances must respond to _all_ messages represented by the keys; the values are available for specifying a custom failure message (or value is +nil+ for stock message);
|
20
|
+
# - +failure_message+ (+String+) If specified, is used when instances of +type+ do not respond to a message and no custom failure message is provided for it;
|
21
|
+
def assert_type_has_instance_methods(type, message_spec, failure_message = nil)
|
19
22
|
|
20
|
-
|
23
|
+
warn "type parameter - '#{type} (#{type.class})' - should be a Class" unless type.is_a?(::Class)
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
case message_spec
|
26
|
+
when ::Hash
|
24
27
|
|
25
|
-
|
26
|
-
|
28
|
+
warn "every key in a Hash message_spec should be of type Symbol" unless message_spec.keys.all? { |k| ::Symbol === k }
|
29
|
+
when ::Array
|
27
30
|
|
28
|
-
|
31
|
+
warn "every key in an Array message_spec should be of type Symbol" unless message_spec.all? { |k| ::Symbol === k }
|
29
32
|
|
30
|
-
|
31
|
-
|
33
|
+
message_spec = Hash[message_spec.map { |s| [ s, nil ] }]
|
34
|
+
when ::Symbol
|
32
35
|
|
33
|
-
|
34
|
-
|
36
|
+
message_spec[message_spec] = nil
|
37
|
+
else
|
35
38
|
|
36
|
-
|
39
|
+
msg = "message_spec - '#{message_spec} (#{message_spec.class})' - should be a Symbol, an Array of Symbols, or a Hash of Symbol => message"
|
37
40
|
|
38
|
-
|
41
|
+
warn msg
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
return assert false, msg
|
44
|
+
end
|
42
45
|
|
43
|
-
|
46
|
+
ims = type.instance_methods
|
44
47
|
|
45
|
-
|
48
|
+
message_spec.each do |sym, message|
|
46
49
|
|
47
|
-
|
50
|
+
unless ims.include? sym
|
48
51
|
|
49
|
-
|
50
|
-
|
52
|
+
message ||= failure_message
|
53
|
+
message ||= "type #{type} does not contain the instance method #{sym}"
|
51
54
|
|
52
|
-
|
55
|
+
return assert false, message
|
56
|
+
end
|
53
57
|
end
|
54
|
-
end
|
55
58
|
|
56
|
-
|
59
|
+
assert true
|
60
|
+
end
|
57
61
|
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end # class Assertions
|
62
|
+
end # class Assertions
|
61
63
|
end # module Unit
|
62
64
|
end # module Test
|
63
65
|
|