Class: XmlSpec::Matchers::BeXmlEql

Inherits:
Object
  • Object
show all
Includes:
Exclusion, Helpers, XmlSpec::Messages
Defined in:
lib/xml_spec/matchers/be_xml_eql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XmlSpec::Messages

#message_with_path

Methods included from Exclusion

#exclude_key?, #exclude_keys, #excluded_keys

Methods included from Helpers

#generate_normalized_xml, #load_xml, #normalize_xml, #parse_xml

Constructor Details

#initialize(expected_xml = nil) ⇒ BeXmlEql

Returns a new instance of BeXmlEql.



15
16
17
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 15

def initialize( expected_xml=nil )
  @expected_xml = expected_xml
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



9
10
11
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 9

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



9
10
11
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 9

def expected
  @expected
end

Instance Method Details

#at_path(path) ⇒ Object



30
31
32
33
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 30

def at_path(path)
  @path = path
  self
end

#descriptionObject



58
59
60
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 58

def description
  message_with_path("equal XML")
end

#diffable?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 11

def diffable?
  true
end

#excluding(*keys) ⇒ Object



40
41
42
43
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 40

def excluding(*keys)
  excluded_keys.merge(keys.map(&:to_s))
  self
end

#failure_message_for_shouldObject



50
51
52
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 50

def failure_message_for_should
  message_with_path( "Expected equivalent XML" ) #+ "\nReadable Diff:\n#{diff}"
end

#failure_message_for_should_notObject



54
55
56
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 54

def failure_message_for_should_not
  message_with_path( "Expected inequivalent XML" )
end

#including(*keys) ⇒ Object



45
46
47
48
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 45

def including(*keys)
  excluded_keys.subtract(keys.map(&:to_s))
  self
end

#matches?(actual_xml) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 19

def matches?( actual_xml )
  raise "Expected equivalent XML not provided" if @expected_xml.nil?

  @actual_xml = actual_xml
  @actual = parse_xml( actual_xml, @path )
  @expected = parse_xml( @expected_xml, @path )
  #@actual, @expected = scrub(actual_xml, @path), scrub(@expected_xml)
  #@actual == @expected
  EquivalentXml.equivalent?( @expected_xml, @actual_xml )
end

#to_file(path) ⇒ Object



35
36
37
38
# File 'lib/xml_spec/matchers/be_xml_eql.rb', line 35

def to_file(path)
  @expected_xml = load_xml(path)
  self
end