Skip to content

Instantly share code, notes, and snippets.

@haikuwebdev
Created January 26, 2009 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save haikuwebdev/52976 to your computer and use it in GitHub Desktop.
Save haikuwebdev/52976 to your computer and use it in GitHub Desktop.
require 'test_helper'
class MyHelperTest < ActionView::TestCase
test "title" do
assert_select_in '<h1>My Awesome App</h1>', 'h1'
end
test "nav" do
html = '<div id="nav"><a href="/">Home</a></div>'
assert_select_in html, 'div' do
assert_select 'a', /home/i
end
end
end
# A more flexible and elegant solution can be found here:
# http://github.com/vigetlabs/helper_me_test/tree/master
# Add this to the bottom of your test_helper.rb
module HelpersSelectorAsssertions
def assert_select_in(html, *args, &block)
node = HTML::Document.new(html).root
assert_select(*args.unshift(node), &block)
end
end
ActionView::TestCase.send(:include, HelpersSelectorAsssertions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment