You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
893 B

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe URLValidator, type: :validator do
  4. describe '#validate_each' do
  5. before do
  6. allow(validator).to receive(:compliant?).with(value) { compliant }
  7. validator.validate_each(record, attribute, value)
  8. end
  9. let(:validator) { described_class.new(attributes: [attribute]) }
  10. let(:record) { double(errors: errors) }
  11. let(:errors) { double(add: nil) }
  12. let(:value) { '' }
  13. let(:attribute) { :foo }
  14. context 'unless compliant?' do
  15. let(:compliant) { false }
  16. it 'calls errors.add' do
  17. expect(errors).to have_received(:add).with(attribute, :invalid)
  18. end
  19. end
  20. context 'if compliant?' do
  21. let(:compliant) { true }
  22. it 'not calls errors.add' do
  23. expect(errors).not_to have_received(:add).with(attribute, any_args)
  24. end
  25. end
  26. end
  27. end