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,150 +1,152 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe HashValidator::Validator::DynamicPatternValidator do
4
- describe 'Pattern-based validator' do
6
+ describe "Pattern-based validator" do
5
7
  let(:odd_pattern_validator) do
6
8
  HashValidator::Validator::DynamicPatternValidator.new(
7
- 'odd_pattern',
9
+ "odd_pattern",
8
10
  /\A\d*[13579]\z/,
9
- 'is not an odd number'
11
+ "is not an odd number"
10
12
  )
11
13
  end
12
14
 
13
15
  let(:postal_code_validator) do
14
16
  HashValidator::Validator::DynamicPatternValidator.new(
15
- 'us_postal',
17
+ "us_postal",
16
18
  /\A\d{5}(-\d{4})?\z/,
17
- 'is not a valid US postal code'
19
+ "is not a valid US postal code"
18
20
  )
19
21
  end
20
22
 
21
23
  let(:errors) { Hash.new }
22
24
 
23
- describe '#initialize' do
24
- it 'requires a valid regular expression' do
25
+ describe "#initialize" do
26
+ it "requires a valid regular expression" do
25
27
  expect {
26
- HashValidator::Validator::DynamicPatternValidator.new('test', 'not_a_regex')
27
- }.to raise_error(ArgumentError, 'Pattern must be a regular expression')
28
+ HashValidator::Validator::DynamicPatternValidator.new("test", "not_a_regex")
29
+ }.to raise_error(ArgumentError, "Pattern must be a regular expression")
28
30
  end
29
31
 
30
- it 'accepts a custom error message' do
32
+ it "accepts a custom error message" do
31
33
  validator = HashValidator::Validator::DynamicPatternValidator.new(
32
- 'test',
34
+ "test",
33
35
  /test/,
34
- 'custom error'
36
+ "custom error"
35
37
  )
36
- expect(validator.error_message).to eq('custom error')
38
+ expect(validator.error_message).to eq("custom error")
37
39
  end
38
40
 
39
- it 'uses default error message when none provided' do
40
- validator = HashValidator::Validator::DynamicPatternValidator.new('test', /test/)
41
- expect(validator.error_message).to eq('test required')
41
+ it "uses default error message when none provided" do
42
+ validator = HashValidator::Validator::DynamicPatternValidator.new("test", /test/)
43
+ expect(validator.error_message).to eq("test required")
42
44
  end
43
45
  end
44
46
 
45
- describe '#should_validate?' do
46
- it 'validates the correct name' do
47
- expect(odd_pattern_validator.should_validate?('odd_pattern')).to eq true
47
+ describe "#should_validate?" do
48
+ it "validates the correct name" do
49
+ expect(odd_pattern_validator.should_validate?("odd_pattern")).to eq true
48
50
  end
49
51
 
50
- it 'does not validate other names' do
51
- expect(odd_pattern_validator.should_validate?('even_pattern')).to eq false
52
- expect(odd_pattern_validator.should_validate?('string')).to eq false
52
+ it "does not validate other names" do
53
+ expect(odd_pattern_validator.should_validate?("even_pattern")).to eq false
54
+ expect(odd_pattern_validator.should_validate?("string")).to eq false
53
55
  end
54
56
  end
55
57
 
56
- describe '#validate' do
57
- context 'with odd number pattern' do
58
- it 'validates odd numbers correctly' do
59
- odd_pattern_validator.validate(:key, '1', {}, errors)
58
+ describe "#validate" do
59
+ context "with odd number pattern" do
60
+ it "validates odd numbers correctly" do
61
+ odd_pattern_validator.validate(:key, "1", {}, errors)
60
62
  expect(errors).to be_empty
61
63
 
62
64
  errors.clear
63
- odd_pattern_validator.validate(:key, '13', {}, errors)
65
+ odd_pattern_validator.validate(:key, "13", {}, errors)
64
66
  expect(errors).to be_empty
65
67
 
66
68
  errors.clear
67
- odd_pattern_validator.validate(:key, '999', {}, errors)
69
+ odd_pattern_validator.validate(:key, "999", {}, errors)
68
70
  expect(errors).to be_empty
69
71
  end
70
72
 
71
- it 'rejects even numbers' do
72
- odd_pattern_validator.validate(:key, '2', {}, errors)
73
- expect(errors).to eq({ key: 'is not an odd number' })
73
+ it "rejects even numbers" do
74
+ odd_pattern_validator.validate(:key, "2", {}, errors)
75
+ expect(errors).to eq({ key: "is not an odd number" })
74
76
 
