hash_validator 2.0.0 → 2.0.1

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +6 -1
  3. data/.rubocop.yml +340 -0
  4. data/Gemfile +3 -1
  5. data/README.md +2 -1
  6. data/Rakefile +6 -4
  7. data/hash_validator.gemspec +11 -5
  8. data/lib/hash_validator/base.rb +2 -0
  9. data/lib/hash_validator/configuration.rb +5 -3
  10. data/lib/hash_validator/validations/many.rb +2 -0
  11. data/lib/hash_validator/validations/multiple.rb +2 -0
  12. data/lib/hash_validator/validations/optional.rb +2 -0
  13. data/lib/hash_validator/validations.rb +5 -3
  14. data/lib/hash_validator/validators/alpha_validator.rb +5 -3
  15. data/lib/hash_validator/validators/alphanumeric_validator.rb +5 -3
  16. data/lib/hash_validator/validators/array_validator.rb +44 -48
  17. data/lib/hash_validator/validators/base.rb +6 -4
  18. data/lib/hash_validator/validators/boolean_validator.rb +3 -1
  19. data/lib/hash_validator/validators/class_validator.rb +3 -1
  20. data/lib/hash_validator/validators/digits_validator.rb +5 -3
  21. data/lib/hash_validator/validators/dynamic_func_validator.rb +8 -8
  22. data/lib/hash_validator/validators/dynamic_pattern_validator.rb +5 -3
  23. data/lib/hash_validator/validators/email_validator.rb +4 -2
  24. data/lib/hash_validator/validators/enumerable_validator.rb +4 -2
  25. data/lib/hash_validator/validators/hash_validator.rb +5 -3
  26. data/lib/hash_validator/validators/hex_color_validator.rb +5 -3
  27. data/lib/hash_validator/validators/ip_validator.rb +6 -4
  28. data/lib/hash_validator/validators/ipv4_validator.rb +5 -3
  29. data/lib/hash_validator/validators/ipv6_validator.rb +6 -4
  30. data/lib/hash_validator/validators/json_validator.rb +6 -4
  31. data/lib/hash_validator/validators/lambda_validator.rb +4 -2
  32. data/lib/hash_validator/validators/many_validator.rb +3 -1
  33. data/lib/hash_validator/validators/multiple_validator.rb +4 -2
  34. data/lib/hash_validator/validators/optional_validator.rb +3 -1
  35. data/lib/hash_validator/validators/presence_validator.rb +4 -2
  36. data/lib/hash_validator/validators/regex_validator.rb +4 -2
  37. data/lib/hash_validator/validators/simple_type_validators.rb +3 -1
  38. data/lib/hash_validator/validators/simple_validator.rb +2 -0
  39. data/lib/hash_validator/validators/url_validator.rb +6 -4
  40. data/lib/hash_validator/validators.rb +35 -33
  41. data/lib/hash_validator/version.rb +3 -1
  42. data/lib/hash_validator.rb +7 -5
  43. data/spec/configuration_spec.rb +76 -74
  44. data/spec/hash_validator_spec.rb +132 -113
  45. data/spec/hash_validator_spec_helper.rb +2 -0
  46. data/spec/spec_helper.rb +14 -4
  47. data/spec/validators/alpha_validator_spec.rb +43 -41
  48. data/spec/validators/alphanumeric_validator_spec.rb +44 -42
  49. data/spec/validators/array_spec.rb +102 -47
  50. data/spec/validators/base_spec.rb +25 -10
  51. data/spec/validators/boolean_spec.rb +15 -13
  52. data/spec/validators/class_spec.rb +20 -18
  53. data/spec/validators/digits_validator_spec.rb +46 -44
  54. data/spec/validators/dynamic_func_validator_spec.rb +90 -88
  55. data/spec/validators/dynamic_pattern_validator_spec.rb +65 -63
  56. data/spec/validators/email_spec.rb +15 -13
  57. data/spec/validators/hash_validator_spec.rb +39 -37
  58. data/spec/validators/hex_color_validator_spec.rb +49 -47
  59. data/spec/validators/in_enumerable_spec.rb +32 -30
  60. data/spec/validators/ip_validator_spec.rb +46 -44
  61. data/spec/validators/ipv4_validator_spec.rb +45 -43
  62. data/spec/validators/ipv6_validator_spec.rb +44 -42
  63. data/spec/validators/json_validator_spec.rb +38 -36
  64. data/spec/validators/lambda_spec.rb +20 -18
  65. data/spec/validators/many_spec.rb +25 -23
  66. data/spec/validators/multiple_spec.rb +13 -11
  67. data/spec/validators/optional_spec.rb +22 -20
  68. data/spec/validators/presence_spec.rb +16 -14
  69. data/spec/validators/regexp_spec.rb +14 -12
  70. data/spec/validators/simple_spec.rb +17 -15
  71. data/spec/validators/simple_types_spec.rb +21 -19
  72. data/spec/validators/url_validator_spec.rb +34 -32
  73. data/spec/validators/user_defined_spec.rb +29 -27
  74. metadata +59 -2
