Module: Merb::Test::Rspec::ViewMatchers
- Defined in:
- lib/merb-core/test/matchers/view_matchers.rb
Defined Under Namespace
Classes: HasContent, HasTag, HaveSelector, HaveXpath, MatchTag, NotMatchTag
Instance Method Summary collapse
- #contain(content) ⇒ Object
-
#have_selector(expected) ⇒ Object
(also: #match_selector)
Parameters expected<String>:: The string to look for.
-
#have_tag(tag, attributes = {}, &blk) ⇒ Object
(also: #with_tag)
RSpec matcher to test for the presence of tags.
- #have_xpath(expected) ⇒ Object (also: #match_xpath)
-
#match_tag(name, attrs = {}) ⇒ Object
Parameters name<~to_s>:: The name of the tag to look for.
-
#not_match_tag(attrs) ⇒ Object
Parameters attrs<Hash>:: A set of attributes that must not be matched.
Instance Method Details
#contain(content) ⇒ Object
372 373 374 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 372 def contain(content) HasContent.new(content) end |
#have_selector(expected) ⇒ Object Also known as: match_selector
Parameters
- expected<String>
-
The string to look for.
Returns
- HaveSelector
-
A new have selector matcher.
330 331 332 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 330 def have_selector(expected) HaveSelector.new(expected) end |
#have_tag(tag, attributes = {}, &blk) ⇒ Object Also known as: with_tag
RSpec matcher to test for the presence of tags.
Parameters
- tag<~to_s>
-
The name of the tag.
- attributes<Hash>
-
Tag attributes.
Returns
- HasTag
-
A new has tag matcher.
Examples
# Check for <div>
body.should have_tag("div")
# Check for <span id="notice">
body.should have_tag("span", :id => :notice)
# Check for <h1 id="foo" class="bar">
body.should have_tag(:h2, :class => "bar", :id => "foo")
# Check for <div attr="val">
body.should have_tag(:div, :attr => :val)
366 367 368 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 366 def have_tag(tag, attributes = {}, &blk) HasTag.new(tag, attributes, &blk) end |
#have_xpath(expected) ⇒ Object Also known as: match_xpath
335 336 337 338 339 340 341 342 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 335 def have_xpath(expected) begin require "libxml" rescue LoadError => e puts "To use have_xpath helper you need to install libxml-ruby gem" end HaveXpath.new(expected) end |
#match_tag(name, attrs = {}) ⇒ Object
Parameters
- name<~to_s>
-
The name of the tag to look for.
- attrs<Hash>
-
Attributes to look for in the tag (see below).
Options (attrs)
- :content<String>
-
Optional content to match.
Returns
- MatchTag
-
A new match tag matcher.
312 313 314 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 312 def match_tag(name, attrs={}) MatchTag.new(name, attrs) end |
#not_match_tag(attrs) ⇒ Object
Parameters
- attrs<Hash>
-
A set of attributes that must not be matched.
Returns
- NotMatchTag
-
A new not match tag matcher.
321 322 323 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 321 def not_match_tag(attrs) NotMatchTag.new(attrs) end |