75
77
  errors.clear
76
- odd_pattern_validator.validate(:key, '100', {}, errors)
77
- expect(errors).to eq({ key: 'is not an odd number' })
78
+ odd_pattern_validator.validate(:key, "100", {}, errors)
79
+ expect(errors).to eq({ key: "is not an odd number" })
78
80
  end
79
81
 
80
- it 'rejects non-numeric strings' do
81
- odd_pattern_validator.validate(:key, 'abc', {}, errors)
82
- expect(errors).to eq({ key: 'is not an odd number' })
82
+ it "rejects non-numeric strings" do
83
+ odd_pattern_validator.validate(:key, "abc", {}, errors)
84
+ expect(errors).to eq({ key: "is not an odd number" })
83
85
  end
84
86
 
85
- it 'converts non-string values to strings' do
87
+ it "converts non-string values to strings" do
86
88
  odd_pattern_validator.validate(:key, 13, {}, errors)
87
89
  expect(errors).to be_empty
88
90
 
89
91
  errors.clear
90
92
  odd_pattern_validator.validate(:key, 14, {}, errors)
91
- expect(errors).to eq({ key: 'is not an odd number' })
93
+ expect(errors).to eq({ key: "is not an odd number" })
92
94
  end
93
95
  end
94
96
 
95
- context 'with postal code pattern' do
96
- it 'validates correct postal codes' do
97
- postal_code_validator.validate(:key, '12345', {}, errors)
97
+ context "with postal code pattern" do
98
+ it "validates correct postal codes" do
99
+ postal_code_validator.validate(:key, "12345", {}, errors)
98
100
  expect(errors).to be_empty
99
101
 
100
102
  errors.clear
101
- postal_code_validator.validate(:key, '12345-6789', {}, errors)
103
+ postal_code_validator.validate(:key, "12345-6789", {}, errors)
102
104
  expect(errors).to be_empty
103
105
  end
104
106
 
105
- it 'rejects invalid postal codes' do
106
- postal_code_validator.validate(:key, '1234', {}, errors)
107
- expect(errors).to eq({ key: 'is not a valid US postal code' })
107
+ it "rejects invalid postal codes" do
108
+ postal_code_validator.validate(:key, "1234", {}, errors)
109
+ expect(errors).to eq({ key: "is not a valid US postal code" })
108
110
 
109
111
  errors.clear
110
- postal_code_validator.validate(:key, '12345-678', {}, errors)
111
- expect(errors).to eq({ key: 'is not a valid US postal code' })
112
+ postal_code_validator.validate(:key, "12345-678", {}, errors)
113
+ expect(errors).to eq({ key: "is not a valid US postal code" })
112
114
 
113
115
  errors.clear
114
- postal_code_validator.validate(:key, 'ABCDE', {}, errors)
115
- expect(errors).to eq({ key: 'is not a valid US postal code' })
116
+ postal_code_validator.validate(:key, "ABCDE", {}, errors)
117
+ expect(errors).to eq({ key: "is not a valid US postal code" })
116
118
  end
117
119
  end
118
120
  end
119
121
 
120
- describe 'Integration with HashValidator.add_validator' do
122
+ describe "Integration with HashValidator.add_validator" do
121
123
  before do
122
- HashValidator.add_validator('phone_number',
123
- pattern: /\A\d{3}-\d{3}-\d{4}\z/,
124
- error_message: 'is not a valid phone number')
124
+ HashValidator.add_validator("phone_number",
125
+ pattern: /\A\d{3}-\d{3}-\d{4}\z/,
126
+ error_message: "is not a valid phone number")
125
127
  end
126
128
 
127
129
  after do
128
- HashValidator.remove_validator('phone_number')
130
+ HashValidator.remove_validator("phone_number")
129
131
  end
130
132
 
131
- it 'can be registered and used via add_validator' do
133
+ it "can be registered and used via add_validator" do
132
134
  validator = HashValidator.validate(
133
- { phone: '555-123-4567' },
134
- { phone: 'phone_number' }
135
+ { phone: "555-123-4567" },
136
+ { phone: "phone_number" }
135
137
  )
136
138
  expect(validator.valid?).to eq true
137
139
  expect(validator.errors).to be_empty
