Class: RSpecXML::XMLMatchers::HaveXPath::Matcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  self.xpath = options[:xpath]
  self.example_group = options[:example_group]
end

Instance Attribute Details

#example_groupObject

Returns the value of attribute example_group.



33
34
35
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 33

def example_group
  @example_group
end

#xpathObject

Returns the value of attribute xpath.



33
34
35
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 33

def xpath
  @xpath
end

Instance Method Details

#descriptionObject



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

def description
  "have xpath #{full_xpath}"
end

#failure_messageObject



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

def failure_message
  "expected #{full_xpath} to exist"
end

#failure_message_when_negatedObject



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

def failure_message_when_negated
  "expected #{full_xpath} to not exist"
end

#full_xpathObject



28
29
30
31
# File 'lib/rspec-xml/xml_matchers/have_xpath/matcher.rb', line 28

def full_xpath
  xpath_stack = example_group.instance_variable_get(:@xpath_stack) || []
  xpath_stack.join.concat(xpath)
end

#matches?(xml) ⇒ Boolean

Returns:

  • (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