xqsr3 0.38.2 → 0.39.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -6
  3. data/examples/count_word_frequencies.md +12 -12
  4. data/examples/count_word_frequencies.rb +4 -4
  5. data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
  6. data/lib/xqsr3/array_utilities.rb +2 -2
  7. data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
  8. data/lib/xqsr3/command_line_utilities.rb +2 -2
  9. data/lib/xqsr3/containers/frequency_map.rb +399 -399
  10. data/lib/xqsr3/containers/multi_map.rb +448 -448
  11. data/lib/xqsr3/containers.rb +3 -3
  12. data/lib/xqsr3/conversion/bool_parser.rb +51 -51
  13. data/lib/xqsr3/conversion/integer_parser.rb +87 -87
  14. data/lib/xqsr3/conversion.rb +3 -3
  15. data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
  16. data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
  17. data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
  18. data/lib/xqsr3/diagnostics.rb +3 -3
  19. data/lib/xqsr3/doc_.rb +130 -130
  20. data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
  21. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
  22. data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
  23. data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
  24. data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
  25. data/lib/xqsr3/extensions/hash/except.rb +16 -16
  26. data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
  27. data/lib/xqsr3/extensions/hash/match.rb +10 -10
  28. data/lib/xqsr3/extensions/hash/slice.rb +11 -11
  29. data/lib/xqsr3/extensions/hash.rb +1 -1
  30. data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
  31. data/lib/xqsr3/extensions/integer.rb +3 -0
  32. data/lib/xqsr3/extensions/io/writelines.rb +28 -28
  33. data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
  34. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
  35. data/lib/xqsr3/extensions/kernel.rb +1 -0
  36. data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
  37. data/lib/xqsr3/extensions/string/map_option_string.rb +4 -4
  38. data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
  39. data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
  40. data/lib/xqsr3/extensions/string/quote_if.rb +1 -1
  41. data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
  42. data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
  43. data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
  44. data/lib/xqsr3/extensions/string/truncate.rb +1 -1
  45. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
  46. data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
  47. data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
  48. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
  49. data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
  50. data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
  51. data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
  52. data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
  53. data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
  54. data/lib/xqsr3/extensions.rb +5 -5
  55. data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
  56. data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
  57. data/lib/xqsr3/hash_utilities.rb +3 -3
  58. data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
  59. data/lib/xqsr3/io/writelines.rb +122 -120
  60. data/lib/xqsr3/quality/parameter_checking.rb +445 -445
  61. data/lib/xqsr3/quality.rb +2 -2
  62. data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
  63. data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
  64. data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
  65. data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
  66. data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
  67. data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
  68. data/lib/xqsr3/string_utilities/truncate.rb +55 -55
  69. data/lib/xqsr3/string_utilities.rb +8 -8
  70. data/lib/xqsr3/version.rb +12 -12
  71. data/test/performance/frequency_map.rb +12 -12
  72. data/test/scratch/test_assert_raise_with_message.rb +11 -11
  73. data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
  74. data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
  75. data/test/unit/containers/tc_frequency_map.rb +591 -591
  76. data/test/unit/containers/tc_multi_map.rb +558 -558
  77. data/test/unit/conversion/tc_integer_parser.rb +72 -72
  78. data/test/unit/conversion/tc_to_bool.rb +25 -25
  79. data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
  80. data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
  81. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
  82. data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
  83. data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
  84. data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
  85. data/test/unit/extensions/hash/tc_except.rb +28 -28
  86. data/test/unit/extensions/hash/tc_slice.rb +13 -13
  87. data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
  88. data/test/unit/extensions/integer/ts_all.rb +12 -0
  89. data/test/unit/extensions/io/tc_writelines.rb +149 -77
  90. data/test/unit/extensions/kernel/tc_integer.rb +75 -75
  91. data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
  92. data/test/unit/extensions/object/tc_inspect.rb +50 -50
  93. data/test/unit/extensions/string/tc_bool.tb +24 -24
  94. data/test/unit/extensions/string/tc_ends_with.rb +53 -53
  95. data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
  96. data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
  97. data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
  98. data/test/unit/extensions/string/tc_quote_if.rb +18 -18
  99. data/test/unit/extensions/string/tc_starts_with.rb +53 -53
  100. data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
  101. data/test/unit/extensions/string/tc_truncate.rb +18 -18
  102. data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
  103. data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
  104. data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
  105. data/test/unit/hash_utilities/tc_has_match.rb +70 -70
  106. data/test/unit/hash_utilities/tc_match.rb +83 -83
  107. data/test/unit/io/tc_writelines.rb +166 -106
  108. data/test/unit/quality/tc_parameter_checking.rb +389 -389
  109. data/test/unit/string_utilities/tc_truncate.rb +27 -27
  110. data/test/unit/tc_version.rb +15 -15
  111. metadata +6 -2
