defra_ruby_validators 2.4.1 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +9 -2
  3. data/lib/defra_ruby/validators/companies_house_number_validator.rb +9 -5
  4. data/lib/defra_ruby/validators/companies_house_service.rb +26 -12
  5. data/lib/defra_ruby/validators/version.rb +1 -1
  6. metadata +22 -174
  7. data/spec/defra_ruby/validators/business_type_validator_spec.rb +0 -56
  8. data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +0 -108
  9. data/spec/defra_ruby/validators/companies_house_service_spec.rb +0 -70
  10. data/spec/defra_ruby/validators/configuration_spec.rb +0 -49
  11. data/spec/defra_ruby/validators/email_validator_spec.rb +0 -46
  12. data/spec/defra_ruby/validators/grid_reference_validator_spec.rb +0 -57
  13. data/spec/defra_ruby/validators/location_validator_spec.rb +0 -56
  14. data/spec/defra_ruby/validators/past_date_validator_spec.rb +0 -35
  15. data/spec/defra_ruby/validators/phone_number_validator_spec.rb +0 -59
  16. data/spec/defra_ruby/validators/position_validator_spec.rb +0 -47
  17. data/spec/defra_ruby/validators/token_validator_spec.rb +0 -45
  18. data/spec/defra_ruby/validators/true_false_validator_spec.rb +0 -37
  19. data/spec/defra_ruby/validators_spec.rb +0 -12
  20. data/spec/spec_helper.rb +0 -87
  21. data/spec/support/defra_ruby_validators.rb +0 -16
  22. data/spec/support/helpers/text_generator.rb +0 -17
  23. data/spec/support/helpers/translator.rb +0 -15
  24. data/spec/support/i18n.rb +0 -8
  25. data/spec/support/pry.rb +0 -7
  26. data/spec/support/shared_examples/validators/characters_validator.rb +0 -29
  27. data/spec/support/shared_examples/validators/invalid_record.rb +0 -29
  28. data/spec/support/shared_examples/validators/length_validator.rb +0 -29
  29. data/spec/support/shared_examples/validators/presence_validator.rb +0 -29
  30. data/spec/support/shared_examples/validators/selection_validator.rb +0 -40
  31. data/spec/support/shared_examples/validators/valid_record.rb +0 -12
  32. data/spec/support/shared_examples/validators/validator.rb +0 -8
  33. data/spec/support/simplecov.rb +0 -17
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe DefraRuby::Validators::Configuration do
6
- describe "ATTRIBUTES" do
7
- it "represents the expected config settings and only those settings" do
8
- expected_attributes = %i[
9
- companies_house_host
10
- companies_house_api_key
11
- ]
12
-
13
- expect(described_class::ATTRIBUTES).to match_array(expected_attributes)
14
- end
15
- end
16
-
17
- it "sets the appropriate default config settings" do
18
- fresh_config = described_class.new
19
-
20
- expect(fresh_config.companies_house_host).to eq("https://api.companieshouse.gov.uk/company/")
21
- expect(fresh_config.companies_house_api_key).to eq(nil)
22
- end
23
-
24
- describe "#ensure_valid" do
25
- before(:each) do
26
- described_class::ATTRIBUTES.each do |attribute|
27
- subject.public_send("#{attribute}=", "foo")
28
- end
29
- end
30
-
31
- context "when all of the attributes are present" do
32
- it "does not raise an error" do
33
- expect { subject.ensure_valid }.to_not raise_error
34
- expect(subject.ensure_valid).to eq(true)
35
- end
36
- end
37
-
38
- context "when at least one of the attributes is missing" do
39
- before(:each) do
40
- subject.companies_house_api_key = nil
41
- end
42
-
43
- it "raises an error" do
44
- message = "The following DefraRuby::Validators configuration attributes are missing: [:companies_house_api_key]"
45
- expect { subject.ensure_valid }.to raise_error(message)
46
- end
47
- end
48
- end
49
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- EmailValidatable = Struct.new(:email) do
7
- include ActiveModel::Validations
8
-
9
- validates :email, "defra_ruby/validators/email": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe EmailValidator, type: :model do
16
-
17
- valid_email = "test@example.com"
18
- invalid_email = "foo@bar"
19
-
20
- it_behaves_like("a validator")
21
- it_behaves_like(
22
- "a presence validator",
23
- EmailValidator,
24
- Test::EmailValidatable,
25
- :email,
26
- valid: valid_email
27
- )
28
-
29
- describe "#validate_each" do
30
- context "when the email is not valid" do
31
- context "because the email is not correctly formatted" do
32
- validatable = Test::EmailValidatable.new(invalid_email)
33
-
34
- error_message = Helpers::Translator.error_message(EmailValidator, :invalid_format)
35
-
36
- it_behaves_like "an invalid record",
37
- validatable: validatable,
38
- attribute: :email,
39
- error: :invalid_format,
40
- error_message: error_message
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- GridReferenceValidatable = Struct.new(:grid_reference) do
7
- include ActiveModel::Validations
8
-
9
- validates :grid_reference, "defra_ruby/validators/grid_reference": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe GridReferenceValidator, type: :model do
16
-
17
- valid_grid_reference = "ST 58337 72855" # Bristol, City of Bristol
18
- invalid_grid_reference = "58337 72855"
19
- non_coordinate_grid_reference = "AA 12345 67890"
20
-
21
- it_behaves_like("a validator")
22
- it_behaves_like(
23
- "a presence validator",
24
- GridReferenceValidator,
25
- Test::GridReferenceValidatable,
26
- :grid_reference,
27
- valid: valid_grid_reference
28
- )
29
-
30
- describe "#validate_each" do
31
- context "when the grid reference is not valid" do
32
- context "because the grid reference is not correctly formatted" do
33
- validatable = Test::GridReferenceValidatable.new(invalid_grid_reference)
34
- error_message = Helpers::Translator.error_message(GridReferenceValidator, :invalid_format)
35
-
36
- it_behaves_like "an invalid record",
37
- validatable: validatable,
38
- attribute: :grid_reference,
39
- error: :invalid_format,
40
- error_message: error_message
41
- end
42
-
43
- context "because the grid reference is not a coordinate" do
44
- validatable = Test::GridReferenceValidatable.new(non_coordinate_grid_reference)
45
- error_message = Helpers::Translator.error_message(GridReferenceValidator, :invalid)
46
-
47
- it_behaves_like "an invalid record",
48
- validatable: validatable,
49
- attribute: :grid_reference,
50
- error: :invalid,
51
- error_message: error_message
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- LocationValidatable = Struct.new(:location) do
7
- include ActiveModel::Validations
8
-
9
- validates :location, "defra_ruby/validators/location": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe LocationValidator, type: :model do
16
-
17
- valid_location = %w[england northern_ireland scotland wales].sample
18
- invalid_location = "france"
19
-
20
- it_behaves_like("a validator")
21
- it_behaves_like(
22
- "a selection validator",
23
- LocationValidator,
24
- Test::LocationValidatable,
25
- :location,
26
- valid: valid_location, invalid: invalid_location
27
- )
28
-
29
- context "when the value is overseas" do
30
- validatable = Test::LocationValidatable.new("overseas")
31
-
32
- context "when overseas_allowed is enabled" do
33
- before do
34
- allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return(allow_overseas: true)
35
- end
36
-
37
- it_behaves_like "a valid record", validatable
38
- end
39
-
40
- context "when overseas_allowed is not enabled" do
41
- before do
42
- allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return({})
43
- end
44
-
45
- error_message = Helpers::Translator.error_message(LocationValidator, :inclusion)
46
-
47
- it_behaves_like "an invalid record",
48
- validatable: validatable,
49
- attribute: :location,
50
- error: :inclusion,
51
- error_message: error_message
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- PastDateValidatable = Struct.new(:date) do
7
- include ActiveModel::Validations
8
-
9
- validates :date, "defra_ruby/validators/past_date": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe PastDateValidator, type: :model do
16
-
17
- valid_date = Date.today
18
- future_date = Date.today + 1
19
- invalid_date = Date.new(20, 2, 2)
20
-
21
- it_behaves_like "a valid record", Test::PastDateValidatable.new(valid_date)
22
- it_behaves_like "an invalid record",
23
- validatable: Test::PastDateValidatable.new(future_date),
24
- attribute: :date,
25
- error: :past_date,
26
- error_message: Helpers::Translator.error_message(PastDateValidator, :past_date)
27
-
28
- it_behaves_like "an invalid record",
29
- validatable: Test::PastDateValidatable.new(invalid_date),
30
- attribute: :date,
31
- error: :invalid_date,
32
- error_message: Helpers::Translator.error_message(PastDateValidator, :invalid_date)
33
- end
34
- end
35
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- PhoneNumberValidatable = Struct.new(:phone_number) do
7
- include ActiveModel::Validations
8
-
9
- validates :phone_number, "defra_ruby/validators/phone_number": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe PhoneNumberValidator, type: :model do
16
-
17
- valid_number = [
18
- "+441234567890",
19
- "01234567890",
20
- "+441234-567-890",
21
- "01234.567.890",
22
- "+441234 567 890"
23
- ].sample
24
- too_long_number = Helpers::TextGenerator.random_number_string(16) # The max length is 15.
25
- invalid_number = "#123"
26
-
27
- it_behaves_like("a validator")
28
- it_behaves_like(
29
- "a presence validator",
30
- PhoneNumberValidator,
31
- Test::PhoneNumberValidatable,
32
- :phone_number,
33
- valid: valid_number
34
- )
35
- it_behaves_like(
36
- "a length validator",
37
- PhoneNumberValidator,
38
- Test::PhoneNumberValidatable,
39
- :phone_number,
40
- valid: valid_number, invalid: too_long_number
41
- )
42
-
43
- describe "#validate_each" do
44
- context "when the phone number is not valid" do
45
- context "because the phone number is not correctly formatted" do
46
- validatable = Test::PhoneNumberValidatable.new(invalid_number)
47
- error_message = Helpers::Translator.error_message(PhoneNumberValidator, :invalid_format)
48
-
49
- it_behaves_like "an invalid record",
50
- validatable: validatable,
51
- attribute: :phone_number,
52
- error: :invalid_format,
53
- error_message: error_message
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- PositionValidatable = Struct.new(:position) do
7
- include ActiveModel::Validations
8
-
9
- validates :position, "defra_ruby/validators/position": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe PositionValidator, type: :model do
16
-
17
- valid_position = "Padawan"
18
- too_long_position = Helpers::TextGenerator.random_string(PositionValidator::MAX_LENGTH + 1)
19
- invalid_position = "**Invalid_@_Position**"
20
- empty_position = ""
21
-
22
- it_behaves_like("a validator")
23
- it_behaves_like(
24
- "a length validator",
25
- PositionValidator,
26
- Test::PositionValidatable,
27
- :position,
28
- valid: valid_position, invalid: too_long_position
29
- )
30
- it_behaves_like(
31
- "a characters validator",
32
- PositionValidator,
33
- Test::PositionValidatable,
34
- :position,
35
- valid: valid_position, invalid: invalid_position
36
- )
37
-
38
- describe "#validate_each" do
39
- context "when the position is valid" do
40
- context "despite being blank (because position is optional)" do
41
- it_behaves_like "a valid record", Test::PositionValidatable.new(empty_position)
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- TokenValidatable = Struct.new(:token) do
7
- include ActiveModel::Validations
8
-
9
- validates :token, "defra_ruby/validators/token": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe TokenValidator, type: :model do
16
-
17
- valid_token = Helpers::TextGenerator.random_string(24)
18
- invalid_token = "123456"
19
-
20
- it_behaves_like("a validator")
21
- it_behaves_like(
22
- "a presence validator",
23
- TokenValidator,
24
- Test::TokenValidatable,
25
- :token,
26
- valid: valid_token
27
- )
28
-
29
- describe "#validate_each" do
30
- context "when the token is not valid" do
31
- context "because the token is not correctly formatted" do
32
- validatable = Test::TokenValidatable.new(invalid_token)
33
- error_message = Helpers::Translator.error_message(TokenValidator, :invalid_format)
34
-
35
- it_behaves_like "an invalid record",
36
- validatable: validatable,
37
- attribute: :token,
38
- error: :invalid_format,
39
- error_message: error_message
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- TrueFalseValidatable = Struct.new(:attribute) do
7
- include ActiveModel::Validations
8
-
9
- validates :attribute, "defra_ruby/validators/true_false": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe TrueFalseValidator do
16
- invalid_value = "unsure"
17
-
18
- it_behaves_like("a validator")
19
-
20
- it_behaves_like(
21
- "a selection validator",
22
- TrueFalseValidator,
23
- Test::TrueFalseValidatable,
24
- :attribute,
25
- valid: true, invalid: invalid_value
26
- )
27
-
28
- it_behaves_like(
29
- "a selection validator",
30
- TrueFalseValidator,
31
- Test::TrueFalseValidatable,
32
- :attribute,
33
- valid: false, invalid: invalid_value
34
- )
35
- end
36
- end
37
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe DefraRuby::Validators do
6
- describe "VERSION" do
7
- it "is a version string in the correct format" do
8
- expect(DefraRuby::Validators::VERSION).to be_a(String)
9
- expect(DefraRuby::Validators::VERSION).to match(/\d+\.\d+\.\d+/)
10
- end
11
- end
12
- end
data/spec/spec_helper.rb DELETED
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/setup"
4
-
5
- # Require and run our simplecov initializer as the very first thing we do.
6
- # This is as per its docs https://github.com/colszowka/simplecov#getting-started
7
- require "./spec/support/simplecov"
8
-
9
- # Load env vars from a text file. This must be done before we load the other
10
- # support files as some of them rely on the env vars being set.
11
- require "dotenv/load"
12
-
13
- # Requires supporting ruby files with custom matchers and macros, etc, in
14
- # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
15
- # run as spec files by default. This means that files in spec/support that end
16
- # in _spec.rb will both be required and run as specs, causing the specs to be
17
- # run twice. It is recommended that you do not name files matching this glob to
18
- # end with _spec.rb. You can configure this pattern with the --pattern
19
- # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
20
- #
21
- # We make an exception for simplecov because that will already have been
22
- # required and run at the very top of spec_helper.rb
23
- support_files = Dir["./spec/support/**/*.rb"].reject { |file| file == "./spec/support/simplecov.rb" }
24
- support_files.each { |f| require f }
25
-
26
- RSpec.configure do |config|
27
- # rspec-expectations config goes here. You can use an alternate
28
- # assertion/expectation library such as wrong or the stdlib/minitest
29
- # assertions if you prefer.
30
- config.expect_with :rspec do |expectations|
31
- # This option will default to `true` in RSpec 4. It makes the `description`
32
- # and `failure_message` of custom matchers include text for helper methods
33
- # defined using `chain`, e.g.:
34
- # be_bigger_than(2).and_smaller_than(4).description
35
- # # => "be bigger than 2 and smaller than 4"
36
- # ...rather than:
37
- # # => "be bigger than 2"
38
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
- end
40
-
41
- # rspec-mocks config goes here. You can use an alternate test double
42
- # library (such as bogus or mocha) by changing the `mock_with` option here.
43
- config.mock_with :rspec do |mocks|
44
- # Prevents you from mocking or stubbing a method that does not exist on
45
- # a real object. This is generally recommended, and will default to
46
- # `true` in RSpec 4.
47
- mocks.verify_partial_doubles = true
48
- end
49
-
50
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
51
- # have no way to turn it off -- the option exists only for backwards
52
- # compatibility in RSpec 3). It causes shared context metadata to be
53
- # inherited by the metadata hash of host groups and examples, rather than
54
- # triggering implicit auto-inclusion in groups with matching metadata.
55
- config.shared_context_metadata_behavior = :apply_to_host_groups
56
-
57
- # This allows you to limit a spec run to individual examples or groups
58
- # you care about by tagging them with `:focus` metadata. When nothing
59
- # is tagged with `:focus`, all examples get run. RSpec also provides
60
- # aliases for `it`, `describe`, and `context` that include `:focus`
61
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
62
- config.filter_run_when_matching :focus
63
-
64
- # Allows RSpec to persist some state between runs in order to support
65
- # the `--only-failures` and `--next-failure` CLI options. We recommend
66
- # you configure your source control system to ignore this file.
67
- config.example_status_persistence_file_path = "spec/examples.txt"
68
-
69
- # Limits the available syntax to the non-monkey patched syntax that is
70
- # recommended. For more details, see:
71
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
72
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
73
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
74
- config.disable_monkey_patching!
75
-
76
- # Run specs in random order to surface order dependencies. If you find an
77
- # order dependency and want to debug it, you can fix the order by providing
78
- # the seed, which is printed after each run.
79
- # --seed 1234
80
- config.order = :random
81
-
82
- # Seed global randomization in this process using the `--seed` CLI option.
83
- # Setting this allows you to use `--seed` to deterministically reproduce
84
- # test failures related to randomization by passing the same `--seed` value
85
- # as the one that triggered the failure.
86
- Kernel.srand config.seed
87
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Need to require our actual code files. We don't just require everything in
4
- # lib/defra_ruby because it contains the engine file which has a dependency on
5
- # rails. We don't have that as a dependency of this project because it is
6
- # a given this will be used in a rails project. So instead we require the
7
- # validators file directly to load the content covered by our tests.
8
- require "defra_ruby/validators"
9
-
10
- DefraRuby::Validators.configure do |c|
11
- def raise_missing_env_var(variable)
12
- raise("Environment variable #{variable} has not been set")
13
- end
14
-
15
- c.companies_house_api_key = (ENV["COMPANIES_HOUSE_API_KEY"] || raise_missing_env_var("COMPANIES_HOUSE_API_KEY"))
16
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Helpers
4
- module TextGenerator
5
- def self.random_string(length)
6
- random_string_from_sequence([("a".."z"), ("A".."Z")].map(&:to_a).flatten, length)
7
- end
8
-
9
- def self.random_number_string(length)
10
- random_string_from_sequence(("0".."9").to_a, length)
11
- end
12
-
13
- def self.random_string_from_sequence(sequence, length)
14
- (0...length).map { sequence[rand(sequence.length)] }.join
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Helpers
4
- module Translator
5
- def self.error_message(klass, error)
6
- class_name = klass_name(klass)
7
-
8
- I18n.t("defra_ruby.validators.#{class_name}.#{error}")
9
- end
10
-
11
- def self.klass_name(klass)
12
- klass.name.split("::").last
13
- end
14
- end
15
- end
data/spec/support/i18n.rb DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Support using the locale files within our tests (else we'd rely on loading the
4
- # gem in a rails app to confirm these are being pulled through correctly.)
5
- require "i18n"
6
-
7
- I18n.load_path << Dir[File.expand_path("config/locales") + "/**/*.yml"]
8
- I18n.default_locale = :en
data/spec/support/pry.rb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Support debugging in the tests. Add `binding.pry` wherever you want execution
4
- # to stop and the debugger to kick in.
5
- # Details on the debugging commands can be found here
6
- # https://github.com/deivid-rodriguez/pry-byebug#commands
7
- require "pry-byebug"
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples "a characters validator" do |validator, validatable_class, attribute, values|
4
- it "includes CanValidateCharacters" do
5
- included_modules = described_class.ancestors.select { |ancestor| ancestor.instance_of?(Module) }
6
-
7
- expect(included_modules)
8
- .to include(DefraRuby::Validators::CanValidateCharacters)
9
- end
10
-
11
- describe "#validate_each" do
12
- context "when the #{attribute} is valid" do
13
- it_behaves_like "a valid record", validatable_class.new(values[:valid])
14
- end
15
-
16
- context "when the #{attribute} is not valid" do
17
- context "because the #{attribute} is not correctly formatted" do
18
- validatable = validatable_class.new(values[:invalid])
19
- error_message = Helpers::Translator.error_message(validator, :invalid_format)
20
-
21
- it_behaves_like "an invalid record",
22
- validatable: validatable,
23
- attribute: attribute,
24
- error: :invalid_format,
25
- error_message: error_message
26
- end
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples "an invalid record" do |validatable:, attribute:, error:, error_message:|
4
- it "confirms the object is invalid" do
5
- expect(validatable).to_not be_valid
6
- end
7
-
8
- it "adds a single validation error to the record" do
9
- validatable.valid?
10
- expect(validatable.errors[attribute].count).to eq(1)
11
- end
12
-
13
- it "adds an appropriate validation error" do
14
- validatable.valid?
15
- expect(error_message).to_not include("translation missing:")
16
- expect(validatable.errors[attribute]).to eq([error_message])
17
- end
18
-
19
- context "when there are custom error messages" do
20
- let(:custom_message) { "something is wrong (in a customised way)" }
21
- let(:messages) { { error => custom_message } }
22
- before { allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return(messages: messages) }
23
-
24
- it "uses the custom message instead of the default" do
25
- validatable.valid?
26
- expect(validatable.errors[attribute]).to eq([custom_message])
27
- end
28
- end
29
- end