$:.unshift File.dirname(File.expand_path($0)).gsub!(%r#[^/]+$#,'') + "lib" Dir.chdir( File.dirname($0) ) require 'html/fillinform' require 'test/unit' class FillInFormTest < Test::Unit::TestCase def setup fp = open('form.html') @html = fp.read fp.close end def test_target fif = HTML::FillInForm.new(@html) hash = {'username' => 'foobar'} assert_match(%r//i, fif.fill(hash,'form5')) end def test_text fif = HTML::FillInForm.new(@html) hash = { "username" => "bar", "password" => "baz", "submit" => nil, } assert_match( %r//i, fif.fill(hash) ) assert_match( %r//i, fif.fill(hash) ) end def test_submit fif = HTML::FillInForm.new(@html) hash = {} assert_match( %r//i, fif.fill(hash) ) end def test_backward assert_nothing_raised(LoadError){ require 'html/fillform' } fif = HTML::FillForm.new(@html) hash = { "username" => "baz" } assert_match( %r//i, fif.fill(hash) ) end def test_checkbox fif = HTML::FillInForm.new(@html) hash = {"hoge" => ["fuga"]} fif.fill(hash) assert_match( %r//i, fif.output ) assert_match( %r//i, fif.output ) assert_match( %r//i, fif.output ) end def test_escape fif = HTML::FillInForm.new(@html) hash = { "textbox" => %Q(foobar), # textarea "username" => %Q(username) # type="text" } assert_match(%r(<font size="1">foobar</font>),fif.fill(hash)); assert_match(%r(<font size="3">username</font>),fif.output); end def test_option fif = HTML::FillInForm.new(@html) hash = {"selector" => "Ruby"} output = fif.fill(hash) assert_match( %r/