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

#descriptionObject



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

def description
  "have xpath #{xpath} with text #{text}"
end

#failure_messageObject



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

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

#failure_message_when_negatedObject



26
27
28
# File 'lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb', line 26

def failure_message_when_negated
  "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).to_a.any? { |e| e.text == text }
end