@@ -3,14 +3,14 @@ require 'xqsr3/command_line_utilities/map_option_string'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::CommandLineUtilities::MapOptionString
6
+ include ::Xqsr3::CommandLineUtilities::MapOptionString
7
7
  end # class String
8
8
 
9
9
  class NilClass
10
10
 
11
- def map_option_string *args
11
+ def map_option_string *args
12
12
 
13
- nil
14
- end
13
+ nil
14
+ end
15
15
  end
16
16
 
@@ -3,6 +3,6 @@ require 'xqsr3/string_utilities/nil_if_empty'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::StringUtilities::NilIfEmpty
6
+ include ::Xqsr3::StringUtilities::NilIfEmpty
7
7
  end # class String
8
8
 
@@ -3,6 +3,6 @@ require 'xqsr3/string_utilities/nil_if_whitespace'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::StringUtilities::NilIfWhitespace
6
+ include ::Xqsr3::StringUtilities::NilIfWhitespace
7
7
  end # class String
8
8
 
@@ -3,6 +3,6 @@ require 'xqsr3/string_utilities/quote_if'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::StringUtilities::QuoteIf
6
+ include ::Xqsr3::StringUtilities::QuoteIf
7
7
  end # class String
8
8
 
@@ -3,6 +3,6 @@ require 'xqsr3/string_utilities/starts_with'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::StringUtilities::StartsWith
6
+ include ::Xqsr3::StringUtilities::StartsWith
7
7
  end # class String
8
8
 
@@ -3,13 +3,13 @@ require 'xqsr3/conversion/bool_parser'
3
3
 
4
4
  class String
5
5
 
6
- # Attempts to convert instance to a Boolean value, based on the given
7
- # +options+
8
- #
9
- # See Xqsr3::Conversion::BoolParser
10
- def to_bool **options
11
-
12
- return ::Xqsr3::Conversion::BoolParser.to_bool self, **options
13
- end
6
+ # Attempts to convert instance to a Boolean value, based on the given
7
+ # +options+
8
+ #
9
+ # See Xqsr3::Conversion::BoolParser
10
+ def to_bool **options
11
+
12
+ return ::Xqsr3::Conversion::BoolParser.to_bool self, **options
13
+ end
14
14
  end # class String
15
15
 
@@ -3,6 +3,6 @@ require 'xqsr3/string_utilities/to_symbol'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::StringUtilities::ToSymbol
6
+ include ::Xqsr3::StringUtilities::ToSymbol
7
7
  end # class String
8
8
 
@@ -3,6 +3,6 @@ require 'xqsr3/string_utilities/truncate'
3
3
 
4
4
  class String
5
5
 
6
- include ::Xqsr3::StringUtilities::Truncate
6
+ include ::Xqsr3::StringUtilities::Truncate
7
7
  end # class String
8
8
 
@@ -1,18 +1,21 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_eql
10
+ unless self.method_defined? :assert_eql
8
11
 
9
- # Assert that +expected+ and +actual+ have the same hash key, as
10
- # evaluated by the instance method +eq?+
11
- def assert_eql(expected, actual, failure_message = '')
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
- assert expected.eql?(actual), failure_message
14
- end
15
- end
16
+ assert expected.eql?(actual), failure_message
17
+ end
18
+ end
16
19
 
17
20
  end # class Assertions
18
21
  end # module Unit
@@ -1,17 +1,20 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_false
10
+ unless self.method_defined? :assert_false
8
11
 