@@ -1,67 +1,69 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Enumerable validator' do
4
- describe 'Accepting Enumerables in validations' do
5
- it 'should accept an empty array' do
3
+ require "spec_helper"
4
+
5
+ describe "Enumerable validator" do
6
+ describe "Accepting Enumerables in validations" do
7
+ it "should accept an empty array" do
6
8
  validate({}, { foo: [] })
7
9
  end
8
10
 
9
- it 'should accept an array' do
10
- validate({}, { foo: [ 'apple', 'banana', 'carrot' ] })
11
+ it "should accept an array" do
12
+ validate({}, { foo: [ "apple", "banana", "carrot" ] })
11
13
  end
12
14
 
13
- it 'should accept a hash' do
14
- validate({}, { foo: { apple: 'apple', banana: 'banana', carrot: 'cattot' } })
15
+ it "should accept a hash" do
16
+ validate({}, { foo: { apple: "apple", banana: "banana", carrot: "cattot" } })
15
17
  end
16
18
  end
17
19
 
18
- describe '#validate' do
19
- describe 'Simple Array' do
20
- let(:validations) {{ fruit: [ 'apple', 'banana', 'carrot' ] }}
20
+ describe "#validate" do
21
+ describe "Simple Array" do
22
+ let(:validations) { { fruit: [ "apple", "banana", "carrot" ] } }
21
23
 
22
- it 'should validate true if the value is present' do
23
- expect(validate({ fruit: 'apple' }, validations).valid?).to eq true
24
+ it "should validate true if the value is present" do
25
+ expect(validate({ fruit: "apple" }, validations).valid?).to eq true
24
26
  end
25
27
 
26
- it 'should validate false if the value is not present' do
27
- expect(validate({ fruit: 'pear' }, validations).valid?).to eq false
28
+ it "should validate false if the value is not present" do
29
+ expect(validate({ fruit: "pear" }, validations).valid?).to eq false
28
30
  end
29
31
 
30
- it 'should validate false if the key is not present' do
31
- expect(validate({ something: 'apple' }, validations).valid?).to eq false
32
+ it "should validate false if the key is not present" do
33
+ expect(validate({ something: "apple" }, validations).valid?).to eq false
32
34
  end
33
35
 
34
- it 'should provide an appropriate error message is the value is not present' do
35
- expect(validate({ fruit: 'pear' }, validations).errors).to eq({ fruit: 'value from list required' })
36
+ it "should provide an appropriate error message is the value is not present" do
37
+ expect(validate({ fruit: "pear" }, validations).errors).to eq({ fruit: "value from list required" })
36
38
  end
37
39
  end
38
40
 
39
- describe 'Range' do
40
- let(:validations) {{ number: 1..10 }}
41
+ describe "Range" do
42
+ let(:validations) { { number: 1..10 } }
41
43
 
