This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 94073fc5cf9d7b7101be05df1dde030c53031b79
tree 563844b936323251651773d328d661039fdd2091
parent c105a68f1ae84f191912ab875dfd620456602115
tree 563844b936323251651773d328d661039fdd2091
parent c105a68f1ae84f191912ab875dfd620456602115
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Tue May 27 13:41:44 -0700 2008 | [btakita] |
| |
MIT-LICENSE | Tue Mar 04 16:48:48 -0800 2008 | [pd] |
| |
README | Mon Mar 31 04:55:56 -0700 2008 | [pd] |
| |
Rakefile | Wed Mar 26 12:05:48 -0700 2008 | [pd] |
| |
lib/ | Wed May 28 07:25:07 -0700 2008 | [pd] |
| |
spec/ | Tue May 27 13:41:57 -0700 2008 | [btakita] |
README
= rspec_hpricot_matchers
An implementation of have_tag(), as in rspec_on_rails, but sitting atop
Hpricot rather than merely wrapping assert_select().
== Installation
To use rspec_hpricot_matchers in your project, install the gem, and
add the following to your spec_helper.rb file:
require 'rspec_hpricot_matchers'
Spec::Runner.configure do |config|
config.include(RspecHpricotMatchers)
end
Similarly, to make the matchers available to stories, you can add the
following to your stories/helper.rb file:
require 'rspec_hpricot_matchers'
include RspecHpricotMatchers
== Usage
As its first argument, have_tag() accepts any CSS or XPath selectors
which are supported by Hpricot.
body.should have_tag('form[@action*=session]')
body.should have_tag('ul > li + li')
Expectations can be placed upon the inner text of the matched element
by providing another argument, which should be either a String or a
Regexp:
body.should have_tag('h1', 'Welcome')
body.should have_tag('p', /a very important blurb/i)
Expectations can be placed upon the number of matched elements by
passing an options hash:
body.should have_tag('abbr', :count => 1) # exactly one
body.should have_tag('dt', :minimum => 4) # at least 4
body.should have_tag('dd', :maximum => 4) # at most 4
body.should have_tag('a.outgoing', /rspec/i, :count => 2)
The :count key also accepts a Range, making the following equivalent:
body.should have_tag('tr', :count => 3..5)
body.should have_tag('tr', :minimum => 3,
:maximum => 5)
The usage of with_tag(), however, is no longer supported. Instead, a
block passed to have_tag() will have each matched element successively
yielded to it. If none of the blocks return without raising an
ExpectationNotMetError, the outer have_tag() is treated as having failed:
body.should have_tag('thead') do |thead|
thead.should have_tag('th', :count => 5)
end
This also allows arbitrary expectations to be applied from within
the block, such as:
body.should have_tag('dl dd.sha1') do |dd|
dd.inner_text.length.should == 40
end
== Notes
Currently, this implementation does not support substitution values
as assert_select did (by way of HTML::Selector):
# Not yet supported:
body.should have_tag('li[class=?]', dom_class)
body.should have_tag('tr.person#?', /^person-\d+$/)
I personally rarely use these, and Hpricot's advanced selectors make
them mostly useless, as far as I can tell, so I am unlikely to
implement them myself.
This have_tag() further differs from the assert_select-based
implementation in that the nested have_tag() calls must *all* pass
on a single selected element in order to be true. This was a source
of confusion in RSpec ticket #316. There is a spec covering this
case if you need an example.




