Class: ValidatesXmlOf::Matchers::ValidateXmlOf

Inherits:
Object
  • Object
show all
Defined in:
lib/validates_xml_of/matchers/validate_xml_of.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ ValidateXmlOf

Returns a new instance of ValidateXmlOf.



6
7
8
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 6

def initialize(attribute)
  @attribute = attribute
end

Instance Method Details

#descriptionObject



25
26
27
28
29
30
31
32
33
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 25

def description
  description = "#{@attribute} contains a valid xml"

  if @schema
    description << " based on '#{@schema}'"
  end

  description
end

#failure_messageObject



41
42
43
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 41

def failure_message
  "Expected #{@attribute} to contains a valid xml, but it is #{attribute_output.inspect}"
end

#failure_message_when_negatedObject



45
46
47
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 45

def failure_message_when_negated
  "Expected #{@attribute} to not contains a valid xml, but it is #{attribute_output.inspect}"
end

#matches?(given_record) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 10

def matches?(given_record)
  @given_record = given_record

  @expected_message ||= ValidatesXmlOf.default_message

  valid_xml? && valid_xml_based_on_schema?
end

#with_message(expected_message) ⇒ Object



35
36
37
38
39
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 35

def with_message(expected_message)
  @expected_message = expected_message

  self
end

#with_schema(schema) ⇒ Object



18
19
20
21
22
23
# File 'lib/validates_xml_of/matchers/validate_xml_of.rb', line 18

def with_schema(schema)
  @schema = schema
  @expected_message ||= ValidatesXmlOf.default_schema_message

  self
end