Tue Aug 7 09:05:05 EST 2007 Matt Palmer * A first, trivial test, to show the general structure of assert_elements tests and to prove that the test suite actually runs diff -rN -u old-testsuite/test/hpricot_test_helper_test.rb new-testsuite/test/hpricot_test_helper_test.rb --- old-testsuite/test/hpricot_test_helper_test.rb 2008-10-20 23:31:06.559867415 +1100 +++ new-testsuite/test/hpricot_test_helper_test.rb 2008-10-20 23:31:06.571878553 +1100 @@ -1,8 +1,50 @@ +RAILS_ENV = 'test' + require 'test/unit' +begin + require 'hpricot' +rescue LoadError => e + begin + require 'rubygems' + require_gem 'hpricot' + rescue LoadError => e + puts "It's hard to test a hpricot test_helper without hpricot." + puts "Please install hpricot ('gem install hpricot') and try again." + exit 0 + end +end + +load File.dirname(__FILE__) + '/../init.rb' + +# Define this ourselves to avoid faffing around with including all of +# activesupport. +class Symbol + def to_proc + Proc.new { |*args| args.shift.__send__(self, *args) } + end +end class HpricotTestHelperTest < Test::Unit::TestCase - # Replace this with your real tests. - def test_this_plugin - flunk - end + class AssertElementsController + attr_accessor :body + end + + def setup + @response = AssertElementsController.new + end + + def assert_failure(message, &block) + e = assert_raise(Test::Unit::AssertionFailedError, &block) + assert_match(message, e.message) if Regexp === message + assert_equal(message, e.message) if String === message + end + + def test_trivial_assert_element + @response.body = "Foo" + + assert_elements("//title") + assert_equal "Foo", tag("//title") + assert_equal "Foo", element("//title").inner_html + assert_failure(/./) { assert_elements("//h1") } + end end