Class: Merb::Test::Rspec::ViewMatchers::HaveXpath

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/test/matchers/view_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveXpath

Returns a new instance of HaveXpath.



3
4
5
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 3

def initialize(expected)
  @expected = expected
end

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



21
22
23
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 21

def failure_message
  "expected following text to match xpath #{@expected}:\n#{@document}"
end

#matches?(stringlike) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 7

def matches?(stringlike)
  @document = case stringlike
  when LibXML::XML::Document, LibXML::XML::Node
    stringlike
  when StringIO
    LibXML::XML::HTMLParser.string(stringlike.string).parse
  else
    LibXML::XML::HTMLParser.string(stringlike).parse
  end
  !@document.find(@expected).empty?
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



27
28
29
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 27

def negative_failure_message
  "expected following text to not match xpath #{@expected}:\n#{@document}"
end