42
- it 'should validate true if the value is present' do
44
+ it "should validate true if the value is present" do
43
45
  expect(validate({ number: 5 }, validations).valid?).to eq true
44
46
  end
45
- it 'should validate false if the value is not present' do
47
+ it "should validate false if the value is not present" do
46
48
  expect(validate({ number: 15 }, validations).valid?).to eq false
47
49
  end
48
50
  end
49
51
 
50
- describe 'Infinite Range' do
51
- let(:validations) {{ number: 1..Float::INFINITY }}
52
+ describe "Infinite Range" do
53
+ let(:validations) { { number: 1..Float::INFINITY } }
52
54
 
53
- it 'should validate true if the value is present' do
55
+ it "should validate true if the value is present" do
54
56
  expect(validate({ number: 5 }, validations).valid?).to eq true
55
57
  end
56
- it 'should validate false if the value is not present' do
58
+ it "should validate false if the value is not present" do
57
59
  expect(validate({ number: -5 }, validations).valid?).to eq false
58
60
  end
59
61
  end
60
62
 
61
- describe 'nil values' do
62
- let(:validations) {{ fruit: [ nil, :apple, :banana ] }}
63
+ describe "nil values" do
64
+ let(:validations) { { fruit: [ nil, :apple, :banana ] } }
63
65
 
64
- it 'should validate true if a nil value is present' do
66
+ it "should validate true if a nil value is present" do
65
67
  expect(validate({ fruit: nil }, validations).valid?).to eq true
66
68
  end
67
69
  end
@@ -1,105 +1,107 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe HashValidator::Validator::IpValidator do
4
6
  let(:validator) { HashValidator::Validator::IpValidator.new }
5
7
 
6
- context 'valid IP addresses' do
7
- it 'validates IPv4 addresses' do
8
+ context "valid IP addresses" do
9
+ it "validates IPv4 addresses" do
8
10
  errors = {}
9
- validator.validate('key', '192.168.1.1', {}, errors)
11
+ validator.validate("key", "192.168.1.1", {}, errors)
10
12
  expect(errors).to be_empty
11
13
  end
12
14
 
13
- it 'validates IPv4 localhost' do
15
+ it "validates IPv4 localhost" do
14
16
  errors = {}
15
- validator.validate('key', '127.0.0.1', {}, errors)
17
+ validator.validate("key", "127.0.0.1", {}, errors)
16
18
  expect(errors).to be_empty
17
19
  end
18
20
 
19
- it 'validates IPv4 zero address' do
21
+ it "validates IPv4 zero address" do
20
22
  errors = {}
21
- validator.validate('key', '0.0.0.0', {}, errors)
23
+ validator.validate("key", "0.0.0.0", {}, errors)
22
24
  expect(errors).to be_empty
23
25
  end
24
26
 
25
- it 'validates IPv4 broadcast address' do
27
+ it "validates IPv4 broadcast address" do
26
28
  errors = {}
27
- validator.validate('key', '255.255.255.255', {}, errors)
29
+ validator.validate("key", "255.255.255.255", {}, errors)
28
30
  expect(errors).to be_empty
29
31
  end
30
32
 
31
- it 'validates IPv6 addresses' do
33
+ it "validates IPv6 addresses" do
32
34
  errors = {}
33
- validator.validate('key', '2001:db8:85a3::8a2e:370:7334', {}, errors)
35
+ validator.validate("key", "2001:db8:85a3::8a2e:370:7334", {}, errors)
34
36
  expect(errors).to be_empty
35
37
  end
36
38
 
37
- it 'validates IPv6 localhost' do
39
+ it "validates IPv6 localhost" do
38
40
  errors = {}
39
- validator.validate('key', '::1', {}, errors)
41
+ validator.validate("key", "::1", {}, errors)
40
42
  expect(errors).to be_empty
41
43
  end
42
44
 
43
- it 'validates IPv6 zero address' do
45
+ it "validates IPv6 zero address" do
44
46
  errors = {}
