respect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +289 -0
  3. data/RELATED_WORK.md +40 -0
  4. data/RELEASE_NOTES.md +23 -0
  5. data/Rakefile +31 -0
  6. data/STATUS_MATRIX.html +137 -0
  7. data/lib/respect.rb +231 -0
  8. data/lib/respect/any_schema.rb +22 -0
  9. data/lib/respect/array_def.rb +28 -0
  10. data/lib/respect/array_schema.rb +203 -0
  11. data/lib/respect/boolean_schema.rb +32 -0
  12. data/lib/respect/composite_schema.rb +86 -0
  13. data/lib/respect/core_statements.rb +206 -0
  14. data/lib/respect/datetime_schema.rb +27 -0
  15. data/lib/respect/def_without_name.rb +6 -0
  16. data/lib/respect/divisible_by_validator.rb +20 -0
  17. data/lib/respect/doc_helper.rb +24 -0
  18. data/lib/respect/doc_parser.rb +37 -0
  19. data/lib/respect/dsl_dumper.rb +181 -0
  20. data/lib/respect/equal_to_validator.rb +20 -0
  21. data/lib/respect/fake_name_proxy.rb +116 -0
  22. data/lib/respect/float_schema.rb +27 -0
  23. data/lib/respect/format_validator.rb +136 -0
  24. data/lib/respect/global_def.rb +79 -0
  25. data/lib/respect/greater_than_or_equal_to_validator.rb +19 -0
  26. data/lib/respect/greater_than_validator.rb +19 -0
  27. data/lib/respect/has_constraints.rb +34 -0
  28. data/lib/respect/hash_def.rb +40 -0
  29. data/lib/respect/hash_schema.rb +218 -0
  30. data/lib/respect/in_validator.rb +19 -0
  31. data/lib/respect/integer_schema.rb +27 -0
  32. data/lib/respect/ip_addr_schema.rb +23 -0
  33. data/lib/respect/ipv4_addr_schema.rb +27 -0
  34. data/lib/respect/ipv6_addr_schema.rb +27 -0
  35. data/lib/respect/items_def.rb +21 -0
  36. data/lib/respect/json_schema_html_formatter.rb +143 -0
  37. data/lib/respect/less_than_or_equal_to_validator.rb +19 -0
  38. data/lib/respect/less_than_validator.rb +19 -0
  39. data/lib/respect/match_validator.rb +19 -0
  40. data/lib/respect/max_length_validator.rb +20 -0
  41. data/lib/respect/min_length_validator.rb +20 -0
  42. data/lib/respect/multiple_of_validator.rb +10 -0
  43. data/lib/respect/null_schema.rb +26 -0
  44. data/lib/respect/numeric_schema.rb +33 -0
  45. data/lib/respect/org3_dumper.rb +213 -0
  46. data/lib/respect/regexp_schema.rb +19 -0
  47. data/lib/respect/schema.rb +285 -0
  48. data/lib/respect/schema_def.rb +16 -0
  49. data/lib/respect/string_schema.rb +21 -0
  50. data/lib/respect/unit_test_helper.rb +37 -0
  51. data/lib/respect/uri_schema.rb +23 -0
  52. data/lib/respect/utc_time_schema.rb +17 -0
  53. data/lib/respect/validator.rb +51 -0
  54. data/lib/respect/version.rb +3 -0
  55. data/test/any_schema_test.rb +79 -0
  56. data/test/array_def_test.rb +113 -0
  57. data/test/array_schema_test.rb +487 -0
  58. data/test/boolean_schema_test.rb +89 -0
  59. data/test/composite_schema_test.rb +30 -0
  60. data/test/datetime_schema_test.rb +83 -0
  61. data/test/doc_helper_test.rb +34 -0
  62. data/test/doc_parser_test.rb +109 -0
  63. data/test/dsl_dumper_test.rb +395 -0
  64. data/test/fake_name_proxy_test.rb +138 -0
  65. data/test/float_schema_test.rb +146 -0
  66. data/test/format_validator_test.rb +224 -0
  67. data/test/hash_def_test.rb +126 -0
  68. data/test/hash_schema_test.rb +613 -0
  69. data/test/integer_schema_test.rb +142 -0
  70. data/test/ip_addr_schema_test.rb +78 -0
  71. data/test/ipv4_addr_schema_test.rb +71 -0
  72. data/test/ipv6_addr_schema_test.rb +71 -0
  73. data/test/json_schema_html_formatter_test.rb +214 -0
  74. data/test/null_schema_test.rb +46 -0
  75. data/test/numeric_schema_test.rb +294 -0
  76. data/test/org3_dumper_test.rb +784 -0
  77. data/test/regexp_schema_test.rb +54 -0
  78. data/test/respect_test.rb +108 -0
  79. data/test/schema_def_test.rb +405 -0
  80. data/test/schema_test.rb +290 -0
  81. data/test/string_schema_test.rb +209 -0
  82. data/test/support/circle.rb +11 -0
  83. data/test/support/color.rb +24 -0
  84. data/test/support/point.rb +11 -0
  85. data/test/support/respect/circle_schema.rb +16 -0
  86. data/test/support/respect/color_def.rb +19 -0
  87. data/test/support/respect/color_schema.rb +33 -0
  88. data/test/support/respect/point_schema.rb +19 -0
  89. data/test/support/respect/rgba_schema.rb +20 -0
  90. data/test/support/respect/universal_validator.rb +25 -0
  91. data/test/support/respect/user_macros.rb +12 -0
  92. data/test/support/rgba.rb +11 -0
  93. data/test/test_helper.rb +90 -0
  94. data/test/uri_schema_test.rb +54 -0
  95. data/test/utc_time_schema_test.rb +63 -0
  96. data/test/validator_test.rb +22 -0
  97. metadata +288 -0