9
- # Assert that +expression+ is +false+ (and not merely _falsey_)
10
- def assert_false(expression, failure_message = '')
12
+ # Assert that +expression+ is +false+ (and not merely _falsey_)
13
+ def assert_false(expression, failure_message = '')
11
14
 
12
- assert ::FalseClass === (expression), failure_message
13
- end
14
- end
15
+ assert ::FalseClass === (expression), failure_message
16
+ end
17
+ end
15
18
 
16
19
  end # class Assertions
17
20
  end # module Unit
@@ -1,17 +1,20 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_not
10
+ unless self.method_defined? :assert_not
8
11
 
9
- # Assert that +expression+ is _falsey_
10
- def assert_not(expression, failure_message = '')
12
+ # Assert that +expression+ is _falsey_
13
+ def assert_not(expression, failure_message = '')
11
14
 
12
- assert !(expression), failure_message
13
- end
14
- end
15
+ assert !(expression), failure_message
16
+ end
17
+ end
15
18
 
16
19
  end # class Assertions
17
20
  end # module Unit
@@ -1,18 +1,21 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_not_eql
10
+ unless self.method_defined? :assert_not_eql
8
11
 
9
- # Assert that +expected+ and +actual+ have different hash keys, as
10
- # evaluated by the instance method +eq?+
11
- def assert_not_eql(expected, actual, failure_message = '')
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
- assert !(expected.eql?(actual)), failure_message
14
- end
15
- end
16
+ assert !(expected.eql?(actual)), failure_message
17
+ end
18
+ end
16
19
 
17
20
  end # class Assertions
18
21
  end # module Unit
@@ -9,13 +9,13 @@ module Internal_ # :nodoc: all
9
9
  # @!visibility private
10
10
  module X_assert_raise_with_message_ # :nodoc: all
11
11
 
12
- if TestUnitVersion_.is_at_least? [ 3, 0, 8 ]
12
+ if TestUnitVersion_.is_at_least? [ 3, 0, 8 ]
13
13
 
14
- AssertionFailedError_ = Test::Unit::AssertionFailedError # :nodoc:
15
- else
14
+ AssertionFailedError_ = Test::Unit::AssertionFailedError # :nodoc:
15
+ else
16
16
 
17
- class AssertionFailedError_ < ArgumentError; end # :nodoc:
18
- end
17
+ class AssertionFailedError_ < ArgumentError; end # :nodoc:
18
+ end
19
19
 
20
20
  end # module X_assert_raise_with_message_
21
21
  end # module Internal_
@@ -28,87 +28,87 @@ module Unit
28
28
 
29
29
  module Assertions
30
30
 
31
- undef :assert_raise_with_message if respond_to? :assert_raise_with_message
31
+ undef :assert_raise_with_message if self.method_defined? :assert_raise_with_message
32
32
 
33
- # Asserts that the attached block raises an exception of one of the
34
- # exceptions defined by +type_spec+ and/or has a message matching
35
- # +message_spec+
36
- #
37
- # === Signature
38
- #
39
- # * *Parameters:*
40
- # - +type_spec+ (String, Regexp, [String], [Regexp], nil) Specification of type expectation(s)
41
- # - +message_spec+ (String, Regexp, [String], [Regexp], nil) Specification of message expectation(s)
42
- # - +failure_message+ (String, nil) Optional message to be used if the matching fails
43
- #
44
- # * *Block*
45
- # A required block containing code that is expected to raise an exception
46
- def assert_raise_with_message(type_spec, message_spec, failure_message = nil, &block)
33
+ # Asserts that the attached block raises an exception of one of the
34
+ # exceptions defined by +type_spec+ and/or has a message matching
35
+ # +message_spec+
36
+ #
37
+ # === Signature
38
+ #
39
+ # * *Parameters:*
40
+ # - +type_spec+ (String, Regexp, [String], [Regexp], nil) Specification of type expectation(s)
41
+ # - +message_spec+ (String, Regexp, [String], [Regexp], nil) Specification of message expectation(s)
42
+ # - +failure_message+ (String, nil) Optional message to be used if the matching fails
43
+ #
44
+ # * *Block*
45
+ # A required block containing code that is expected to raise an exception
46
+ def assert_raise_with_message(type_spec, message_spec, failure_message = nil, &block)
47
47
 