138
140
  end
139
141
 
140
- it 'returns errors for invalid values' do
142
+ it "returns errors for invalid values" do
141
143
  validator = HashValidator.validate(
142
- { phone: '5551234567' },
143
- { phone: 'phone_number' }
144
+ { phone: "5551234567" },
145
+ { phone: "phone_number" }
144
146
  )
145
147
  expect(validator.valid?).to eq false
146
- expect(validator.errors).to eq({ phone: 'is not a valid phone number' })
148
+ expect(validator.errors).to eq({ phone: "is not a valid phone number" })
147
149
  end
148
150
  end
149
151
  end
150
- end
152
+ end
@@ -1,40 +1,42 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe HashValidator::Validator::Base do
4
6
  let(:validator) { HashValidator::Validator::EmailValidator.new }
5
7
  let(:errors) { Hash.new }
6
8
 
7
- describe '#should_validate?' do
9
+ describe "#should_validate?" do
8
10
  it 'should validate the name "email"' do
9
- expect(validator.should_validate?('email')).to eq true
11
+ expect(validator.should_validate?("email")).to eq true
10
12
  end
11
13
 
12
- it 'should not validate other names' do
13
- expect(validator.should_validate?('string')).to eq false
14
- expect(validator.should_validate?('array')).to eq false
14
+ it "should not validate other names" do
15
+ expect(validator.should_validate?("string")).to eq false
16
+ expect(validator.should_validate?("array")).to eq false
15
17
  expect(validator.should_validate?(nil)).to eq false
16
18
  end
17
19
  end
18
20
 
19
- describe '#validate' do
20
- it 'should validate an email with true' do
21
+ describe "#validate" do
22
+ it "should validate an email with true" do
21
23
  validator.validate(:key, "johndoe@gmail.com", {}, errors)
22
24
 
23
25
  expect(errors).to be_empty
24
26
  end
25
27
 
26
- it 'should validate a string without an @ symbol with false' do
27
- validator.validate(:key, 'test', {}, errors)
28
+ it "should validate a string without an @ symbol with false" do
29
+ validator.validate(:key, "test", {}, errors)
28
30
 
29
31
  expect(errors).not_to be_empty
30
- expect(errors).to eq({ key: 'is not a valid email' })
32
+ expect(errors).to eq({ key: "is not a valid email" })
31
33
  end
32
34
 
33
- it 'should validate a number with false' do
35
+ it "should validate a number with false" do
34
36
  validator.validate(:key, 123, {}, errors)
35
37
 
36
38
  expect(errors).not_to be_empty
37
- expect(errors).to eq({ key: 'is not a valid email' })
39
+ expect(errors).to eq({ key: "is not a valid email" })
38
40
  end
39
41
  end
40
42
  end
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'ActionController::Parameters support' do
3
+ require "spec_helper"
4
+
5
+ describe "ActionController::Parameters support" do
4
6
  # Mock ActionController::Parameters for testing
5
7
  let(:mock_params_class) do
6
8
  Class.new do
@@ -23,12 +25,12 @@ describe 'ActionController::Parameters support' do
23
25
  end
24
26
 
25
27
  def is_a?(klass)
26
- return true if klass.name == 'ActionController::Parameters'
28
+ return true if klass.name == "ActionController::Parameters"
27
29
  super
28
30
  end
29
31
 
30
32
  def class
31
- OpenStruct.new(name: 'ActionController::Parameters')
33
+ Struct.new(:name).new("ActionController::Parameters")
32
34
  end
33
35
  end
34
36
  end
@@ -41,62 +43,62 @@ describe 'ActionController::Parameters support' do
41
43
  end
42
44
  end
43
45
 
44
- it 'should validate ActionController::Parameters objects' do
45
- params = ActionController::Parameters.new({ name: 'John', age: 30 })
46
- validations = { name: 'string', age: 'integer' }
47
-
46
+ it "should validate ActionController::Parameters objects" do
47
+ params = ActionController::Parameters.new({ name: "John", age: 30 })
48
+ validations = { name: "string", age: "integer" }
49
+
48
50
  validator = HashValidator.validate(params, validations)
49
-
51
+
50
52
  expect(validator.valid?).to be true
51
53
  expect(validator.errors).to be_empty
52
54
  end
53
55
 
