danreedy / rspec-html-matchers

Old school have_tag, with_tag(and more) matchers for rspec 2 (Nokogiri powered)

Home Page:http://rubygems.org/gems/rspec-html-matchers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test views, be true! :) Build Status

Mikhalok

Why?

  • you need to test some complex views
  • and you want to use RSpec2
  • and assert_select seems is something strange to you
  • have_tag in rspec-rails are deprecated now
  • you need a user-firendly output in your error messages

Being true

Install

Add to your Gemfile (in the :test group :) ):

group :test do
  gem 'rspec-html-matchers'
end

Instructions for installing Nokogiri.

Usage

Simple example:

view=<<-HTML
<h1>Simple Form</h1>
<form action="/users" method="post">
<p>
  <input type="email" name="user[email]" />
</p>
<p>
  <input type="submit" id="special_submit" />
</p>
</form>
HTML

view.should have_tag('form', :with => { :action => '/users', :method => 'post' }) do
  with_tag "input", :with => { :name => "user[email]", :type => 'email' }
  with_tag "input#special_submit", :count => 1
  without_tag "h1", :text => 'unneeded tag'
  without_tag "p",  :text => /content/i
end

Also included special matchers for form inputs:

and of course you can use the without_ matchers (see the documentation).

More info

You can find more on RubyDoc, take a look at {RSpec::Matchers#have_tag have_tag} method.

Also, please read {file:CHANGELOG.md CHANGELOG}, it might be helpful.

Contribution

  1. Fork the repository
  2. Add tests for your feature
  3. Write the code
  4. Send a pull request

Contributors

MIT Licensed

Copyright (c) 2011 Dmitry Mjakotny

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Old school have_tag, with_tag(and more) matchers for rspec 2 (Nokogiri powered)

http://rubygems.org/gems/rspec-html-matchers


Languages

Language:Ruby 100.0%