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.



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

def example_group
  @example_group
end

#xpathObject

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_shouldObject



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

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

#failure_message_for_should_notObject



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

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

#full_xpathObject



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

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