Created
March 3, 2010 00:28
-
-
Save jamesarosen/320157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails' assert_select rocks for testing generated markup, | |
# but it assumes you've just rendered a view. If you want | |
# to use it in a plain ole' unit test, try adding the | |
# following to your test_helper.rb. | |
# | |
# Tip o' the Hat to Erik Ostrom for the basic idea: | |
# http://www.echographia.com/blog/2009/08/22/assert_select-from-arbitrary-text/ | |
require 'action_controller' | |
Test::Unit::TestCase.class_eval do | |
include ActionController::Assertions::SelectorAssertions | |
# Supports assert_select without having to render a view. | |
# Usage: | |
# assert_select_from some_html 'ul#foo' do | |
# assert_select 'li.bar' | |
# end | |
def assert_select_from(text, *args, &block) | |
@selected = HTML::Document.new(text).root.children | |
assert_select(*args, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment