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 (
| name | age | message | |
|---|---|---|---|
| |
CHANGELOG | ||
| |
MIT-LICENSE | Thu Jun 19 13:36:30 -0700 2008 | |
| |
README.markdown | ||
| |
Rakefile | Thu Jun 19 13:36:30 -0700 2008 | |
| |
about.yml | ||
| |
generators/ | ||
| |
init.rb | Fri Jun 20 12:35:26 -0700 2008 | |
| |
lib/ | ||
| |
tasks/ | ||
| |
test/ |
README.markdown
Helper Me Test
Providing quick and easy ways to create and write tests for your Rails helpers.
Features
Assertions / Test Helper Methods
- Tag Assertions:
assert_tag_inandassert_tag_not_inmirror theassert_tagmethod built into Rails. They work with the same option, only that they need a target string as the first parameter.
- Selector Assertion:
assert_select_inworks almost identically toassert_selectdoes in Rails. It allows for a CSS selector to be matched against a HTML string target. It also accepts an equality expression and can be nested likeassert_select.
- Hpricot Assertion:
assert_hpricot_in, andassert_hpricot_not_intest that a given CSS or XPath expression can be found in an HTML string. See Hpricot documentation for details.
Generators
- Helper Test Generator:
- Usage:
script/generate helper_tests [SampleHelper Admin::AnotherHelper ...]
- Creates helper tests for each helper you currently have, creating one test for each public method in the module. If you instead pass it a space separated set of helper module names you'll only generate tests for those.
- You can also pass it an option of
--skip-method-testsand it won't create tests for each of the helper methods.
- Usage:
- Helper Generator:
- Usage:
script/generate helper HelperName [methods ...]
- Creates a helper based on a camelcased or underscored name, and a test file for it. It will also accept a list of method names and create methods for each of them and a test for each of the methods.
- Usage:
Rake Tasks
I've also provided a rake task for running the generated helper tests, rake test:helpers
and changed the rake test task to run that test task in a addition to the other
test tasks.
Examples
Using Tag Assertions:
def test_some_html_string_with_assert_tag_in
html = "<div><ul id="list"><li>one</li><li>two</li></ul><p id="content">hello world</p></div>"
assert_tag_in html, :ul, :attributes => {:id => 'list'}, :child => {:tag => 'li'}
assert_tag_in html, :p
end
Using Selector Assertions:
def test_some_html_string_with_assert_select_in
html = "<div><ul id="list"><li>one</li><li>two</li></ul><p id="content">hello world</p></div>"
assert_select_in html 'ul#list' do
assert_select_in 'li'
end
assert_select_in html,'p#content', 'hello world'
end
Using Hpricot Methods
def test_some_html_string_with_assert_hpricot_in
html = "<div><ul id="list"><li>one</li><li>two</li></ul><p id="content">hello world</p></div>"
assert_hpricot_in html, 'ul[@id="list"][li="one"]'
assert_hpricot_in html, 'p[@id="content"]'
end
Additional Documentation
License
Copyright (c) 2008 Brian Landau of Viget Labs, released under the MIT license








