Class: RSpecXML::XMLMatchers::HaveXPath::TextMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TextMatcher

Returns a new instance of TextMatcher.



9
10
11
12
# File 'lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb', line 9

def initialize(options={})
  self.xpath = options[:xpath]
  self.text = options[:text]
end

Instance Method Details

#failure_message_for_shouldObject



18
19
20
# File 'lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb', line 18

def failure_message_for_should
  "expected #{xpath} to contain #{text}"
end

#failure_message_for_should_notObject



22
23
24
# File 'lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb', line 22

def failure_message_for_should_not
  "expected #{xpath} to not exist with text: #{text}"
end

#matches?(xml) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb', line 14

def matches?(xml)
  ::Nokogiri::XML(xml).xpath(xpath).text == text
end