Class: RSpecXML::XMLMatchers::HaveXPath::AttrMatcher
- Inherits:
-
Object
- Object
- RSpecXML::XMLMatchers::HaveXPath::AttrMatcher
- Defined in:
- lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(options = {}) ⇒ AttrMatcher
constructor
A new instance of AttrMatcher.
- #matches?(xml) ⇒ Boolean
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(={}) self.xpath = [:xpath] self.attr = [:attr] end |
Instance Method Details
#failure_message_for_should ⇒ Object
20 21 22 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 20 def "expected #{xpath} to contain #{attr}" end |
#failure_message_for_should_not ⇒ Object
24 25 26 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 24 def "expected #{xpath} to not exist with attribute: #{attr}" end |
#matches?(xml) ⇒ 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 |