45
- validator.validate('key', '::', {}, errors)
47
+ validator.validate("key", "::", {}, errors)
46
48
  expect(errors).to be_empty
47
49
  end
48
50
 
49
- it 'validates IPv4-mapped IPv6 addresses' do
51
+ it "validates IPv4-mapped IPv6 addresses" do
50
52
  errors = {}
51
- validator.validate('key', '::ffff:192.168.1.1', {}, errors)
53
+ validator.validate("key", "::ffff:192.168.1.1", {}, errors)
52
54
  expect(errors).to be_empty
53
55
  end
54
56
  end
55
57
 
56
- context 'invalid IP addresses' do
57
- it 'rejects non-string values' do
58
+ context "invalid IP addresses" do
59
+ it "rejects non-string values" do
58
60
  errors = {}
59
- validator.validate('key', 123, {}, errors)
60
- expect(errors['key']).to eq('is not a valid IP address')
61
+ validator.validate("key", 123, {}, errors)
62
+ expect(errors["key"]).to eq("is not a valid IP address")
61
63
  end
62
64
 
63
- it 'rejects nil values' do
65
+ it "rejects nil values" do
64
66
  errors = {}
65
- validator.validate('key', nil, {}, errors)
66
- expect(errors['key']).to eq('is not a valid IP address')
67
+ validator.validate("key", nil, {}, errors)
68
+ expect(errors["key"]).to eq("is not a valid IP address")
67
69
  end
68
70
 
69
- it 'rejects malformed IPv4 addresses' do
71
+ it "rejects malformed IPv4 addresses" do
70
72
  errors = {}
71
- validator.validate('key', '256.1.1.1', {}, errors)
72
- expect(errors['key']).to eq('is not a valid IP address')
73
+ validator.validate("key", "256.1.1.1", {}, errors)
74
+ expect(errors["key"]).to eq("is not a valid IP address")
73
75
  end
74
76
 
75
- it 'rejects malformed IPv6 addresses' do
77
+ it "rejects malformed IPv6 addresses" do
76
78
  errors = {}
77
- validator.validate('key', '2001:db8:85a3::8a2e::7334', {}, errors)
78
- expect(errors['key']).to eq('is not a valid IP address')
79
+ validator.validate("key", "2001:db8:85a3::8a2e::7334", {}, errors)
80
+ expect(errors["key"]).to eq("is not a valid IP address")
79
81
  end
80
82
 
81
- it 'rejects non-IP strings' do
83
+ it "rejects non-IP strings" do
82
84
  errors = {}
83
- validator.validate('key', 'not an ip', {}, errors)
84
- expect(errors['key']).to eq('is not a valid IP address')
85
+ validator.validate("key", "not an ip", {}, errors)
86
+ expect(errors["key"]).to eq("is not a valid IP address")
85
87
  end
86
88
 
87
- it 'rejects empty strings' do
89
+ it "rejects empty strings" do
88
90
  errors = {}
89
- validator.validate('key', '', {}, errors)
90
- expect(errors['key']).to eq('is not a valid IP address')
91
+ validator.validate("key", "", {}, errors)
92
+ expect(errors["key"]).to eq("is not a valid IP address")
91
93
  end
92
94
 
93
- it 'rejects hostnames' do
95
+ it "rejects hostnames" do
94
96
  errors = {}
95
- validator.validate('key', 'example.com', {}, errors)
96
- expect(errors['key']).to eq('is not a valid IP address')
97
+ validator.validate("key", "example.com", {}, errors)
98
+ expect(errors["key"]).to eq("is not a valid IP address")
97
99
  end
98
100
 
99
- it 'rejects URLs' do
101
+ it "rejects URLs" do
100
102
  errors = {}
101
- validator.validate('key', 'http://192.168.1.1', {}, errors)
102
- expect(errors['key']).to eq('is not a valid IP address')
103
+ validator.validate("key", "http://192.168.1.1", {}, errors)
104
+ expect(errors["key"]).to eq("is not a valid IP address")
103
105
  end
