github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

vigetlabs / helper_me_test

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (1)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (1)
    • 2.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Providing quick and easy ways to create and write tests for your Rails helpers. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Slim down assert_select_in 
brianjlandau (author)
Tue Feb 03 16:43:43 -0800 2009
commit  ee339bbedfa7b36859503b28008497ba9afc6837
tree    7b4d585e2cea68b730626b131f45676cedab51b5
parent  3e1c54dd6cb1a994fa21127b759c90cd04821c88
helper_me_test /
name age
history
message
file CHANGELOG Tue Feb 03 16:43:43 -0800 2009 Slim down assert_select_in [brianjlandau]
file MIT-LICENSE Thu Jun 19 13:36:30 -0700 2008 initial commit of base plugin [brianjlandau]
file README.markdown Thu Jul 03 12:59:33 -0700 2008 Add option to not make tests for the helper met... [brianjlandau]
file Rakefile Thu Jun 19 13:36:30 -0700 2008 initial commit of base plugin [brianjlandau]
file about.yml Tue Feb 03 16:43:43 -0800 2009 Slim down assert_select_in [brianjlandau]
directory generators/ Thu Jul 03 12:59:33 -0700 2008 Add option to not make tests for the helper met... [brianjlandau]
file init.rb Fri Jun 20 12:35:26 -0700 2008 Add helper generator and flesh out helper test ... [brianjlandau]
directory lib/ Tue Feb 03 16:43:43 -0800 2009 Slim down assert_select_in [brianjlandau]
directory tasks/ Thu Jul 03 12:28:20 -0700 2008 Add rake tasks for helper tests, and modify Rai... [brianjlandau]
directory test/ Tue Feb 03 16:43:43 -0800 2009 Slim down assert_select_in [brianjlandau]
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_in and assert_tag_not_in mirror the assert_tag method built into Rails. They work with the same option, only that they need a target string as the first parameter.
  • Selector Assertion:
    • assert_select_in works almost identically to assert_select does 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 like assert_select.
  • Hpricot Assertion:
    • assert_hpricot_in, and assert_hpricot_not_in test 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-tests and it won't create tests for each of the helper methods.
  • 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.

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

  • assert_tag RDoc
  • assert_select RDoc
  • Hpricot Tutorial
  • Hpricot RDoc

License

Copyright (c) 2008 Brian Landau of Viget Labs, released under the MIT license

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server