Class: RSpecXML::XMLMatchers::HaveXPath::AttrMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AttrMatcher

Returns a new instance of AttrMatcher.



9
10
11
12
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 9

def initialize(options={})
  self.xpath = options[:xpath]
  self.attr = options[:attr]
end

Instance Method Details

#failure_message_for_shouldObject



20
21
22
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 20

def failure_message_for_should
  "expected #{xpath} to contain #{attr}"
end

#failure_message_for_should_notObject



24
25
26
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 24

def failure_message_for_should_not
  "expected #{xpath} to not exist with attribute: #{attr}"
end

#matches?(xml) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 14

def matches?(xml)
  attr.each do |k, v|
    ::Nokogiri::XML(xml).xpath(xpath).attr(k.to_s).value == v.to_s
  end
end