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
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ 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
#description ⇒ Object
24 25 26 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 24 def description "have xpath #{xpath} with attribute: #{attr}" end |
#failure_message ⇒ Object
28 29 30 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 28 def "expected #{xpath} to contain attribute: #{attr}" end |
#failure_message_when_negated ⇒ Object
32 33 34 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 32 def "expected #{xpath} to not exist with attribute: #{attr}" end |
#matches?(xml) ⇒ Boolean
14 15 16 17 18 19 20 21 22 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb', line 14 def matches?(xml) nodes = ::Nokogiri::XML(xml).xpath(xpath).to_a !nodes.empty? && nodes.any? do |node| attr.all? do |k, v| attr_value = node.attr(k.to_s) !attr_value.nil? && attr_value == v.to_s end end end |