Class: Merb::Test::Rspec::ViewMatchers::HaveXpath
- Defined in:
- lib/merb-core/test/matchers/view_matchers.rb
Instance Method Summary collapse
-
#failure_message ⇒ Object
Returns String:: The failure message.
-
#initialize(expected, type) ⇒ HaveXpath
constructor
A new instance of HaveXpath.
- #matches?(stringlike) ⇒ Boolean
- #matches_libxml?(stringlike) ⇒ Boolean
- #matches_rexml?(stringlike) ⇒ Boolean
-
#negative_failure_message ⇒ Object
Returns String:: The failure message to be displayed in negative matches.
Constructor Details
#initialize(expected, type) ⇒ HaveXpath
Returns a new instance of HaveXpath.
3 4 5 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 3 def initialize(expected, type) @expected, @type = expected, type end |
Instance Method Details
#failure_message ⇒ Object
Returns
- String
-
The failure message.
41 42 43 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 41 def "expected following text to match xpath #{@expected}:\n#{@document}" end |
#matches?(stringlike) ⇒ Boolean
7 8 9 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 7 def matches?(stringlike) send("matches_#{@type}?", stringlike) end |
#matches_libxml?(stringlike) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 25 def matches_libxml?(stringlike) stringlike = stringlike.body.to_s if stringlike.respond_to?(:body) @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 |
#matches_rexml?(stringlike) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 11 def matches_rexml?(stringlike) stringlike = stringlike.body.to_s if stringlike.respond_to?(:body) @document = case stringlike when REXML::Document stringlike.root when REXML::Node stringlike when StringIO, String REXML::Document.new(stringlike).root end !REXML::XPath.match(@document, @expected).empty? end |
#negative_failure_message ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
47 48 49 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 47 def "expected following text to not match xpath #{@expected}:\n#{@document}" end |