48
- unless block_given?
48
+ unless block_given?
49
49
 
50
- msg = "WARNING: no block_given to assert_raise_with_message() called from: #{caller[0]}"
50
+ msg = "WARNING: no block_given to assert_raise_with_message() called from: #{caller[0]}"
51
51
 
52
- warn "\n#{msg}"
52
+ warn "\n#{msg}"
53
53
 
54
- assert false, msg
55
- end
54
+ assert false, msg
55
+ end
56
56
 
57
- case type_spec
58
- when ::Array, nil
57
+ case type_spec
58
+ when ::Array, nil
59
59
 
60
- ;
61
- else
60
+ ;
61
+ else
62
62
 
63
- type_spec = [ type_spec ]
64
- end
63
+ type_spec = [ type_spec ]
64
+ end
65
65
 
66
- case message_spec
67
- when ::Array, nil
66
+ case message_spec
67
+ when ::Array, nil
68
68
 
69
- ;
70
- else
69
+ ;
70
+ else
71
71
 
72
- message_spec = [ message_spec ]
73
- end
72
+ message_spec = [ message_spec ]
73
+ end
74
74
 
75
75
 
76
- begin
76
+ begin
77
77
 
78
- yield
78
+ yield
79
79
 
80
- assert false, 'the block did not throw an exception as was expected'
81
- rescue ::Xqsr3::Internal_::X_assert_raise_with_message_::AssertionFailedError_
80
+ assert false, 'the block did not throw an exception as was expected'
81
+ rescue ::Xqsr3::Internal_::X_assert_raise_with_message_::AssertionFailedError_
82
82
 
83
- raise
84
- rescue Exception => x
83
+ raise
84
+ rescue Exception => x
85
85
 
86
- if type_spec
86
+ if type_spec
87
87
 
88
- 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}
89
- end
88
+ 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}
89
+ end
90
90
 
91
- if message_spec
91
+ if message_spec
92
92
 
93
- assert false, "exception message not of any of required messages; '#{x.message}' given" unless message_spec.any? do |m|
93
+ assert false, "exception message not of any of required messages; '#{x.message}' given" unless message_spec.any? do |m|
94
94
 
95
- case m
96
- when ::Regexp
95
+ case m
96
+ when ::Regexp
97
97
 
98
- x.message =~ m
99
- when ::String
98
+ x.message =~ m
99
+ when ::String
100
100
 
101
- x.message == m
102
- else
101
+ x.message == m
102
+ else
103
103
 
104
- warn "\nunsupported message_spec entry '#{m}' (#{m.class})"
105
- end
106
- end
107
- end
104
+ warn "\nunsupported message_spec entry '#{m}' (#{m.class})"
105
+ end
106
+ end
107
+ end
108
108
 
109
- assert true
110
- end
111
- end
109
+ assert true
110
+ end
111
+ end
112
112
  end # class Assertions
113
113
  end # module Unit
114
114
  end # module Test
@@ -1,19 +1,22 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_subclass_of
10
+ unless self.method_defined? :assert_subclass_of
8
11
 
9
- # Assert that +tested_class+ is a sub-class of +parent_class+
10
- def assert_subclass_of(parent_class, tested_class, failure_message = nil)
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
- failure_message ||= "#{tested_class} is not a subclass of #{parent_class}"
15
+ failure_message ||= "#{tested_class} is not a subclass of #{parent_class}"
13
16
 
14
- assert(tested_class < parent_class, failure_message)
15
- end
16
- end
17
+ assert(tested_class < parent_class, failure_message)
18
+ end
19
+ end
17
20
 
18
21
  end # class Assertions
19
22
  end # module Unit
@@ -1,19 +1,22 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_superclass_of
10
+ unless self.method_defined? :assert_superclass_of
8
11
 
9
- # Assert that +tested_class+ is a super-class of +child_class+
10
- def assert_superclass_of(child_class, tested_class, failure_message = nil)
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
- failure_message ||= "#{tested_class} is not a superclass of #{child_class}"
15
+ failure_message ||= "#{tested_class} is not a superclass of #{child_class}"
13
16
 
14
- assert(child_class < tested_class, failure_message)
15
- end
16
- end
17
+ assert(child_class < tested_class, failure_message)
18
+ end
19
+ end
17
20
 
