Class: VatIdValidator::Matchers::ValidateVatIdOf

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/matchers/validate_vat_id_of.rb

Overview

Represents the rspec matcher for the vat_id validator

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ ValidateVatIdOf

Returns a new instance of ValidateVatIdOf.



14
15
16
# File 'lib/rspec/matchers/validate_vat_id_of.rb', line 14

def initialize(expected)
  @expected = expected
end

Instance Method Details

#descriptionString

Returns the description for the matcher

Returns:

  • (String)

    the description



44
45
46
# File 'lib/rspec/matchers/validate_vat_id_of.rb', line 44

def description
  'be a vat id'
end

#failure_message_for_shouldString

Returns a error message for should matches

Returns:

  • (String)

    the error message



30
31
32
# File 'lib/rspec/matchers/validate_vat_id_of.rb', line 30

def failure_message_for_should
  "expected that #{@expected} would be a vat id"
end

#failure_message_for_should_notString

Returns a error message for should_not matches

Returns:

  • (String)

    the error message



37
38
39
# File 'lib/rspec/matchers/validate_vat_id_of.rb', line 37

def failure_message_for_should_not
  "expected that #{@expected} would not be a vat id"
end

#matches?(actual) ⇒ boolean

Checks if the given Objects has a validator for the expected attribute

Parameters:

  • actual (Object)

    the object with the expected attribute

Returns:

  • (boolean)


22
23
24
25
# File 'lib/rspec/matchers/validate_vat_id_of.rb', line 22

def matches?(actual)
  validators = actual._validators[@expected]
  validators.select { |val| val.is_a?(ActiveModel::Validations::VatIdValidator) }.count > 0
end