104
106
  end
105
- end
107
+ end
@@ -1,99 +1,101 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe HashValidator::Validator::Ipv4Validator do
4
6
  let(:validator) { HashValidator::Validator::Ipv4Validator.new }
5
7
 
6
- context 'valid IPv4 addresses' do
7
- it 'validates standard IPv4 addresses' do
8
+ context "valid IPv4 addresses" do
9
+ it "validates standard IPv4 addresses" do
8
10
  errors = {}
9
- validator.validate('key', '192.168.1.1', {}, errors)
11
+ validator.validate("key", "192.168.1.1", {}, errors)
10
12
  expect(errors).to be_empty
11
13
  end
12
14
 
13
- it 'validates localhost' do
15
+ it "validates localhost" do
14
16
  errors = {}
15
- validator.validate('key', '127.0.0.1', {}, errors)
17
+ validator.validate("key", "127.0.0.1", {}, errors)
16
18
  expect(errors).to be_empty
17
19
  end
18
20
 
19
- it 'validates zero address' do
21
+ it "validates zero address" do
20
22
  errors = {}
21
- validator.validate('key', '0.0.0.0', {}, errors)
23
+ validator.validate("key", "0.0.0.0", {}, errors)
22
24
  expect(errors).to be_empty
23
25
  end
24
26
 
25
- it 'validates broadcast address' do
27
+ it "validates broadcast address" do
26
28
  errors = {}
27
- validator.validate('key', '255.255.255.255', {}, errors)
29
+ validator.validate("key", "255.255.255.255", {}, errors)
28
30
  expect(errors).to be_empty
29
31
  end
30
32
 
31
- it 'validates private network addresses' do
33
+ it "validates private network addresses" do
32
34
  errors = {}
33
- validator.validate('key', '10.0.0.1', {}, errors)
35
+ validator.validate("key", "10.0.0.1", {}, errors)
34
36
  expect(errors).to be_empty
35
37
  end
36
38
 
37
- it 'validates Class B private addresses' do
39
+ it "validates Class B private addresses" do
38
40
  errors = {}
39
- validator.validate('key', '172.16.0.1', {}, errors)
41
+ validator.validate("key", "172.16.0.1", {}, errors)
40
42
  expect(errors).to be_empty
41
43
  end
42
44
  end
43
45
 
44
- context 'invalid IPv4 addresses' do
45
- it 'rejects non-string values' do
46
+ context "invalid IPv4 addresses" do
47
+ it "rejects non-string values" do
46
48
  errors = {}
47
- validator.validate('key', 123, {}, errors)
48
- expect(errors['key']).to eq('is not a valid IPv4 address')
49
+ validator.validate("key", 123, {}, errors)
50
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
49
51
  end
50
52
 
51
- it 'rejects nil values' do
53
+ it "rejects nil values" do
52
54
  errors = {}
53
- validator.validate('key', nil, {}, errors)
54
- expect(errors['key']).to eq('is not a valid IPv4 address')
55
+ validator.validate("key", nil, {}, errors)
56
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
55
57
  end
56
58
 
57
- it 'rejects octets over 255' do
59
+ it "rejects octets over 255" do
58
60
  errors = {}
59
- validator.validate('key', '256.1.1.1', {}, errors)
60
- expect(errors['key']).to eq('is not a valid IPv4 address')
61
+ validator.validate("key", "256.1.1.1", {}, errors)
62
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
61
63
  end
62
64
 
63
- it 'rejects too few octets' do
65
+ it "rejects too few octets" do
64
66
  errors = {}
65
- validator.validate('key', '192.168.1', {}, errors)
66
- expect(errors['key']).to eq('is not a valid IPv4 address')
67
+ validator.validate("key", "192.168.1", {}, errors)
68
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
67
69
  end
68
70
 
69
- it 'rejects too many octets' do
71
+ it "rejects too many octets" do
70
72
  errors = {}
