Class: RSpecXML::XMLMatchers::HaveXPath::Matcher
- Inherits:
-
Object
- Object
- RSpecXML::XMLMatchers::HaveXPath::Matcher
- Defined in:
- lib/rspec-xml/xml_matchers/have_xpath/matcher.rb
Instance Attribute Summary collapse
-
#example_group ⇒ Object
Returns the value of attribute example_group.
-
#xpath ⇒ Object
Returns the value of attribute xpath.
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
- #full_xpath ⇒ Object
-
#initialize(options = {}) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(xml) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Matcher
Returns a new instance of Matcher.
7 8 9 10 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 7 def initialize(={}) self.xpath = [:xpath] self.example_group = [:example_group] end |
Instance Attribute Details
#example_group ⇒ Object
Returns the value of attribute example_group.
29 30 31 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 29 def example_group @example_group end |
#xpath ⇒ Object
Returns the value of attribute xpath.
29 30 31 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 29 def xpath @xpath end |
Instance Method Details
#failure_message_for_should ⇒ Object
16 17 18 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 16 def "expected #{full_xpath} to exist" end |
#failure_message_for_should_not ⇒ Object
20 21 22 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 20 def "expected #{full_xpath} to not exist" end |
#full_xpath ⇒ Object
24 25 26 27 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 24 def full_xpath xpath_stack = example_group.instance_variable_get(:@xpath_stack) || [] xpath_stack.join.concat(xpath) end |
#matches?(xml) ⇒ Boolean
12 13 14 |
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 12 def matches?(xml) ::Nokogiri::XML(xml).xpath(full_xpath).count > 0 end |