54
- it 'should handle nested ActionController::Parameters' do
55
- nested_params = ActionController::Parameters.new({ theme: 'dark' })
56
- params = ActionController::Parameters.new({
57
- name: 'John',
56
+ it "should handle nested ActionController::Parameters" do
57
+ nested_params = ActionController::Parameters.new({ theme: "dark" })
58
+ params = ActionController::Parameters.new({
59
+ name: "John",
58
60
  preferences: nested_params
59
61
  })
60
-
61
- validations = {
62
- name: 'string',
63
- preferences: { theme: 'string' }
62
+
63
+ validations = {
64
+ name: "string",
65
+ preferences: { theme: "string" }
64
66
  }
65
-
67
+
66
68
  validator = HashValidator.validate(params, validations)
67
-
69
+
68
70
  expect(validator.valid?).to be true
69
71
  expect(validator.errors).to be_empty
70
72
  end
71
73
 
72
- it 'should validate ActionController::Parameters with our new validators' do
74
+ it "should validate ActionController::Parameters with our new validators" do
73
75
  params = ActionController::Parameters.new({
74
- name: 'John',
75
- email: 'john@example.com',
76
- website: 'https://john.com',
77
- zip_code: '12345'
76
+ name: "John",
77
+ email: "john@example.com",
78
+ website: "https://john.com",
79
+ zip_code: "12345"
78
80
  })
79
-
81
+
80
82
  validations = {
81
- name: 'alpha',
82
- email: 'email',
83
- website: 'url',
84
- zip_code: 'digits'
83
+ name: "alpha",
84
+ email: "email",
85
+ website: "url",
86
+ zip_code: "digits"
85
87
  }
86
-
88
+
87
89
  validator = HashValidator.validate(params, validations)
88
-
90
+
89
91
  expect(validator.valid?).to be true
90
92
  expect(validator.errors).to be_empty
91
93
  end
92
94
 
93
- it 'should still work with regular hashes' do
94
- hash = { name: 'John', age: 30 }
95
- validations = { name: 'string', age: 'integer' }
96
-
95
+ it "should still work with regular hashes" do
96
+ hash = { name: "John", age: 30 }
97
+ validations = { name: "string", age: "integer" }
98
+
97
99
  validator = HashValidator.validate(hash, validations)
98
-
100
+
99
101
  expect(validator.valid?).to be true
100
102
  expect(validator.errors).to be_empty
101
103
  end
102
- end
104
+ end
@@ -1,111 +1,113 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe HashValidator::Validator::HexColorValidator do
4
6
  let(:validator) { HashValidator::Validator::HexColorValidator.new }
5
7
 
6
- context 'valid hex colors' do
7
- it 'validates 6-digit hex colors (lowercase)' do
8
+ context "valid hex colors" do
9
+ it "validates 6-digit hex colors (lowercase)" do
8
10
  errors = {}
9
- validator.validate('key', '#ff0000', {}, errors)
11
+ validator.validate("key", "#ff0000", {}, errors)
10
12
  expect(errors).to be_empty
11
13
  end
12
14
 
13
- it 'validates 6-digit hex colors (uppercase)' do
15
+ it "validates 6-digit hex colors (uppercase)" do
14
16
  errors = {}
15
- validator.validate('key', '#FF0000', {}, errors)
17
+ validator.validate("key", "#FF0000", {}, errors)
16
18
  expect(errors).to be_empty
17
19
  end
18
20
 
19
- it 'validates 6-digit hex colors (mixed case)' do
21
+ it "validates 6-digit hex colors (mixed case)" do
20
22
  errors = {}
21
- validator.validate('key', '#Ff0000', {}, errors)
23
+ validator.validate("key", "#Ff0000", {}, errors)
22
24
  expect(errors).to be_empty
23
25
  end
24
26
 
25
- it 'validates 3-digit hex colors (lowercase)' do
27
+ it "validates 3-digit hex colors (lowercase)" do
26
28
  errors = {}
27
- validator.validate('key', '#f00', {}, errors)
29
+ validator.validate("key", "#f00", {}, errors)
28
30
  expect(errors).to be_empty
29
31
  end
30
32
 
31
- it 'validates 3-digit hex colors (uppercase)' do
33
+ it "validates 3-digit hex colors (uppercase)" do
32
34
  errors = {}
33
- validator.validate('key', '#F00', {}, errors)
35
+ validator.validate("key", "#F00", {}, errors)
34
36
  expect(errors).to be_empty
35
37
  end
36
38
 
37
- it 'validates black color' do
39
+ it "validates black color" do
38
40
  errors = {}
39
- validator.validate('key', '#000000', {}, errors)
41
+ validator.validate("key", "#000000", {}, errors)
40
42
  expect(errors).to be_empty
41
43
  end
42
44
 
43
- it 'validates white color' do
45
+ it "validates white color" do
44
46
  errors = {}
45
- validator.validate('key', '#ffffff', {}, errors)
47
+ validator.validate("key", "#ffffff", {}, errors)
46
48
  expect(errors).to be_empty
47
49
  end
48
50
 
49
- it 'validates complex hex colors' do
51
+ it "validates complex hex colors" do
50
52
  errors = {}
51
- validator.validate('key', '#3a7bd4', {}, errors)
53
+ validator.validate("key", "#3a7bd4", {}, errors)
52
54
  expect(errors).to be_empty
53
55
  end
54
56
  end
55
57
 
56
- context 'invalid hex colors' do
57
- it 'rejects non-string values' do
58
+ context "invalid hex colors" 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 hex color')
61
+ validator.validate("key", 123, {}, errors)
62
+ expect(errors["key"]).to eq("is not a valid hex color")
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 hex color')
67
+ validator.validate("key", nil, {}, errors)
68
+ expect(errors["key"]).to eq("is not a valid hex color")
67
69
  end
68
70
 
69
- it 'rejects hex colors without hash' do
71
+ it "rejects hex colors without hash" do
70
72
  errors = {}
71
- validator.validate('key', 'ff0000', {}, errors)
72
- expect(errors['key']).to eq('is not a valid hex color')
73
+ validator.validate("key", "ff0000", {}, errors)
74
+ expect(errors["key"]).to eq("is not a valid hex color")
73
75
  end
74
76
 
75
- it 'rejects invalid length (4 digits)' do
77
+ it "rejects invalid length (4 digits)" do
76
78
  errors = {}
77
- validator.validate('key', '#ff00', {}, errors)
78
- expect(errors['key']).to eq('is not a valid hex color')
79
+ validator.validate("key", "#ff00", {}, errors)
80
+ expect(errors["key"]).to eq("is not a valid hex color")
79
81
  end
80
82
 
81
- it 'rejects invalid length (5 digits)' do
83
+ it "rejects invalid length (5 digits)" do
82
84
  errors = {}
83
- validator.validate('key', '#ff000', {}, errors)
84
- expect(errors['key']).to eq('is not a valid hex color')
85
+ validator.validate("key", "#ff000", {}, errors)
86
+ expect(errors["key"]).to eq("is not a valid hex color")
85
87
  end
86
88
 
87
- it 'rejects invalid length (7 digits)' do
89
+ it "rejects invalid length (7 digits)" do
88
90
  errors = {}
89
- validator.validate('key', '#ff00000', {}, errors)
90
- expect(errors['key']).to eq('is not a valid hex color')
91
+ validator.validate("key", "#ff00000", {}, errors)
92
+ expect(errors["key"]).to eq("is not a valid hex color")
91
93
  end
92
94
 
93
- it 'rejects invalid characters' do
95
+ it "rejects invalid characters" do
94
96
  errors = {}
95
- validator.validate('key', '#gg0000', {}, errors)
96
- expect(errors['key']).to eq('is not a valid hex color')
97
+ validator.validate("key", "#gg0000", {}, errors)
98
+ expect(errors["key"]).to eq("is not a valid hex color")
97
99
  end
98
100
 
99
- it 'rejects empty strings' do
101
+ it "rejects empty strings" do
100
102
  errors = {}
101
- validator.validate('key', '', {}, errors)
102
- expect(errors['key']).to eq('is not a valid hex color')
103
+ validator.validate("key", "", {}, errors)
104
+ expect(errors["key"]).to eq("is not a valid hex color")
103
105
  end
104
106
 
105
- it 'rejects just hash symbol' do
107
+ it "rejects just hash symbol" do
106
108
  errors = {}
107
- validator.validate('key', '#', {}, errors)
108
- expect(errors['key']).to eq('is not a valid hex color')
109
+ validator.validate("key", "#", {}, errors)
110
+ expect(errors["key"]).to eq("is not a valid hex color")
109
111
  end
110
112
  end
111
- end
113
+ end