71
- validator.validate('key', '192.168.1.1.1', {}, errors)
72
- expect(errors['key']).to eq('is not a valid IPv4 address')
73
+ validator.validate("key", "192.168.1.1.1", {}, errors)
74
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
73
75
  end
74
76
 
75
- it 'rejects IPv6 addresses' do
77
+ it "rejects IPv6 addresses" do
76
78
  errors = {}
77
- validator.validate('key', '2001:db8::1', {}, errors)
78
- expect(errors['key']).to eq('is not a valid IPv4 address')
79
+ validator.validate("key", "2001:db8::1", {}, errors)
80
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
79
81
  end
80
82
 
81
- it 'rejects malformed addresses' do
83
+ it "rejects malformed addresses" do
82
84
  errors = {}
83
- validator.validate('key', '192.168.1.', {}, errors)
84
- expect(errors['key']).to eq('is not a valid IPv4 address')
85
+ validator.validate("key", "192.168.1.", {}, errors)
86
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
85
87
  end
86
88
 
87
- it 'rejects empty strings' do
89
+ it "rejects empty strings" do
88
90
  errors = {}
89
- validator.validate('key', '', {}, errors)
90
- expect(errors['key']).to eq('is not a valid IPv4 address')
91
+ validator.validate("key", "", {}, errors)
92
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
91
93
  end
92
94
 
93
- it 'rejects non-numeric octets' do
95
+ it "rejects non-numeric octets" do
94
96
  errors = {}
95
- validator.validate('key', '192.168.a.1', {}, errors)
96
- expect(errors['key']).to eq('is not a valid IPv4 address')
97
+ validator.validate("key", "192.168.a.1", {}, errors)
98
+ expect(errors["key"]).to eq("is not a valid IPv4 address")
97
99
  end
98
100
  end
99
- end
101
+ end
@@ -1,99 +1,101 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe HashValidator::Validator::Ipv6Validator do
4
6
  let(:validator) { HashValidator::Validator::Ipv6Validator.new }
5
7
 
6
- context 'valid IPv6 addresses' do
7
- it 'validates full IPv6 addresses' do
8
+ context "valid IPv6 addresses" do
9
+ it "validates full IPv6 addresses" do
8
10
  errors = {}