18
21
  end # class Assertions
19
22
  end # module Unit
@@ -1,17 +1,20 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_true
10
+ unless self.method_defined? :assert_true
8
11
 
9
- # Assert that +expression+ is +true+ (and not merely _truey_)
10
- def assert_true(expression, failure_message = '')
12
+ # Assert that +expression+ is +true+ (and not merely _truey_)
13
+ def assert_true(expression, failure_message = '')
11
14
 
12
- assert ::TrueClass === (expression), failure_message
13
- end
14
- end
15
+ assert ::TrueClass === (expression), failure_message
16
+ end
17
+ end
15
18
 
16
19
  end # class Assertions
17
20
  end # module Unit
@@ -1,61 +1,64 @@
1
1
 
2
+ require 'test/unit/assertions'
3
+
4
+
2
5
  module Test
3
6
  module Unit
4
7
 
5
8
  module Assertions
6
9
 
7
- unless respond_to? :assert_type_has_instance_methods
10
+ unless self.method_defined? :assert_type_has_instance_methods
8
11
 
9
- # Fails unless the given +type+ responds to all of the messages
10
- # given by +message_spec+
11
- #
12
- # === Signature
13
- #
14
- # * *Parameters:*
15
- # - +type+ (::Class) The type
16
- # - +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)
17
- # - +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
18
- def assert_type_has_instance_methods(type, message_spec, failure_message = nil)
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
- warn "type parameter - '#{type} (#{type.class})' - should be a Class" unless type.is_a?(::Class)
23
+ warn "type parameter - '#{type} (#{type.class})' - should be a Class" unless type.is_a?(::Class)
21
24
 
22
- case message_spec
23
- when ::Hash
25
+ case message_spec
26
+ when ::Hash
24
27
 
25
- warn "every key in a Hash message_spec should be of type Symbol" unless message_spec.keys.all? { |k| ::Symbol === k }
26
- when ::Array
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
- warn "every key in an Array message_spec should be of type Symbol" unless message_spec.all? { |k| ::Symbol === k }
31
+ warn "every key in an Array message_spec should be of type Symbol" unless message_spec.all? { |k| ::Symbol === k }
29
32
 
30
- message_spec = Hash[message_spec.map { |s| [ s, nil ] }]
31
- when ::Symbol
33
+ message_spec = Hash[message_spec.map { |s| [ s, nil ] }]
34
+ when ::Symbol
32
35
 
33
- message_spec[message_spec] = nil
34
- else
36
+ message_spec[message_spec] = nil
37
+ else
35
38
 
36
- msg = "message_spec - '#{message_spec} (#{message_spec.class})' - should be a Symbol, an Array of Symbols, or a Hash of Symbol => message"
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
- warn msg
41
+ warn msg
39
42
 
40
- return assert false, msg
41
- end
43
+ return assert false, msg
44
+ end
42
45
 
43
- ims = type.instance_methods
46
+ ims = type.instance_methods
44
47
 
45
- message_spec.each do |sym, message|
48
+ message_spec.each do |sym, message|
46
49
 
47
- unless ims.include? sym
50
+ unless ims.include? sym
48
51
 
49
- message ||= failure_message
50
- message ||= "type #{type} does not contain the instance method #{sym}"
52
+ message ||= failure_message
53
+ message ||= "type #{type} does not contain the instance method #{sym}"
51
54
 
52
- return assert false, message
53
- end
54
- end
55
+ return assert false, message
56
+ end
57
+ end
55
58
 
56
- assert true
57
- end
58
- end
59
+ assert true
60
+ end
61
+ end
59
62
 
60
63
  end # class Assertions
61
64
  end # module Unit
@@ -1,13 +1,13 @@
1
1
 
2
2
  %w{
3
3
 
4
- array
5
- enumerable
6
- hash
7
- io
4
+ array
5
+ enumerable
6
+ hash
7
+ io
8
8
  }.each do |name|
9
9
 
10
- require File.join(File.dirname(__FILE__), 'extensions', name)
10
+ require File.join(File.dirname(__FILE__), 'extensions', name)
11
11
  end
12
12
 
13
13