@@ -0,0 +1,138 @@
1
+ require "test_helper"
2
+
3
+ class FakeNameProxyTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @def_class = Class.new(Respect::GlobalDef) do
7
+ include Respect::CoreStatements
8
+ def accept_name(name)
9
+ name
10
+ end
11
+ def do_not_accept_name(arg1)
12
+ arg1
13
+ end
14
+ def method_missing(symbol, *args, &block)
15
+ [symbol, args, block]
16
+ end
17
+ def respond_to_missing?(symbol, include_all)
18
+ symbol == :dynamic_method
19
+ end
20
+ end
21
+ @def_target = @def_class.new
22
+ @evaluator = Respect::FakeNameProxy.new(@def_target)
23
+
24
+ @def_class_no_name = @def_class.clone
25
+ @def_class_no_name.send(:include, Respect::DefWithoutName)
26
+ @def_target_no_name = @def_class_no_name.new
27
+ @evaluator_no_name = Respect::FakeNameProxy.new(@def_target_no_name)
28
+ end
29
+
30
+ def test_consider_name_as_accepted_by_default
31
+ assert(!@evaluator.__send__(:should_fake_name?))
32
+ assert(@evaluator_no_name.__send__(:should_fake_name?))
33
+ end
34
+
35
+ def test_access_to_target
36
+ assert(@def_target == @evaluator.target)
37
+ assert(@def_class == @evaluator.target.class)
38
+ @evaluator.eval do |e|
39
+ assert(e == @evaluator)
40
+ assert(e.target == @def_target)
41
+ assert(e.target.class == @def_class)
42
+ end
43
+ end
44
+
45
+ def test_nil_inserted_as_fake_name
46
+ @evaluator_no_name.eval do |e|
47
+ assert_nil e.accept_name
48
+ assert_raise(ArgumentError) do
49
+ e.accept_name "extra arg"
50
+ end
51
+ assert_raise(ArgumentError) do
52
+ e.do_not_accept_name
53
+ end
54
+ assert_equal("arg1", e.do_not_accept_name("arg1"))
55
+ end
56
+ end
57
+
58
+ def test_nothing_inserted_as_fake_name
59
+ @evaluator.eval do |e|
60
+ assert_equal("name", e.accept_name("name"))
61
+ assert_raise(ArgumentError) do
62
+ e.accept_name
63
+ end
64
+ assert_raise(ArgumentError) do
65
+ e.accept_name "name", "extra arg"
66
+ end
67
+ assert_raise(ArgumentError) do
68
+ e.do_not_accept_name
69
+ end
70
+ assert_equal("arg1", e.do_not_accept_name("arg1"))
71
+ assert_raise(ArgumentError) do
72
+ e.do_not_accept_name "arg1", "extra arg"
73
+ end
74
+ end
75
+ end
76
+
77
+ def test_rewrite_argument_error_message_values
78
+ @evaluator_no_name.eval do |e|
79
+ assert_argument_error_number(1, 0) do
80
+ e.accept_name "extra arg"
81
+ end
82
+ assert_argument_error_number(0, 1) do
83
+ e.do_not_accept_name
84
+ end
85
+ end
86
+ end
87
+
88
+ def test_block_must_take_one_arg
89
+ assert_nothing_raised do
90
+ s = Respect::FakeNameProxy.new(@def_target).eval do |s, a|
91
+ end
92
+ end
93
+ assert_nothing_raised do
94
+ s = Respect::FakeNameProxy.new(@def_target).eval do
95
+ end
96
+ end
97
+ end
98
+
99
+ def test_handle_target_dynamic_method
100
+ # If the target accepts name, all arguments are always passed unchanged.
101
+ @evaluator.eval do |e|
102
+ assert_equal [:dynamic_method, [], nil], e.dynamic_method
103
+ assert_equal [:dynamic_method, [1, 2], nil], e.dynamic_method(1, 2)
104
+ assert_equal [:dynamic_method, [1, 2, 3], nil], e.dynamic_method(1, 2, 3)
105
+ end
106
+ # If the target does not accepts name, a fake name is always passed (we do not test whether the first
107
+ # parameters is a name since we do not have access to the parameters list).
108
+ @evaluator_no_name.eval do |e|
109
+ assert_equal [:dynamic_method, [nil], nil], e.dynamic_method
110
+ assert_equal [:dynamic_method, [nil, 1, 2], nil], e.dynamic_method(1, 2)
111
+ assert_equal [:dynamic_method, [nil, 1, 2, 3], nil], e.dynamic_method(1, 2, 3)
112
+ end
113
+ end
114
+
115
+ def test_can_access_target_ancestors_methods
116
+ @evaluator.eval do |e|
117
+ assert(e.target.class == e.class, "call to Object method")
118
+ assert(e.send(:String, :foo) == e.target.send(:String, :foo), "call to Kernel method")
119
+ end
120
+ end
121
+
122
+ def test_self_does_not_change_in_block
123
+ @evaluator.eval do
124
+ assert_kind_of(FakeNameProxyTest, self)
125
+ end
126
+ end
127
+
128
+ private
129
+
130
+ def assert_argument_error_number(actual, expected, &block)
131
+ begin
132
+ block.call
133
+ assert false
134
+ rescue ArgumentError => err
135
+ assert_match(/\(#{actual} for #{expected}\)/, err.message)
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,146 @@
1
+ require "test_helper"
2
+
3
+ class FloatSchemaTest < Test::Unit::TestCase
4
+ def test_expected_value_are_not_converted
5
+ s = Respect::FloatSchema.new(equal_to: "42.5")
6
+ assert_raise(Respect::ValidationError) do
7
+ s.validate(42.5)
8
+ end
9
+ end
10
+
11
+ def test_malformed_string_value_raise_exception
12
+ s = Respect::FloatSchema.new
13
+ [
14
+ "s42.5",
15
+ "4s2.5",
16
+ "42.5s",
17
+ "4-2.5",
18
+ "42.5-",
19
+ "-+42.5",
20
+ "+-42.5",
21
+ ].each do |test_value|
22
+ assert_raise(Respect::ValidationError) do
23
+ s.validate_type(test_value)
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_string_value_get_converted
29
+ [
30
+ [ "-42.5", -42.5 ],
31
+ [ "+42.54", 42.54 ],
32
+ [ "42.123", 42.123 ],
33
+ ].each do |test_data|
34
+ s = Respect::FloatSchema.new
35
+ assert_equal test_data[1], s.validate_type(test_data[0])
36
+ assert_nil s.sanitized_object
37
+ s.validate(test_data[0])
38
+ assert_equal test_data[1], s.sanitized_object
39
+ end
40
+ end
41
+
42
+ def test_greater_than_constraint_works
43
+ s = Respect::FloatSchema.new(greater_than: 0)
44
+ assert s.validate(42.5)
45
+ [ 0.0, -42.5 ].each do |test_value|
46
+ assert_raise(Respect::ValidationError) do
47
+ s.validate(test_value)
48
+ end
49
+ end
50
+ end
51
+
52
+ def test_greater_than_or_equal_to_constraint_works
53
+ s = Respect::FloatSchema.new(greater_than_or_equal_to: 0)
54
+ assert s.validate(42.5)
55
+ assert s.validate(0.0)
56
+ assert_raise(Respect::ValidationError) do
57
+ s.validate(-42.5)
58
+ end
59
+ end
60
+
61
+ def test_less_than_constraint_works
62
+ s = Respect::FloatSchema.new(less_than: 0)
63
+ assert s.validate(-1.5)
64
+ [ 0.0, 1.5 ].each do |test_value|
65
+ assert_raise(Respect::ValidationError) do
66
+ s.validate(test_value)
67
+ end
68
+ end
69
+ end
70
+
71
+ def test_less_than_or_equal_to_constraint_works
72
+ s = Respect::FloatSchema.new(less_than_or_equal_to: 0)
73
+ assert s.validate(-1.5)
74
+ assert s.validate(0.0)
75
+ assert_raise(Respect::ValidationError) do
76
+ s.validate(1.5)
77
+ end
78
+ end
79
+
80
+ def test_float_value_is_in_set
81
+ s = Respect::FloatSchema.new(in: [42.5, 51.5])
82
+ assert_schema_validate s, 42.5
83
+ assert_schema_validate s, 51.5
84
+ assert_schema_invalidate s, 1664.5
85
+ end
86
+
87
+ def test_float_value_is_in_range
88
+ s = Respect::FloatSchema.new(in: 1.5..4.5)
89
+ assert_schema_invalidate s, 0.0
90
+ assert_schema_invalidate s, 1.4
91
+ assert_schema_validate s, 1.5
92
+ assert_schema_validate s, 2.0
93
+ assert_schema_validate s, 3.0
94
+ assert_schema_validate s, 4.0
95
+ assert_schema_validate s, 4.5
96
+ assert_schema_invalidate s, 4.6
97
+ assert_schema_invalidate s, 5.0
98
+
99
+ s = Respect::FloatSchema.new(in: 1.5...4.5)
100
+ assert_schema_invalidate s, 0.0
101
+ assert_schema_invalidate s, 1.4
102
+ assert_schema_validate s, 1.5
103
+ assert_schema_validate s, 2.0
104
+ assert_schema_validate s, 3.0
105
+ assert_schema_validate s, 4.0
106
+ assert_schema_invalidate s, 4.5
107
+ assert_schema_invalidate s, 4.6
108
+ assert_schema_invalidate s, 5.0
109
+ end
110
+
111
+ def test_float_accept_equal_to_constraint
112
+ s = Respect::FloatSchema.new(equal_to: 41.5)
113
+ assert_schema_validate s, 41.5
114
+ assert_schema_invalidate s, 41.55
115
+ end
116
+
117
+ def test_failed_validation_reset_sanitized_object
118
+ s = Respect::FloatSchema.new equal_to: 42.5
119
+ assert_schema_validate(s, 42.5)
120
+ assert_equal(42.5, s.sanitized_object)
121
+ assert_schema_invalidate(s, "wrong")
122
+ assert_equal(nil, s.sanitized_object)
123
+ end
124
+
125
+ def test_allow_nil
126
+ s = Respect::FloatSchema.new(allow_nil: true)
127
+ assert_schema_validate s, nil
128
+ assert_equal(nil, s.sanitized_object)
129
+ assert_schema_validate s, 42.5
130
+ assert_equal(42.5, s.sanitized_object)
131
+ assert_schema_validate s, "42.5"
132
+ assert_equal(42.5, s.sanitized_object)
133
+ end
134
+
135
+ def test_disallow_nil
136
+ s = Respect::FloatSchema.new
137
+ assert !s.allow_nil?
138
+ exception = assert_exception(Respect::ValidationError) { s.validate(nil) }
139
+ assert_match exception.message, /\bFloatSchema\b/
140
+ assert_equal(nil, s.sanitized_object)
141
+ assert_schema_validate s, 42.5
142
+ assert_equal(42.5, s.sanitized_object)
143
+ assert_schema_validate s, "42.5"
144
+ assert_equal(42.5, s.sanitized_object)
145
+ end
146
+ end
@@ -0,0 +1,224 @@
1
+ require "test_helper"
2
+
3
+ class FormatValidatorTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @valid_ipv4_addr = [
7
+ "0.0.0.0",
8
+ "255.255.255.255",
9
+ "1.1.1.1",
10
+ "11.1.1.1",
11
+ "11.1.1.1",
12
+ "1.1.1.1",
13
+ "1.11.1.1",
14
+ "1.111.1.1",
15
+ "1.1.1.1",
16
+ "1.1.11.1",
17
+ "1.1.111.1",
18
+ "1.1.1.1",
19
+ "1.1.1.11",
20
+ "1.1.1.111",
21
+ ]
22
+ @invalid_ipv4_addr = [
23
+ "a1.1.1.1",
24
+ "1.1.1.1b",
25
+ "260.0.0.0",
26
+ "0.260.0.0",
27
+ "0.0.260.0",
28
+ "0.0.0.260",
29
+ "0.0.0.0.0",
30
+ ]
31
+ @valid_ipv6_addr = [
32
+ "1080:0:0:0:8:800:200C:417A",
33
+ "FF01:0:0:0:0:0:0:101",
34
+ "0:0:0:0:0:0:0:1",
35
+ "0:0:0:0:0:0:0:0",
36
+ ]
37
+ @invalid_ipv6_addr = [
38
+ "z1080:0:0:0:8:800:200C:417A",
39
+ "FF01:0:0:0:0:0:0:101z",
40
+ "0:0:0:0",
41
+ "0:0:0:0:0:0:11111:0",
42
+ ]
43
+ end
44
+
45
+ def test_ipv4_addr_validator
46
+ # Valid IPv4 sample data.
47
+ @valid_ipv4_addr.each_with_index do |test_data, i|
48
+ assert_nothing_raised("validate #{i}") do
49
+ Respect::FormatValidator.new(:ipv4_addr).validate(test_data)
50
+ end
51
+ end
52
+ # Invalid IPv4 sample data.
53
+ @invalid_ipv4_addr.each_with_index do |test_data, i|
54
+ assert_raises(Respect::ValidationError, "validate #{i}") do
55
+ Respect::FormatValidator.new(:ipv4_addr).validate(test_data)
56
+ end
57
+ end
58
+ end
59
+
60
+ def test_ipv4_addr_say_is_not_ipv4
61
+ begin
62
+ Respect::FormatValidator.new(:ipv4_addr).validate("0.333.0.0")
63
+ assert false, "nothing raised"
64
+ rescue Respect::ValidationError => e
65
+ assert_match(/\bIPv4\b/, e.message)
66
+ assert_match(/\b0.333.0.0\b/, e.message)
67
+ end
68
+ end
69
+
70
+ def test_ipv4_addr_mention_wrong_value_in_error
71
+ begin
72
+ Respect::FormatValidator.new(:ipv4_addr).validate("invalid")
73
+ assert false, "nothing raised"
74
+ rescue Respect::ValidationError => e
75
+ assert_match(/\binvalid\b/, e.message)
76
+ end
77
+ end
78
+
79
+ def test_phone_number_validator
80
+ # Valid phone number sample data.
81
+ [
82
+ "+112",
83
+ "00112",
84
+ "+1212",
85
+ "001212",
86
+ "1",
87
+ "123456789",
88
+ ].each_with_index do |test_data, i|
89
+ assert_nothing_raised("validate #{i}") do
90
+ Respect::FormatValidator.new(:phone_number).validate(test_data)
91
+ end
92
+ end
93
+ # Invalid phone number sample data.
94
+ [
95
+ "-112",
96
+ "00112a",
97
+ "a+1212",
98
+ "00d1212",
99
+ "1-",
100
+ "12 34 56 78 9",
101
+ ].each_with_index do |test_data, i|
102
+ assert_raises(Respect::ValidationError, "validate #{i}") do
103
+ Respect::FormatValidator.new(:phone_number).validate(test_data)
104
+ end
105
+ end
106
+ end
107
+
108
+ def test_phone_number_mention_wrong_value_in_error
109
+ begin
110
+ Respect::FormatValidator.new(:phone_number).validate("invalid00phone00number")
111
+ assert false, "nothing raised"
112
+ rescue Respect::ValidationError => e
113
+ assert_match(/\binvalid00phone00number\b/, e.message)
114
+ end
115
+ end
116
+
117
+ def test_ipv6_addr_validator
118
+ # Valid IPv6 sample data.
119
+ @valid_ipv6_addr.each_with_index do |test_data, i|
120
+ assert_nothing_raised("validate #{i}") do
121
+ Respect::FormatValidator.new(:ipv6_addr).validate(test_data)
122
+ end
123
+ end
124
+ # Invalid IPV6 sample data.
125
+ @invalid_ipv6_addr.each_with_index do |test_data, i|
126
+ assert_raises(Respect::ValidationError, "validate #{i}") do
127
+ Respect::FormatValidator.new(:ipv6_addr).validate(test_data)
128
+ end
129
+ end
130
+ end
131
+
132
+ def test_ipv6_addr_say_it_is_not_ipv6
133
+ begin
134
+ Respect::FormatValidator.new(:ipv6_addr).validate("0.333.0.0")
135
+ assert false, "nothing raised"
136
+ rescue Respect::ValidationError => e
137
+ assert_match(/\bIPv6\b/, e.message)
138
+ assert_match(/\b0.333.0.0\b/, e.message)
139
+ end
140
+ end
141
+
142
+ def test_ipv6_addr_mention_wrong_value_in_error
143
+ begin
144
+ Respect::FormatValidator.new(:ipv6_addr).validate("invalid_ipaddr")
145
+ assert false, "nothing raised"
146
+ rescue Respect::ValidationError => e
147
+ assert_match(/\binvalid_ipaddr\b/, e.message)
148
+ end
149
+ end
150
+
151
+ def test_ip_addr_validator
152
+ # Valid IP sample data.
153
+ (@valid_ipv4_addr + @valid_ipv6_addr).each_with_index do |test_data, i|
154
+ assert_nothing_raised("validate #{i}") do
155
+ Respect::FormatValidator.new(:ip_addr).validate(test_data)
156
+ end
157
+ end
158
+ # Invalid IP sample data.
159
+ (@invalid_ipv4_addr + @invalid_ipv6_addr).each_with_index do |test_data, i|
160
+ assert_raises(Respect::ValidationError, "validate #{i}") do
161
+ Respect::FormatValidator.new(:ip_addr).validate(test_data)
162
+ end
163
+ end
164
+ end
165
+
166
+ def test_ip_mention_wrong_value_in_error
167
+ begin
168
+ Respect::FormatValidator.new(:ip_addr).validate("invalid_ipaddr")
169
+ assert false, "nothing raised"
170
+ rescue Respect::ValidationError => e
171
+ assert_match(/\binvalid_ipaddr\b/, e.message)
172
+ end
173
+ end
174
+
175
+ def test_hostname_addr_validator
176
+ # Valid hostname sample data.
177
+ [
178
+ "a.b.c.d",
179
+ "aa.bb.cc.dd",
180
+ "aaa.bbb.ccc.ddd",
181
+ "a",
182
+ "abcdefghijklmnopqrstuvwxyz-0123456789",
183
+ "abcdefghijklmnopqrstuvwxyz-0123456789.abcdefghijklmnopqrstuvwxyz-0123456789",
184
+ "A.B.C.D",
185
+ ].each_with_index do |test_data, i|
186
+ assert_nothing_raised("validate #{i}") do
187
+ Respect::FormatValidator.new(:hostname).validate(test_data)
188
+ end
189
+ end
190
+ # Invalid hostname sample data.
191
+ [
192
+ "-a.b.c.d",
193
+ "1a.b.c.d",
194
+ "a_b",
195
+ ].each_with_index do |test_data, i|
196
+ assert_raises(Respect::ValidationError, "validate #{i}") do
197
+ Respect::FormatValidator.new(:hostname).validate(test_data)
198
+ end
199
+ end
200
+ end
201
+
202
+ def test_hostname_say_which_part_is_wrong
203
+ begin
204
+ invalid_part = "b" * 100
205
+ invalid_hostname = "a.#{invalid_part}.c.d"
206
+ Respect::FormatValidator.new(:hostname).validate(invalid_hostname)
207
+ assert false, "nothing raised"
208
+ rescue Respect::ValidationError => e
209
+ assert_match(/\b#{invalid_part}\b/, e.message)
210
+ assert_match(/\b1st\b/, e.message)
211
+ assert_match(/\b#{invalid_hostname}\b/, e.message)
212
+ end
213
+ end
214
+
215
+ def test_ipv4_addr_mention_wrong_value_in_error
216
+ begin
217
+ Respect::FormatValidator.new(:ipv4_addr).validate("invalid_hostname")
218
+ assert false, "nothing raised"
219
+ rescue Respect::ValidationError => e
220
+ assert_match(/\binvalid_hostname\b/, e.message)
221
+ end
222
+ end
223
+
224
+ end