9
- validator.validate('key', '2001:0db8:85a3:0000:0000:8a2e:0370:7334', {}, errors)
11
+ validator.validate("key", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", {}, errors)
10
12
  expect(errors).to be_empty
11
13
  end
12
14
 
13
- it 'validates compressed IPv6 addresses' do
15
+ it "validates compressed IPv6 addresses" do
14
16
  errors = {}
15
- validator.validate('key', '2001:db8:85a3::8a2e:370:7334', {}, errors)
17
+ validator.validate("key", "2001:db8:85a3::8a2e:370:7334", {}, errors)
16
18
  expect(errors).to be_empty
17
19
  end
18
20
 
19
- it 'validates IPv6 localhost' do
21
+ it "validates IPv6 localhost" do
20
22
  errors = {}
21
- validator.validate('key', '::1', {}, errors)
23
+ validator.validate("key", "::1", {}, errors)
22
24
  expect(errors).to be_empty
23
25
  end
24
26
 
25
- it 'validates IPv6 zero address' do
27
+ it "validates IPv6 zero address" do
26
28
  errors = {}
27
- validator.validate('key', '::', {}, errors)
29
+ validator.validate("key", "::", {}, errors)
28
30
  expect(errors).to be_empty
29
31
  end
30
32
 
31
- it 'validates IPv6 with leading zeros' do
33
+ it "validates IPv6 with leading zeros" do
32
34
  errors = {}
33
- validator.validate('key', '2001:0db8::0001', {}, errors)
35
+ validator.validate("key", "2001:0db8::0001", {}, errors)
34
36
  expect(errors).to be_empty
35
37
  end
36
38
 
37
- it 'validates IPv6 with mixed case' do
39
+ it "validates IPv6 with mixed case" do
38
40
  errors = {}
39
- validator.validate('key', '2001:DB8::1', {}, errors)
41
+ validator.validate("key", "2001:DB8::1", {}, errors)
40
42
  expect(errors).to be_empty
41
43
  end
42
44
 
43
- it 'validates IPv4-mapped IPv6 addresses' do
45
+ it "validates IPv4-mapped IPv6 addresses" do
44
46
  errors = {}
45
- validator.validate('key', '::ffff:192.168.1.1', {}, errors)
47
+ validator.validate("key", "::ffff:192.168.1.1", {}, errors)
46
48
  expect(errors).to be_empty
47
49
  end
48
50
  end
49
51
 
50
- context 'invalid IPv6 addresses' do
51
- it 'rejects non-string values' do
52
+ context "invalid IPv6 addresses" do
53
+ it "rejects non-string values" do
52
54
  errors = {}
53
- validator.validate('key', 123, {}, errors)
54
- expect(errors['key']).to eq('is not a valid IPv6 address')
55
+ validator.validate("key", 123, {}, errors)
56
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
55
57
  end
56
58
 
57
- it 'rejects nil values' do
59
+ it "rejects nil values" do
58
60
  errors = {}
59
- validator.validate('key', nil, {}, errors)
60
- expect(errors['key']).to eq('is not a valid IPv6 address')
61
+ validator.validate("key", nil, {}, errors)
62
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
61
63
  end
62
64
 
63
- it 'rejects IPv4 addresses' do
65
+ it "rejects IPv4 addresses" do
64
66
  errors = {}
65
- validator.validate('key', '192.168.1.1', {}, errors)
66
- expect(errors['key']).to eq('is not a valid IPv6 address')
67
+ validator.validate("key", "192.168.1.1", {}, errors)
68
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
67
69
  end
68
70
 
69
- it 'rejects malformed IPv6 addresses' do
71
+ it "rejects malformed IPv6 addresses" do
70
72
  errors = {}
71
- validator.validate('key', '2001:db8:85a3::8a2e::7334', {}, errors)
72
- expect(errors['key']).to eq('is not a valid IPv6 address')
73
+ validator.validate("key", "2001:db8:85a3::8a2e::7334", {}, errors)
74
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
73
75
  end
74
76
 
75
- it 'rejects too many groups' do
77
+ it "rejects too many groups" do
76
78
  errors = {}
77
- validator.validate('key', '2001:0db8:85a3:0000:0000:8a2e:0370:7334:extra', {}, errors)
78
- expect(errors['key']).to eq('is not a valid IPv6 address')
79
+ validator.validate("key", "2001:0db8:85a3:0000:0000:8a2e:0370:7334:extra", {}, errors)
80
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
79
81
  end
80
82
 
81
- it 'rejects invalid characters' do
83
+ it "rejects invalid characters" do
82
84
  errors = {}
83
- validator.validate('key', '2001:db8:85a3::8a2g:370:7334', {}, errors)
84
- expect(errors['key']).to eq('is not a valid IPv6 address')
85
+ validator.validate("key", "2001:db8:85a3::8a2g:370:7334", {}, errors)
86
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
85
87
  end
86
88
 
87
- it 'rejects empty strings' do
89
+ it "rejects empty strings" do
88
90
  errors = {}
89
- validator.validate('key', '', {}, errors)
90
- expect(errors['key']).to eq('is not a valid IPv6 address')
91
+ validator.validate("key", "", {}, errors)
92
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
91
93
  end
92
94
 
93
- it 'rejects incomplete addresses' do
95
+ it "rejects incomplete addresses" do
94
96
  errors = {}
95
- validator.validate('key', '2001:db8:', {}, errors)
96
- expect(errors['key']).to eq('is not a valid IPv6 address')
97
+ validator.validate("key", "2001:db8:", {}, errors)
98
+ expect(errors["key"]).to eq("is not a valid IPv6 address")
97
99
  end
98
100
  end
99
- end
101
+ end