mechanize-2.7.2/ 0000755 0000041 0000041 00000000000 12222372210 013506 5 ustar www-data www-data mechanize-2.7.2/.travis.yml 0000644 0000041 0000041 00000000670 12222372210 015622 0 ustar www-data www-data ---
after_script:
- rake travis:after -t
before_script:
- gem install hoe-travis --no-rdoc --no-ri
- rake travis:before -t
language: ruby
notifications:
email:
- drbrain@segment7.net
- ljjarvis@gmail.com
- knu@idaemons.org
rvm:
- 1.9.3
- 2.0.0
- ruby-head
- jruby-19mode
- jruby-head
- rbx-19mode
script: rake travis
matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby-19mode
- rvm: jruby-head
- rvm: rbx-19mode
mechanize-2.7.2/test/ 0000755 0000041 0000041 00000000000 12222372210 014465 5 ustar www-data www-data mechanize-2.7.2/test/test_mechanize_page_image.rb 0000644 0000041 0000041 00000013156 12222372210 022160 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizePageImage < Mechanize::TestCase
def setup
super
@uri = URI 'http://example/'
@src = (@uri + 'a.jpg').to_s
@empty_page = Mechanize::Page.new(@uri, nil, '', 200, @mech)
end
def img attributes
img = node 'img', attributes
Mechanize::Page::Image.new img, @empty_page
end
def test_initialize
image = img("src" => "a.jpg", "alt" => "alt", "width" => "100",
"height" => "200", "title" => "title", "id" => "id",
"class" => "class")
assert_equal "a.jpg", image.src
assert_equal "alt", image.alt
assert_equal "100", image.width
assert_equal "200", image.height
assert_equal "title", image.title
assert_equal "id", image.dom_id
assert_equal "class", image.dom_class
end
def test_initialize_no_attributes
image = img({})
assert_nil image.src
assert_nil image.alt
assert_nil image.width
assert_nil image.height
assert_nil image.title
assert_nil image.dom_id
assert_nil image.dom_class
end
def test_caption
assert_equal "", img("src" => @src).caption
assert_equal "alt", img("src" => @src, "alt" => "alt").caption
assert_equal "title", img("src" => @src, "title" => "title").caption
assert_equal "title", img("src" => @src,
"alt" => "alt", "title" => "title").caption
end
def test_url
assert_equal ".jpg", img('src' => @src).extname
assert_equal "http://example/a.jpg", img('src' => @src).url.to_s
assert_equal "http://example/a%20.jpg", img('src' => 'http://example/a .jpg' ).url.to_s
end
def test_url_base
page = html_page <<-BODY
BODY
assert_equal "http://other.example/a.jpg", page.images.first.url
end
def test_extname
assert_equal ".jpg", img("src" => "a.jpg").extname
assert_equal ".PNG", img("src" => "a.PNG").extname
assert_equal ".aaa", img("src" => "unknown.aaa").extname
assert_equal "", img("src" => "nosuffiximage").extname
assert_nil img("width" => "1", "height" => "1").extname
assert_equal ".jpg", img("src" => "a.jpg?cache_buster").extname
end
def test_mime_type
assert_equal "image/jpeg", img("src" => "a.jpg").mime_type
assert_equal "image/png", img("src" => "a.PNG").mime_type
assert_nil img("src" => "unknown.aaa").mime_type
assert_nil img("src" => "nosuffiximage").mime_type
end
def test_fetch
image = img "src" => "http://localhost/button.jpg"
fetched = image.fetch
assert_equal fetched, @mech.page
assert_equal "http://localhost/button.jpg", fetched.uri.to_s
assert_equal "http://example/", requests.first['Referer']
assert @mech.visited? "http://localhost/button.jpg"
end
def test_fetch_referer_http_page_rel_src
# | rel-src http-src https-src
# http page | *page* page page
# https page | page empty empty
page = html_page '
'
page.images.first.fetch
assert_equal 'http', page.uri.scheme
assert_equal true, page.images.first.relative?
assert_equal "http://example/", requests.first['Referer']
end
def test_fetch_referer_http_page_abs_src
# | rel-src http-src https-src
# http page | page *page* *page*
# https page | page empty empty
page = html_page '
'
page.images.first.fetch
assert_equal 'http', page.uri.scheme
assert_equal false, page.images.first.relative?
assert_equal "http://example/", requests.first['Referer']
end
def test_fetch_referer_https_page_rel_src
# | rel-src http-src https-src
# http page | page page page
# https page | *page* empty empty
page = html_page '
'
page.uri = URI 'https://example/'
page.images.first.fetch
assert_equal 'https', page.uri.scheme
assert_equal true, page.images.first.relative?
assert_equal "https://example/", requests.first['Referer']
end
def test_fetch_referer_https_page_abs_src
# | rel-src http-src https-src
# http page | page page page
# https page | page *empty* *empty*
page = html_page '
'
page.uri = URI 'https://example/'
page.images.first.fetch
assert_equal 'https', page.uri.scheme
assert_equal false, page.images.first.relative?
assert_equal nil, requests.first['Referer']
end
def test_image_referer_http_page_abs_src
page = html_page '
'
assert_equal 'http', page.uri.scheme
assert_equal @uri, page.images.first.image_referer.uri
end
def test_image_referer_http_page_rel_src
page = html_page '
'
assert_equal 'http', page.uri.scheme
assert_equal @uri, page.images.first.image_referer.uri
end
def test_image_referer_https_page_abs_src
page = html_page '
'
page.uri = URI 'https://example/'
assert_equal 'https', page.uri.scheme
assert_nil page.images.first.image_referer.uri
end
def test_image_referer_https_page_rel_src
page = html_page '
'
page.uri = URI 'https://example/'
assert_equal 'https', page.uri.scheme
assert_equal URI('https://example/'), page.images.first.image_referer.uri
end
def test_no_src_attribute
page = html_page '
'
page.uri = URI 'https://example/'
assert_equal URI('https://example/'), page.images.first.url
end
end
mechanize-2.7.2/test/test_mechanize_xml_file.rb 0000644 0000041 0000041 00000001077 12222372210 021700 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeXmlFile < Mechanize::TestCase
def setup
super
uri = URI 'http://example.com/foo.xml'
@xml = Mechanize::XmlFile.new uri, nil, <<-XML
Ruby
Perl
XML
end
def test_xml
assert_kind_of Nokogiri::XML::Document, @xml.xml
end
def test_search
assert_equal ['Ruby', 'Perl'], @xml.search('language').map { |n| n.text }
end
def test_at
assert_equal 'Perl', @xml.at('//language[2]').text
end
end mechanize-2.7.2/test/test_mechanize_redirect_limit_reached_error.rb 0000644 0000041 0000041 00000000661 12222372210 025762 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeRedirectLimitReachedError < Mechanize::TestCase
def setup
super
@error = Mechanize::RedirectLimitReachedError.new fake_page, 10
end
def test_message
assert_equal 'Redirect limit of 10 reached', @error.message
end
def test_redirects
assert_equal 10, @error.redirects
end
def test_response_code
assert_equal 200, @error.response_code
end
end
mechanize-2.7.2/test/test_mechanize_util.rb 0000644 0000041 0000041 00000006270 12222372210 021056 0 ustar www-data www-data # coding: utf-8
require 'mechanize/test_case'
class TestMechanizeUtil < Mechanize::TestCase
INPUTTED_VALUE = "ใในใ" # "test" in Japanese UTF-8 encoding
CONTENT_ENCODING = 'Shift_JIS' # one of Japanese encoding
ENCODED_VALUE = "\x83\x65\x83\x58\x83\x67" # "test" in Japanese Shift_JIS encoding
if Mechanize::Util::NEW_RUBY_ENCODING
ENCODING_ERRORS = [EncodingError, Encoding::ConverterNotFoundError] # and so on
ERROR_LOG_MESSAGE = /from_native_charset: Encoding::ConverterNotFoundError: form encoding: "UTF-eight"/
ENCODED_VALUE.force_encoding(::Encoding::SHIFT_JIS)
else
ENCODING_ERRORS = [Iconv::InvalidEncoding, Iconv::IllegalSequence]
ERROR_LOG_MESSAGE = /from_native_charset: Iconv::InvalidEncoding: form encoding: "UTF-eight"/
end
INVALID_ENCODING = 'UTF-eight'
def setup
super
@MU = Mechanize::Util
@result = "not set"
end
def test_from_native_charset
@result = @MU.from_native_charset(INPUTTED_VALUE, CONTENT_ENCODING)
assert_equal ENCODED_VALUE, @result
end
def test_from_native_charset_returns_nil_when_no_string
@result = @MU.from_native_charset(nil, CONTENT_ENCODING)
assert_equal nil, @result
end
def test_from_native_charset_doesnot_convert_when_no_encoding
@result = @MU.from_native_charset(INPUTTED_VALUE, nil)
refute_equal ENCODED_VALUE, @result
assert_equal INPUTTED_VALUE, @result
end
def test_from_native_charset_doesnot_convert_when_not_nokogiri
parser = Mechanize.html_parser
Mechanize.html_parser = 'Another HTML Parser'
@result = @MU.from_native_charset(INPUTTED_VALUE, CONTENT_ENCODING)
refute_equal ENCODED_VALUE, @result
assert_equal INPUTTED_VALUE, @result
ensure
Mechanize.html_parser = parser
end
def test_from_native_charset_raises_error_with_bad_encoding
assert_raises(*ENCODING_ERRORS) do
@MU.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING)
end
end
def test_from_native_charset_suppress_encoding_error_when_3rd_arg_is_true
@MU.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true)
# HACK no assertion
end
def test_from_native_charset_doesnot_convert_when_encoding_error_raised_and_ignored
@result = @MU.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true)
refute_equal ENCODED_VALUE, @result
assert_equal INPUTTED_VALUE, @result
end
def test_from_native_charset_logs_form_when_encoding_error_raised
sio = StringIO.new("")
log = Logger.new(sio)
log.level = Logger::DEBUG
assert_raises(*ENCODING_ERRORS) do
@MU.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, nil, log)
end
assert_match ERROR_LOG_MESSAGE, sio.string
end
def test_from_native_charset_logs_form_when_encoding_error_is_ignored
sio = StringIO.new("")
log = Logger.new(sio)
log.level = Logger::DEBUG
@MU.from_native_charset(INPUTTED_VALUE, INVALID_ENCODING, true, log)
assert_match ERROR_LOG_MESSAGE, sio.string
end
def test_self_html_unescape_entity
assert_equal '&', @MU::html_unescape('&')
assert_equal '&', @MU::html_unescape('&')
end
def test_uri_escape
assert_equal "%25", @MU.uri_escape("%")
assert_equal "%", @MU.uri_escape("%", /[^%]/)
end
end
mechanize-2.7.2/test/test_mechanize_http_www_authenticate_parser.rb 0000644 0000041 0000041 00000007743 12222372210 026104 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeHttpWwwAuthenticateParser < Mechanize::TestCase
def setup
super
@parser = Mechanize::HTTP::WWWAuthenticateParser.new
end
def test_auth_param
@parser.scanner = StringScanner.new 'realm=here'
param = @parser.auth_param
assert_equal %w[realm here], param
end
def test_auth_param_bad_no_value
@parser.scanner = StringScanner.new 'realm='
assert_nil @parser.auth_param
end
def test_auth_param_bad_token
@parser.scanner = StringScanner.new 'realm'
assert_nil @parser.auth_param
end
def test_auth_param_bad_value
@parser.scanner = StringScanner.new 'realm="this '
assert_nil @parser.auth_param
end
def test_auth_param_quoted
@parser.scanner = StringScanner.new 'realm="this site"'
param = @parser.auth_param
assert_equal ['realm', 'this site'], param
end
def test_parse
expected = [
challenge('Basic', { 'realm' => 'foo', 'qop' => 'auth,auth-int' }, 'Basic realm=foo, qop="auth,auth-int"'),
]
assert_equal expected, @parser.parse('Basic realm=foo, qop="auth,auth-int"')
end
def test_parse_without_comma_delimiter
expected = [
challenge('Basic', { 'realm' => 'foo', 'qop' => 'auth,auth-int' }, 'Basic realm=foo qop="auth,auth-int"'),
]
assert_equal expected, @parser.parse('Basic realm=foo qop="auth,auth-int"')
end
def test_parse_multiple
expected = [
challenge('Basic', { 'realm' => 'foo' }, 'Basic realm=foo'),
challenge('Digest', { 'realm' => 'bar' }, 'Digest realm=bar'),
]
assert_equal expected, @parser.parse('Basic realm=foo, Digest realm=bar')
end
def test_parse_multiple_without_comma_delimiter
expected = [
challenge('Basic', { 'realm' => 'foo' }, 'Basic realm=foo'),
challenge('Digest', { 'realm' => 'bar' }, 'Digest realm=bar'),
]
assert_equal expected, @parser.parse('Basic realm=foo Digest realm=bar')
end
def test_parse_multiple_blank
expected = [
challenge('Basic', { 'realm' => 'foo' }, 'Basic realm=foo'),
challenge('Digest', { 'realm' => 'bar' }, 'Digest realm=bar'),
]
assert_equal expected, @parser.parse('Basic realm=foo,, Digest realm=bar')
end
def test_parse_ntlm_init
expected = [
challenge('NTLM', nil, 'NTLM'),
]
assert_equal expected, @parser.parse('NTLM')
end
def test_parse_ntlm_type_2_3
expected = [
challenge('NTLM', 'foo=', 'NTLM foo='),
]
assert_equal expected, @parser.parse('NTLM foo=')
end
def test_parse_realm_uppercase
expected = [
challenge('Basic', { 'realm' => 'foo' }, 'Basic ReAlM=foo'),
]
assert_equal expected, @parser.parse('Basic ReAlM=foo')
end
def test_parse_scheme_uppercase
expected = [
challenge('Basic', { 'realm' => 'foo' }, 'BaSiC realm=foo'),
]
assert_equal expected, @parser.parse('BaSiC realm=foo')
end
def test_quoted_string
@parser.scanner = StringScanner.new '"text"'
string = @parser.quoted_string
assert_equal 'text', string
end
def test_quoted_string_bad
@parser.scanner = StringScanner.new '"text'
assert_nil @parser.quoted_string
end
def test_quoted_string_quote
@parser.scanner = StringScanner.new '"escaped \\" here"'
string = @parser.quoted_string
assert_equal 'escaped \\" here', string
end
def test_quoted_string_quote_end
@parser.scanner = StringScanner.new '"end \""'
string = @parser.quoted_string
assert_equal 'end \"', string
end
def test_token
@parser.scanner = StringScanner.new 'text'
string = @parser.token
assert_equal 'text', string
end
def test_token_space
@parser.scanner = StringScanner.new 't ext'
string = @parser.token
assert_equal 't', string
end
def test_token_special
@parser.scanner = StringScanner.new "t\text"
string = @parser.token
assert_equal 't', string
end
def challenge scheme, params, raw
Mechanize::HTTP::AuthChallenge.new scheme, params, raw
end
end
mechanize-2.7.2/test/test_multi_select.rb 0000644 0000041 0000041 00000010214 12222372210 020540 0 ustar www-data www-data require 'mechanize/test_case'
class MultiSelectTest < Mechanize::TestCase
def setup
super
@page = @mech.get("http://localhost/form_multi_select.html")
@form = @page.forms.first
end
def test_option_with
o = @form.field_with(:name => 'list').option_with(:value => '1')
assert_equal '1', o.value
end
def test_options_with
os = @form.field_with(:name => 'list').options_with(:value => /1|2/)
assert_equal ['1', '2'].sort, os.map { |x| x.value }.sort
end
def test_select_none
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.field_with(:name => 'list').select_none
page = @mech.submit(form)
assert_equal(0, page.links.length)
end
def test_select_all
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.field_with(:name => 'list').select_all
page = @mech.submit(form)
assert_equal(6, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:2').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
assert_equal(1, page.links_with(:text => 'list:4').length)
assert_equal(1, page.links_with(:text => 'list:5').length)
assert_equal(1, page.links_with(:text => 'list:6').length)
end
def test_click_all
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.field_with(:name => 'list').options.each { |o| o.click }
page = @mech.submit(form)
assert_equal(5, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
assert_equal(1, page.links_with(:text => 'list:4').length)
assert_equal(1, page.links_with(:text => 'list:5').length)
assert_equal(1, page.links_with(:text => 'list:6').length)
end
def test_select_default
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
page = @mech.submit(form)
assert_equal(1, page.links.length)
assert_equal(1, page.links_with(:text => 'list:2').length)
end
def test_select_one
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = 'Aaron'
assert_equal(['Aaron'], form.list)
page = @mech.submit(form)
assert_equal(1, page.links.length)
assert_equal('list:Aaron', page.links.first.text)
end
def test_select_two
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', 'Aaron']
page = @mech.submit(form)
assert_equal(2, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:Aaron').length)
end
def test_select_three
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', '2', '3']
page = @mech.submit(form)
assert_equal(3, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:2').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
end
def test_select_three_twice
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', '2', '3']
form.list = ['1', '2', '3']
page = @mech.submit(form)
assert_equal(3, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:2').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
end
def test_select_with_click
page = @mech.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', 'Aaron']
form.field_with(:name => 'list').options[3].tick
assert_equal(['1', 'Aaron', '4'].sort, form.list.sort)
page = @mech.submit(form)
assert_equal(3, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:Aaron').length)
assert_equal(1, page.links_with(:text => 'list:4').length)
end
end
mechanize-2.7.2/test/test_mechanize_form.rb 0000644 0000041 0000041 00000073641 12222372210 021052 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeForm < Mechanize::TestCase
def setup
super
@uri = URI 'http://example'
@page = page @uri
@form = Mechanize::Form.new node('form', 'name' => @NAME), @mech, @page
end
def test_action
form = Mechanize::Form.new node('form', 'action' => '?a=b&b=c')
assert_equal '?a=b&b=c', form.action
end
def test_add_button_to_query
button = Mechanize::Form::Button.new node('input', 'type' => 'submit')
e = assert_raises ArgumentError do
@form.add_button_to_query button
end
assert_equal "#{button.inspect} does not belong to the same page " \
"as the form \"#{@NAME}\" in #{@uri}",
e.message
end
def test_aset
assert_empty @form.keys
@form['intarweb'] = 'Aaron'
assert_equal 'Aaron', @form['intarweb']
end
def test_aset_exists
page = html_page <<-BODY
Page Title
BODY
form = page.form_with(:name => 'post_form')
assert_equal %w[first first], form.keys
form['first'] = 'Aaron'
assert_equal 'Aaron', form['first']
assert_equal ['Aaron', ''], form.values
end
def test_build_query_blank_form
page = @mech.get('http://localhost/tc_blank_form.html')
form = page.forms.first
query = form.build_query
assert(query.length > 0)
assert query.all? { |x| x[1] == '' }
end
def test_build_query_radio_button_duplicate
html = Nokogiri::HTML <<-HTML
HTML
form = Mechanize::Form.new html.at('form'), @mech, @page
query = form.build_query
assert_equal [%w[name a]], query
end
def test_build_query_radio_button_multiple_checked
html = Nokogiri::HTML <<-HTML
HTML
form = Mechanize::Form.new html.at('form'), @mech, @page
e = assert_raises Mechanize::Error do
form.build_query
end
assert_equal 'radiobuttons "a, b" are checked in the "name" group, ' \
'only one is allowed',
e.message
end
def test_method_missing_get
page = html_page <<-BODY
BODY
form = page.forms.first
assert_equal 'some value', form.not_a_method
end
def test_method_missing_set
page = html_page <<-BODY
BODY
form = page.forms.first
form.not_a_method = 'some value'
assert_equal [%w[not_a_method some\ value]], form.build_query
end
def test_parse_buttons
page = html_page <<-BODY
BODY
form = page.forms.first
buttons = form.buttons.sort
assert buttons.all? { |b| Mechanize::Form::Button === b }
assert_equal 'submit', buttons.shift.type
assert_equal 'button', buttons.shift.type
assert_equal 'submit', buttons.shift.type
assert_equal 'button', buttons.shift.type
assert_equal 'image', buttons.shift.type
assert_equal 'image', buttons.shift.type
assert_empty buttons
end
def test_parse_select
page = html_page <<-BODY
BODY
form = page.forms.first
selects = form.fields.sort
multi = selects.shift
assert_kind_of Mechanize::Form::MultiSelectList, multi
single = selects.shift
assert_kind_of Mechanize::Form::SelectList, single
assert_empty selects
end
def test_checkboxes_no_input_name
page = @mech.get('http://localhost/form_no_input_name.html')
form = page.forms.first
assert_equal(0, form.checkboxes.length)
end
def test_field_with
page = @mech.get("http://localhost/google.html")
search = page.forms.find { |f| f.name == "f" }
assert(search.field_with(:name => 'q'))
assert(search.field_with(:name => 'hl'))
assert(search.fields.find { |f| f.name == 'ie' })
end
def test_fields_no_input_name
page = @mech.get('http://localhost/form_no_input_name.html')
form = page.forms.first
assert_equal(0, form.fields.length)
end
def test_file_uploads_no_value
page = @mech.get("http://localhost/file_upload.html")
form = page.form('value_test')
assert_nil(form.file_uploads.first.value)
assert_nil(form.file_uploads.first.file_name)
end
def test_forms_no_input_name
page = @mech.get('http://localhost/form_no_input_name.html')
form = page.forms.first
assert_equal(0, form.radiobuttons.length)
end
def test_has_field_eh
refute @form.has_field? 'name'
@form['name'] = 'Aaron'
assert @form.has_field?('name')
end
def test_has_value_eh
refute @form.has_value? 'Aaron'
@form['name'] = 'Aaron'
assert @form.has_value?('Aaron')
end
def test_keys
assert_empty @form.keys
@form['name'] = 'Aaron'
assert_equal %w[name], @form.keys
end
def test_parse_textarea
form = Nokogiri::HTML <<-FORM
FORM
form = Mechanize::Form.new form, @mech
textarea = form.fields.first
assert_kind_of Mechanize::Form::Textarea, textarea
assert_equal 'hi', textarea.value
end
def test_post_with_rails_3_encoding_hack
page = @mech.get("http://localhost/rails_3_encoding_hack_form_test.html")
form = page.forms.first
form.submit
end
def test_post_with_blank_encoding
page = @mech.get("http://localhost/form_test.html")
form = page.form('post_form1')
form.page.encoding = nil
form.submit
end
def test_set_fields_duplicate
page = html_page ''
form = page.forms.first
form.set_fields :a => 'c'
assert_equal 'c', form.fields.first.value
assert_equal '', form.fields.last.value
end
def test_set_fields_none
page = html_page ''
form = page.forms.first
form.set_fields
assert_equal 'b', form.fields.first.value
end
def test_set_fields_many
page = html_page ''
form = page.forms.first
form.set_fields :a => 'c', :b => 'd'
assert_equal 'c', form.fields.first.value
assert_equal 'd', form.fields.last.value
end
def test_set_fields_one
page = html_page ''
form = page.forms.first
form.set_fields :a => 'c'
assert_equal 'c', form.fields.first.value
end
def test_set_fields_position
page = html_page ''
form = page.forms.first
form.set_fields :a => { 0 => 'c', 1 => 'd' }
assert_equal 'c', form.fields.first.value
assert_equal 'd', form.fields.last.value
end
def test_set_fields_position_crappily
page = html_page ''
form = page.forms.first
form.set_fields :a => ['c', 1]
assert_equal 'b', form.fields.first.value
assert_equal 'c', form.fields.last.value
end
def test_values
assert_empty @form.values
@form['name'] = 'Aaron'
assert_equal %w[Aaron], @form.values
end
def test_no_form_action
page = @mech.get('http://localhost:2000/form_no_action.html')
page.forms.first.fields.first.value = 'Aaron'
page = @mech.submit(page.forms.first)
assert_match('/form_no_action.html?first=Aaron', page.uri.to_s)
end
def test_submit_first_field_wins
page = @mech.get('http://localhost/tc_field_precedence.html')
form = page.forms.first
assert !form.checkboxes.empty?
assert_equal "1", form.checkboxes.first.value
submitted = form.submit
assert_equal 'ticky=1&ticky=0', submitted.parser.at('#query').text
end
def test_submit_takes_arbirary_headers
page = @mech.get('http://localhost:2000/form_no_action.html')
assert form = page.forms.first
form.action = '/http_headers'
page = @mech.submit(form, nil, { 'foo' => 'bar' })
headers = page.body.split("\n").map { |x| x.split('|', 2) }.flatten
headers = Hash[*headers]
assert_equal 'bar', headers['foo']
end
def test_submit_select_default_all
page = html_page <<-BODY
BODY
form = page.forms.first
assert_equal "6", form.list
page = @mech.submit form
assert_equal 1, page.links.length
assert_equal 1, page.links_with(:text => 'list:6').length
end
def test_submit_select_default_none
page = html_page <<-BODY
BODY
form = page.forms.first
assert_equal "1", form.list
page = @mech.submit form
assert_equal 1, page.links.length
assert_equal 1, page.links_with(:text => 'list:1').length
end
def test_form_select_default_noopts
page = html_page <<-BODY
BODY
form = page.forms.first
assert form.field 'list'
assert_nil form.list
page = @mech.submit form
assert_empty page.links
end
# Test submitting form with two fields of the same name
def test_post_multival
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'post_form')
assert_equal(2, form.fields_with(:name => 'first').length)
form.fields_with(:name => 'first')[0].value = 'Aaron'
form.fields_with(:name => 'first')[1].value = 'Patterson'
page = @mech.submit(form)
assert_equal(2, page.links.length)
assert(page.link_with(:text => 'first:Aaron'))
assert(page.link_with(:text => 'first:Patterson'))
end
# Test calling submit on the form object
def test_submit_on_form
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'post_form')
assert_equal(2, form.fields_with(:name => 'first').length)
form.fields_with(:name => 'first')[0].value = 'Aaron'
form.fields_with(:name => 'first')[1].value = 'Patterson'
page = form.submit
assert_equal(2, page.links.length)
assert(page.link_with(:text => 'first:Aaron'))
assert(page.link_with(:text => 'first:Patterson'))
end
# Test submitting form with two fields of the same name
def test_get_multival
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'get_form')
assert_equal(2, form.fields_with(:name => 'first').length)
form.fields_with(:name => 'first')[0].value = 'Aaron'
form.fields_with(:name => 'first')[1].value = 'Patterson'
page = @mech.submit(form)
assert_equal(2, page.links.length)
assert(page.link_with(:text => 'first:Aaron'))
assert(page.link_with(:text => 'first:Patterson'))
end
def test_post_with_non_strings
page = @mech.get("http://localhost/form_test.html")
page.form('post_form1') do |form|
form.first_name = 10
end.submit
end
def test_post
page = @mech.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form1" }
assert_equal("post", post_form.method.downcase)
assert_equal("/form_post", post_form.action)
assert_equal(3, post_form.fields.size)
assert_equal(1, post_form.buttons.size)
assert_equal(2, post_form.radiobuttons.size)
assert_equal(3, post_form.checkboxes.size)
assert(post_form.fields.find { |f| f.name == "first_name" },
"First name field was nil")
assert(post_form.fields.find { |f| f.name == "country" },
"Country field was nil")
assert(post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
"Gender male button was nil")
assert(post_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
"Gender female button was nil")
assert(post_form.checkboxes.find { |f| f.name == "cool person" },
"couldn't find cool person checkbox")
assert(post_form.checkboxes.find { |f| f.name == "likes ham" },
"couldn't find likes ham checkbox")
assert(post_form.checkboxes.find { |f| f.name == "green[eggs]" },
"couldn't find green[eggs] checkbox")
# Find the select list
s = post_form.fields.find { |f| f.name == "country" }
assert_equal(2, s.options.length)
assert_equal("USA", s.value)
assert_equal("USA", s.options.first.value)
assert_equal("USA", s.options.first.text)
assert_equal("CANADA", s.options[1].value)
assert_equal("CANADA", s.options[1].text)
# Now set all the fields
post_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
post_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}.checked = true
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
post_form.checkboxes.find { |f| f.name == "green[eggs]" }.checked = true
page = @mech.submit(post_form, post_form.buttons.first)
# Check that the submitted fields exist
assert_equal(5, page.links.size, "Not enough links")
assert(page.links.find { |l| l.text == "likes ham:on" },
"likes ham check box missing")
assert(page.links.find { |l| l.text == "green[eggs]:on" },
"green[eggs] check box missing")
assert(page.links.find { |l| l.text == "first_name:Aaron" },
"first_name field missing")
assert(page.links.find { |l| l.text == "gender:male" },
"gender field missing")
assert(page.links.find { |l| l.text == "country:USA" },
"select box not submitted")
end
def test_post_multipart
page = @mech.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form4_multipart" }
assert(post_form, "Post form is null")
assert_equal("post", post_form.method.downcase)
assert_equal("/form_post", post_form.action)
assert_equal(1, post_form.fields.size)
assert_equal(1, post_form.buttons.size)
page = @mech.submit(post_form, post_form.buttons.first)
assert page
end
def test_select_box
page = @mech.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form1" }
assert(page.header)
assert(page.root)
assert_equal(0, page.iframes.length)
assert_equal("post", post_form.method.downcase)
assert_equal("/form_post", post_form.action)
# Find the select list
s = post_form.field_with(:name => /country/)
assert_equal(2, s.options.length)
assert_equal("USA", s.value)
assert_equal("USA", s.options.first.value)
assert_equal("USA", s.options.first.text)
assert_equal("CANADA", s.options[1].value)
assert_equal("CANADA", s.options[1].text)
# Now set all the fields
post_form.field_with(:name => /country/).value = s.options[1]
assert_equal('CANADA', post_form.country)
page = @mech.submit(post_form, post_form.buttons.first)
# Check that the submitted fields exist
assert(page.links.find { |l| l.text == "country:CANADA" },
"select box not submitted")
end
def test_get
page = @mech.get("http://localhost/form_test.html")
get_form = page.forms.find { |f| f.name == "get_form1" }
assert_equal("get", get_form.method.downcase)
assert_equal("/form_post", get_form.action)
assert_equal(1, get_form.fields.size)
assert_equal(2, get_form.buttons.size)
assert_equal(2, get_form.radiobuttons.size)
assert_equal(3, get_form.checkboxes.size)
assert(get_form.fields.find { |f| f.name == "first_name" },
"First name field was nil")
assert(get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
"Gender male button was nil")
assert(get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
"Gender female button was nil")
assert(get_form.checkboxes.find { |f| f.name == "cool person" },
"couldn't find cool person checkbox")
assert(get_form.checkboxes.find { |f| f.name == "likes ham" },
"couldn't find likes ham checkbox")
assert(get_form.checkboxes.find { |f| f.name == "green[eggs]" },
"couldn't find green[eggs] checkbox")
# Set up the image button
img = get_form.buttons.find { |f| f.name == "button" }
img.x = "9"
img.y = "10"
# Now set all the fields
get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
get_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}.checked = true
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
get_form.checkboxes.find { |f| f.name == "green[eggs]" }.checked = true
page = @mech.submit(get_form, get_form.buttons.first)
# Check that the submitted fields exist
assert_equal(6, page.links.size, "Not enough links")
assert(page.links.find { |l| l.text == "likes ham:on" },
"likes ham check box missing")
assert(page.links.find { |l| l.text == "green[eggs]:on" },
"green[eggs] check box missing")
assert(page.links.find { |l| l.text == "first_name:Aaron" },
"first_name field missing")
assert(page.links.find { |l| l.text == "gender:male" },
"gender field missing")
assert(page.links.find { |l| l.text == "button.y:10" },
"Image button missing")
assert(page.links.find { |l| l.text == "button.x:9" },
"Image button missing")
end
def test_post_with_space_in_action
page = @mech.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form2" }
assert_equal("post", post_form.method.downcase)
assert_equal("/form post", post_form.action)
assert_equal(1, post_form.fields.size)
assert_equal(1, post_form.buttons.size)
assert_equal(2, post_form.radiobuttons.size)
assert_equal(2, post_form.checkboxes.size)
assert(post_form.fields.find { |f| f.name == "first_name" },
"First name field was nil")
assert(post_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
"Gender male button was nil")
assert(post_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
"Gender female button was nil")
assert(post_form.checkboxes.find { |f| f.name == "cool person" },
"couldn't find cool person checkbox")
assert(post_form.checkboxes.find { |f| f.name == "likes ham" },
"couldn't find likes ham checkbox")
# Now set all the fields
post_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
post_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}.checked = true
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
page = @mech.submit(post_form, post_form.buttons.first)
# Check that the submitted fields exist
assert_equal(3, page.links.size, "Not enough links")
assert(page.links.find { |l| l.text == "likes ham:on" },
"likes ham check box missing")
assert(page.links.find { |l| l.text == "first_name:Aaron" },
"first_name field missing")
assert(page.links.find { |l| l.text == "gender:male" },
"gender field missing")
end
def test_get_with_space_in_action
page = @mech.get("http://localhost/form_test.html")
get_form = page.forms.find { |f| f.name == "get_form2" }
assert_equal("get", get_form.method.downcase)
assert_equal("/form post", get_form.action)
assert_equal(1, get_form.fields.size)
assert_equal(1, get_form.buttons.size)
assert_equal(2, get_form.radiobuttons.size)
assert_equal(2, get_form.checkboxes.size)
assert(get_form.fields.find { |f| f.name == "first_name" },
"First name field was nil")
assert(get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
"Gender male button was nil")
assert(get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
"Gender female button was nil")
assert(get_form.checkboxes.find { |f| f.name == "cool person" },
"couldn't find cool person checkbox")
assert(get_form.checkboxes.find { |f| f.name == "likes ham" },
"couldn't find likes ham checkbox")
# Now set all the fields
get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
get_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}.checked = true
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
page = @mech.submit(get_form, get_form.buttons.first)
# Check that the submitted fields exist
assert_equal(3, page.links.size, "Not enough links")
assert(page.links.find { |l| l.text == "likes ham:on" },
"likes ham check box missing")
assert(page.links.find { |l| l.text == "first_name:Aaron" },
"first_name field missing")
assert(page.links.find { |l| l.text == "gender:male" },
"gender field missing")
end
def test_post_with_param_in_action
page = @mech.get("http://localhost/form_test.html")
post_form = page.forms.find { |f| f.name == "post_form3" }
assert_equal("post", post_form.method.downcase)
assert_equal("/form_post?great day=yes&one=two", post_form.action)
assert_equal(1, post_form.fields.size)
assert_equal(1, post_form.buttons.size)
assert_equal(2, post_form.radiobuttons.size)
assert_equal(2, post_form.checkboxes.size)
assert(post_form.fields.find { |f| f.name == "first_name" },
"First name field was nil")
male_button = post_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}
assert(male_button, "Gender male button was nil")
female_button = post_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "female"
}
assert(female_button, "Gender female button was nil")
assert(post_form.checkbox_with(:name => "cool person"),
"couldn't find cool person checkbox")
assert(post_form.checkboxes.find { |f| f.name == "likes ham" },
"couldn't find likes ham checkbox")
# Now set all the fields
post_form.field_with(:name => 'first_name').value = "Aaron"
post_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}.checked = true
post_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
page = @mech.submit(post_form, post_form.buttons.first)
# Check that the submitted fields exist
assert_equal(3, page.links.size, "Not enough links")
assert(page.links.find { |l| l.text == "likes ham:on" },
"likes ham check box missing")
assert(page.links.find { |l| l.text == "first_name:Aaron" },
"first_name field missing")
assert(page.links.find { |l| l.text == "gender:male" },
"gender field missing")
end
def test_get_with_param_in_action
page = @mech.get("http://localhost/form_test.html")
get_form = page.forms.find { |f| f.name == "get_form3" }
assert_equal("get", get_form.method.downcase)
assert_equal("/form_post?great day=yes&one=two", get_form.action)
assert_equal(1, get_form.fields.size)
assert_equal(1, get_form.buttons.size)
assert_equal(2, get_form.radiobuttons.size)
assert_equal(2, get_form.checkboxes.size)
assert(get_form.fields.find { |f| f.name == "first_name" },
"First name field was nil")
assert(get_form.radiobuttons.find { |f| f.name == "gender" && f.value == "male"},
"Gender male button was nil")
assert(get_form.radiobuttons.find {|f| f.name == "gender" && f.value == "female"},
"Gender female button was nil")
assert(get_form.checkboxes.find { |f| f.name == "cool person" },
"couldn't find cool person checkbox")
assert(get_form.checkboxes.find { |f| f.name == "likes ham" },
"couldn't find likes ham checkbox")
# Now set all the fields
get_form.fields.find { |f| f.name == "first_name" }.value = "Aaron"
get_form.radiobuttons.find { |f|
f.name == "gender" && f.value == "male"
}.checked = true
get_form.checkboxes.find { |f| f.name == "likes ham" }.checked = true
page = @mech.submit(get_form, get_form.buttons.first)
# Check that the submitted fields exist
assert_equal(3, page.links.size, "Not enough links")
assert(page.links.find { |l| l.text == "likes ham:on" },
"likes ham check box missing")
assert(page.links.find { |l| l.text == "first_name:Aaron" },
"first_name field missing")
assert(page.links.find { |l| l.text == "gender:male" },
"gender field missing")
end
def test_field_addition
page = @mech.get("http://localhost/form_test.html")
get_form = page.forms.find { |f| f.name == "get_form1" }
get_form.field("first_name").value = "Gregory"
assert_equal( "Gregory", get_form.field("first_name").value )
end
def test_fields_as_accessors
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'post_form')
assert_equal(2, form.fields_with(:name => 'first').length)
form.first = 'Aaron'
assert_equal('Aaron', form.first)
end
def test_form_and_fields_dom_id
# blatant copypasta of test above
page = @mech.get("http://localhost/form_test.html")
form = page.form_with(:dom_id => 'generic_form')
form_by_id = page.form_with(:id => 'generic_form')
assert_equal(1, form.fields_with(:dom_id => 'name_first').length)
assert_equal('first_name', form.field_with(:dom_id => 'name_first').name)
# *_with(:id => blah) should work exactly like (:dom_id => blah)
assert_equal(form, form_by_id)
assert_equal(form.fields_with(:dom_id => 'name_first'), form.fields_with(:id => 'name_first'))
end
def test_form_and_fields_dom_class
# blatant copypasta of test above
page = @mech.get("http://localhost/form_test.html")
form = page.form_with(:dom_class => 'really_generic_form')
form_by_class = page.form_with(:class => 'really_generic_form')
assert_equal(1, form.fields_with(:dom_class => 'text_input').length)
assert_equal('first_name', form.field_with(:dom_class => 'text_input').name)
# *_with(:class => blah) should work exactly like (:dom_class => blah)
assert_equal(form, form_by_class)
assert_equal(form.fields_with(:dom_class => 'text_input'), form.fields_with(:class => 'text_input'))
end
def test_add_field
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'post_form')
number_of_fields = form.fields.length
assert form.add_field!('intarweb')
assert_equal(number_of_fields + 1, form.fields.length)
end
def test_delete_field
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'post_form')
number_of_fields = form.fields.length
assert_equal 2, number_of_fields
form.delete_field!('first')
assert_nil(form['first'])
assert_equal(number_of_fields - 2, form.fields.length)
end
def test_has_field
page = @mech.get("http://localhost/form_multival.html")
form = page.form_with(:name => 'post_form')
assert(!form.has_field?('intarweb'))
assert form.add_field!('intarweb')
assert(form.has_field?('intarweb'))
end
def test_field_error
@page = @mech.get('http://localhost/empty_form.html')
form = @page.forms.first
assert_raises(NoMethodError) {
form.foo = 'asdfasdf'
}
assert_raises(NoMethodError) {
form.foo
}
end
def test_form_build_query
page = @mech.get("http://localhost/form_order_test.html")
get_form = page.forms.first
query = get_form.build_query
expected = [
%w[1 RADIO],
%w[3 nobody@example],
%w[2 TEXT],
%w[3 2011-10],
]
assert_equal expected, query
end
def test_form_input_disabled
page = html_page <<-BODY
BODY
form = page.forms.first
page = @mech.submit form
assert_empty page.links
end
def test_form_built_from_array_post
submitted = @mech.post(
'http://example/form_post',
[
%w[order_matters 0],
%w[order_matters 1],
%w[order_matters 2],
%w[mess_it_up asdf]
]
)
assert_equal 'order_matters=0&order_matters=1&order_matters=2&mess_it_up=asdf', submitted.parser.at('#query').text
end
def test_form_built_from_hashes_submit
uri = URI 'http://example/form_post'
page = page uri
form = Mechanize::Form.new node('form', 'name' => @NAME, 'method' => 'POST'), @mech, page
form.fields << Mechanize::Form::Field.new({'name' => 'order_matters'}, '0')
form.fields << Mechanize::Form::Field.new({'name' => 'order_matters'}, '1')
form.fields << Mechanize::Form::Field.new({'name' => 'order_matters'}, '2')
form.fields << Mechanize::Form::Field.new({'name' => 'mess_it_up'}, 'asdf')
submitted = @mech.submit form
assert_equal 'order_matters=0&order_matters=1&order_matters=2&mess_it_up=asdf', submitted.parser.at('#query').text
end
end
mechanize-2.7.2/test/test_mechanize_form_image_button.rb 0000644 0000041 0000041 00000000446 12222372210 023600 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFormImageButton < Mechanize::TestCase
def test_query_value
button = Mechanize::Form::ImageButton.new 'name' => 'image_button'
assert_equal [%w[image_button.x 0], %w[image_button.y 0]],
button.query_value
end
end
mechanize-2.7.2/test/test_mechanize_response_read_error.rb 0000644 0000041 0000041 00000001133 12222372210 024134 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeResponseReadError < Mechanize::TestCase
def setup
super
@error = 'error message'
@response = Response.new
@response['content-length'] = 3
@body_io = StringIO.new 'body'
end
def test_force_parse
@response['content-type'] = 'text/html'
uri = URI 'http://example/'
e = Mechanize::ResponseReadError.new @error, @response, @body_io, uri, @mech
page = e.force_parse
assert_kind_of Mechanize::Page, page
assert_equal 'body', page.body
assert_equal @mech, page.mech
end
end
mechanize-2.7.2/test/test_mechanize_form_field.rb 0000644 0000041 0000041 00000003315 12222372210 022204 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFormField < Mechanize::TestCase
def test_inspect
field = node 'input'
field = Mechanize::Form::Field.new field, 'a&b'
assert_match "value: a&b", field.inspect
end
def test_name
field = node 'input', 'name' => 'a&b'
field = Mechanize::Form::Field.new field
assert_equal 'a&b', field.name
end
def test_name_entity
field = node 'input', 'name' => 'a&b'
field = Mechanize::Form::Field.new field
assert_equal 'a&b', field.name
end
def test_name_entity_numeric
field = node 'input', 'name' => 'a&b'
field = Mechanize::Form::Field.new field
assert_equal 'a&b', field.name
end
def test_spaceship
doc = Nokogiri::HTML::Document.new
node = doc.create_element('input')
node['name'] = 'foo'
node['value'] = 'bar'
a = Mechanize::Form::Field.new(node)
b = Mechanize::Form::Field.new({'name' => 'foo'}, 'bar')
c = Mechanize::Form::Field.new({'name' => 'foo'}, 'bar')
assert_equal [a, b], [a, b].sort
assert_equal [a, b], [b, a].sort
assert_equal [b, c].sort, [b, c].sort
end
def test_value
field = node 'input'
field = Mechanize::Form::Field.new field, 'a&b'
assert_equal 'a&b', field.value
end
def test_value_entity
field = node 'input'
field = Mechanize::Form::Field.new field, 'a&b'
assert_equal 'a&b', field.value
end
def test_value_entity_numeric
field = node 'input'
field = Mechanize::Form::Field.new field, 'a&b'
assert_equal 'a&b', field.value
end
def test_raw_value
field = node 'input'
field = Mechanize::Form::Field.new field, 'a&b'
assert_equal 'a&b', field.raw_value
end
end
mechanize-2.7.2/test/test_mechanize_page_encoding.rb 0000644 0000041 0000041 00000012407 12222372210 022662 0 ustar www-data www-data # -*- coding: utf-8 -*-
require 'mechanize/test_case'
# tests for Page encoding and charset and parsing
class TestMechanizePageEncoding < Mechanize::TestCase
MECH_ASCII_ENCODING = Mechanize::Util::NEW_RUBY_ENCODING ? 'US-ASCII' : 'ISO-8859-1'
def setup
super
@uri = URI('http://localhost/')
@response_headers = { 'content-type' => 'text/html' }
@body = 'hi'
end
def util_page body = @body, headers = @response_headers
body.force_encoding Encoding::BINARY if body.respond_to? :force_encoding
Mechanize::Page.new @uri, headers, body, 200, @mech
end
def test_page_charset
charset = Mechanize::Page.charset 'text/html;charset=vAlue'
assert_equal 'vAlue', charset
charset = Mechanize::Page.charset 'text/html;charset=vaLue, text/html'
assert_equal 'vaLue', charset
charset = Mechanize::Page.charset 'text/html ; charset = valUe, text/html'
assert_equal 'valUe', charset
end
def test_page_charset_upcase
charset = Mechanize::Page.charset 'TEXT/HTML;CHARSET=UTF-8'
assert_equal 'UTF-8', charset
end
def test_page_charset_semicolon
charset = Mechanize::Page.charset 'text/html;charset=UTF-8;'
assert_equal 'UTF-8', charset
end
def test_page_charset_no_chaset_token
charset = Mechanize::Page.charset 'text/html'
assert_nil charset
end
def test_page_charset_returns_nil_when_charset_says_none
charset = Mechanize::Page.charset 'text/html;charset=none'
assert_nil charset
end
def test_page_charset_multiple
charset = Mechanize::Page.charset 'text/html;charset=111;charset=222'
assert_equal '111', charset
end
def test_page_response_header_charset
headers = { 'content-type' => 'text/html;charset=HEADER' }
charsets = Mechanize::Page.response_header_charset(headers)
assert_equal ['HEADER'], charsets
end
def test_page_response_header_charset_no_token
headers = {'content-type' => 'text/html'}
charsets = Mechanize::Page.response_header_charset(headers)
assert_equal [], charsets
headers = {'X-My-Header' => 'hello'}
charsets = Mechanize::Page.response_header_charset(headers)
assert_equal [], charsets
end
def test_page_response_header_charset_wrong_header
headers = { 'x-content-type' => 'text/html;charset=bogus' }
charsets = Mechanize::Page.response_header_charset(headers)
assert_equal [], charsets
end
def test_response_header_charset
page = util_page nil, {'content-type' => 'text/html;charset=HEADER'}
assert_equal ['HEADER'], page.response_header_charset
end
def test_page_meta_charset
body = ''
charsets = Mechanize::Page.meta_charset(body)
assert_equal ['META'], charsets
end
def test_page_meta_charset_is_empty_when_no_charset_meta
body = ''
charsets = Mechanize::Page.meta_charset(body)
assert_equal [], charsets
end
def test_page_meta_charset_no_content
body = ''
charsets = Mechanize::Page.meta_charset(body)
assert_empty charsets
end
# Test to fix issue: https://github.com/sparklemotion/mechanize/issues/143
def test_page_meta_charset_handles_whitespace
body = ''
charsets = Mechanize::Page.meta_charset(body)
assert_equal ["iso-8859-1"], charsets
end
def test_meta_charset
body = ''
page = util_page body
assert_equal ['META'], page.meta_charset
end
def test_detected_encoding
page = util_page
assert_equal MECH_ASCII_ENCODING, page.detected_encoding
end
def test_encodings
response = {'content-type' => 'text/html;charset=HEADER'}
body = ''
@mech.default_encoding = 'DEFAULT'
page = util_page body, response
assert_equal true, page.encodings.include?('HEADER')
assert_equal true, page.encodings.include?('META')
assert_equal true, page.encodings.include?(MECH_ASCII_ENCODING)
assert_equal true, page.encodings.include?('DEFAULT')
end
def test_parser_with_default_encoding
# pre test
assert_equal false, util_page.encodings.include?('Windows-1252')
@mech.default_encoding = 'Windows-1252'
page = util_page
assert_equal true, page.encodings.include?('Windows-1252')
end
def test_parser_force_default_encoding
@mech.default_encoding = 'Windows-1252'
@mech.force_default_encoding = true
page = util_page
assert page.encodings.include? 'Windows-1252'
end
def test_parser_encoding_equals_overwrites_force_default_encoding
@mech.default_encoding = 'Windows-1252'
@mech.force_default_encoding = true
page = util_page
assert_equal 'Windows-1252', page.encoding
page.encoding = 'ISO-8859-2'
assert_equal 'ISO-8859-2', page.encoding
end
def test_parser_encoding_when_searching_elements
skip "Encoding not implemented" unless have_encoding?
body = 'hi'
page = util_page body, 'content-type' => 'text/html,charset=ISO-8859-1'
result = page.search('#latin1')
assert_equal Encoding::UTF_8, result.text.encoding
end
end
mechanize-2.7.2/test/test_mechanize_history.rb 0000644 0000041 0000041 00000003226 12222372210 021600 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeHistory < Mechanize::TestCase
def setup
super
@uri = URI 'http://example/'
@uri2 = @uri + '/a'
@history = Mechanize::History.new
end
def test_initialize
assert_empty @history
end
def test_clear
@history.push :page, @uri
@history.clear
assert_empty @history
end
def test_pop
assert_nil @history.pop
@history.push :page1, @uri
@history.push :page2, @uri2
assert_equal :page2, @history.pop
refute_empty @history
end
def test_push
p1 = page @uri
obj = @history.push p1
assert_same @history, obj
assert_equal 1, @history.length
p2 = page @uri2
@history.push p2
assert_equal 2, @history.length
end
def test_push_max_size
@history = Mechanize::History.new 2
@history.push :page1, @uri
assert_equal 1, @history.length
@history.push :page2, @uri
assert_equal 2, @history.length
@history.push :page3, @uri
assert_equal 2, @history.length
end
def test_push_uri
obj = @history.push :page, @uri
assert_same @history, obj
assert_equal 1, @history.length
@history.push :page2, @uri
assert_equal 2, @history.length
end
def test_shift
assert_nil @history.shift
@history.push :page1, @uri
@history.push :page2, @uri2
page = @history.shift
assert_equal :page1, page
refute_empty @history
@history.shift
assert_empty @history
end
def test_visited_eh
refute @history.visited? @uri
@history.push page @uri
assert @history.visited? URI('http://example')
assert @history.visited? URI('http://example/')
end
end
mechanize-2.7.2/test/test_mechanize_form_encoding.rb 0000644 0000041 0000041 00000006561 12222372210 022715 0 ustar www-data www-data # coding: utf-8
require 'mechanize/test_case'
class TestMechanizeFormEncoding < Mechanize::TestCase
# See also: tests of Util.from_native_charset
# Encoding test should do with non-utf-8 characters
INPUTTED_VALUE = "ใในใ" # "test" in Japanese UTF-8 encoding
CONTENT_ENCODING = 'Shift_JIS' # one of Japanese encoding
encoded_value = "\x83\x65\x83\x58\x83\x67" # "test" in Japanese Shift_JIS encoding
encoded_value.force_encoding(::Encoding::SHIFT_JIS) if encoded_value.respond_to?(:force_encoding)
EXPECTED_QUERY = "first_name=#{CGI.escape(encoded_value)}&first_name=&gender=&green%5Beggs%5D="
if Mechanize::Util::NEW_RUBY_ENCODING
ENCODING_ERRORS = [EncodingError, Encoding::ConverterNotFoundError] # and so on
else
ENCODING_ERRORS = [Iconv::InvalidEncoding, Iconv::IllegalSequence]
end
ENCODING_LOG_MESSAGE = /INFO -- : form encoding: Shift_JIS/
INVALID_ENCODING = 'UTF-eight'
def set_form_with_encoding(enc)
page = @mech.get("http://localhost/form_set_fields.html")
form = page.forms.first
form.encoding = enc
form['first_name'] = INPUTTED_VALUE
form
end
def test_form_encoding_returns_accept_charset
page = @mech.get("http://localhost/rails_3_encoding_hack_form_test.html")
form = page.forms.first
accept_charset = form.form_node['accept-charset']
assert accept_charset
assert_equal accept_charset, form.encoding
refute_equal page.encoding, form.encoding
end
def test_form_encoding_returns_page_encoding_when_no_accept_charset
page = @mech.get("http://localhost/form_set_fields.html")
form = page.forms.first
accept_charset = form.form_node['accept-charset']
assert_nil accept_charset
refute_equal accept_charset, form.encoding
assert_equal page.encoding, form.encoding
end
def test_form_encoding_equals_sets_new_encoding
page = @mech.get("http://localhost/form_set_fields.html")
form = page.forms.first
refute_equal CONTENT_ENCODING, form.encoding
form.encoding = CONTENT_ENCODING
assert_equal CONTENT_ENCODING, form.encoding
end
def test_form_encoding_returns_nil_when_no_page_in_initialize
# this sequence is seen at Mechanize#post(url, query_hash)
node = {}
# Create a fake form
class << node
def search(*args); []; end
end
node['method'] = 'POST'
node['enctype'] = 'application/x-www-form-urlencoded'
form = Mechanize::Form.new(node)
assert_equal nil, form.encoding
end
def test_post_form_with_form_encoding
form = set_form_with_encoding CONTENT_ENCODING
form.submit
# we can not use "links.find{|l| l.text == 'key:val'}" assertion here
# because the link text encoding is always UTF-8 regaredless of html encoding
assert EXPECTED_QUERY, @mech.page.at('div#query').inner_text
end
def test_post_form_with_problematic_encoding
form = set_form_with_encoding INVALID_ENCODING
assert_raises(*ENCODING_ERRORS){ form.submit }
end
def test_form_ignore_encoding_error_is_true
form = set_form_with_encoding INVALID_ENCODING
form.ignore_encoding_error = true
form.submit
# HACK no assertions
end
def test_post_form_logs_form_encoding
sio = StringIO.new
@mech.log = Logger.new(sio)
@mech.log.level = Logger::INFO
form = set_form_with_encoding CONTENT_ENCODING
form.submit
assert_match ENCODING_LOG_MESSAGE, sio.string
@mech.log = nil
end
end
mechanize-2.7.2/test/test_mechanize_http_auth_realm.rb 0000644 0000041 0000041 00000001640 12222372210 023255 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeHttpAuthRealm < Mechanize::TestCase
def setup
super
@uri = URI 'http://example/'
@AR = Mechanize::HTTP::AuthRealm
@realm = @AR.new 'Digest', @uri, 'r'
end
def test_initialize
assert_equal 'r', @realm.realm
realm = @AR.new 'Digest', @uri, 'R'
assert_equal 'r', realm.realm
realm = @AR.new 'Digest', @uri, nil
assert_nil realm.realm
end
def test_equals2
other = @realm.dup
assert_equal @realm, other
other = @AR.new 'Basic', @uri, 'r'
refute_equal @realm, other
other = @AR.new 'Digest', URI('http://other.example/'), 'r'
refute_equal @realm, other
other = @AR.new 'Digest', @uri, 's'
refute_equal @realm, other
end
def test_hash
h = {}
h[@realm] = 1
other = @realm.dup
assert_equal 1, h[other]
other = @AR.new 'Basic', @uri, 'r'
assert_nil h[other]
end
end
mechanize-2.7.2/test/test_mechanize_form_textarea.rb 0000644 0000041 0000041 00000003047 12222372210 022740 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFormTextarea < Mechanize::TestCase
def setup
super
@page = @mech.get("http://localhost/tc_textarea.html")
end
def test_empty_text_area
form = @page.forms_with(:name => 'form1').first
assert_equal('', form.field_with(:name => 'text1').value)
form.text1 = 'Hello World'
assert_equal('Hello World', form.field_with(:name => 'text1').value)
page = @mech.submit(form)
assert_equal(1, page.links.length)
assert_equal('text1:Hello World', page.links[0].text)
end
def test_non_empty_textfield
form = @page.forms_with(:name => 'form2').first
assert_equal('sample text', form.field_with(:name => 'text1').value)
page = @mech.submit(form)
assert_equal(1, page.links.length)
assert_equal('text1:sample text', page.links[0].text)
end
def test_multi_textfield
form = @page.form_with(:name => 'form3')
assert_equal(2, form.fields_with(:name => 'text1').length)
assert_equal('', form.fields_with(:name => 'text1')[0].value)
assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)
form.text1 = 'Hello World'
assert_equal('Hello World', form.fields_with(:name => 'text1')[0].value)
assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)
page = @mech.submit(form)
assert_equal(2, page.links.length)
link = page.links_with(:text => 'text1:sample text')
assert_equal(1, link.length)
link = page.links_with(:text => 'text1:Hello World')
assert_equal(1, link.length)
end
end
mechanize-2.7.2/test/test_mechanize_file_response.rb 0000644 0000041 0000041 00000001125 12222372210 022730 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFileResponse < Mechanize::TestCase
def test_content_type
Tempfile.open %w[pi .nothtml] do |tempfile|
res = Mechanize::FileResponse.new tempfile.path
assert_equal nil, res['content-type']
end
Tempfile.open %w[pi .xhtml] do |tempfile|
res = Mechanize::FileResponse.new tempfile.path
assert_equal 'text/html', res['content-type']
end
Tempfile.open %w[pi .html] do |tempfile|
res = Mechanize::FileResponse.new tempfile.path
assert_equal 'text/html', res['Content-Type']
end
end
end
mechanize-2.7.2/test/test_mechanize_redirect_not_get_or_head_error.rb 0000644 0000041 0000041 00000000370 12222372210 026306 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeRedirectNotGetOrHead < Mechanize::TestCase
def test_to_s
page = fake_page
error = Mechanize::RedirectNotGetOrHeadError.new(page, :put)
assert_match(/ PUT /, error.to_s)
end
end
mechanize-2.7.2/test/test_mechanize_page_link.rb 0000644 0000041 0000041 00000022766 12222372210 022042 0 ustar www-data www-data # coding: utf-8
require 'mechanize/test_case'
class TestMechanizePageLink < Mechanize::TestCase
WINDOWS_1255 = <<-HTML
hi
HTML
BAD = <<-HTML
Bia\xB3ystok
HTML
BAD.force_encoding Encoding::BINARY if defined? Encoding
SJIS_TITLE = "\x83\x65\x83\x58\x83\x67"
SJIS_AFTER_TITLE = <<-HTML
#{SJIS_TITLE}
HTML
SJIS_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
SJIS_BAD_AFTER_TITLE = <<-HTML
#{SJIS_TITLE}
HTML
SJIS_BAD_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
UTF8_TITLE = 'ใในใ'
UTF8 = <<-HTML
#{UTF8_TITLE}
HTML
ENCODING_ERROR_CLASS = Nokogiri::XML::SyntaxError
def setup
super
@uri = URI('http://example')
@res = { 'content-type' => 'text/html' }
@body = 'hi'
end
def util_page body = @body, res = @res
body.force_encoding Encoding::BINARY if body.respond_to? :force_encoding
Mechanize::Page.new @uri, res, body, 200, @mech
end
def test_override_content_type
page = Mechanize::Page.new nil, {'content-type' => 'text/html'}, WINDOWS_1255
assert page
assert_equal 'text/html; charset=windows-1255', page.content_type
end
def test_canonical_uri
page = @mech.get("http://localhost/canonical_uri.html")
assert_equal(URI("http://localhost/canonical_uri"), page.canonical_uri)
page = @mech.get("http://localhost/file_upload.html")
assert_equal(nil, page.canonical_uri)
end
def test_canonical_uri_unescaped
page = util_page <<-BODY
BODY
assert_equal @uri + '/white%20space', page.canonical_uri
end
def test_charset_from_content_type
charset = Mechanize::Page.__send__ :charset_from_content_type, 'text/html;charset=UTF-8'
assert_equal 'UTF-8', charset
end
def test_charset_from_bad_content_type
charset = Mechanize::Page.__send__ :charset_from_content_type, 'text/html'
assert_nil charset
end
def test_encoding
page = util_page WINDOWS_1255
assert_equal 'windows-1255', page.encoding
end
def test_encoding_charset_after_title
page = util_page SJIS_AFTER_TITLE
assert_equal false, page.encoding_error?
assert_equal 'Shift_JIS', page.encoding
end
def test_encoding_charset_after_title_bad
page = util_page UTF8
assert_equal false, page.encoding_error?
assert_equal 'UTF-8', page.encoding
end
def test_encoding_charset_after_title_double_bad
page = util_page SJIS_BAD_AFTER_TITLE
assert_equal false, page.encoding_error?
assert_equal 'SHIFT_JIS', page.encoding
end
def test_encoding_charset_bad
page = util_page "#{UTF8_TITLE}"
page.encodings.replace %w[
UTF-8
Shift_JIS
]
assert_equal false, page.encoding_error?
assert_equal 'UTF-8', page.encoding
end
def test_encoding_meta_charset
page = util_page ""
assert_equal 'UTF-8', page.encoding
end
def test_encoding_equals
page = util_page
page.meta_refresh
assert page.instance_variable_get(:@meta_refresh)
page.encoding = 'UTF-8'
assert_nil page.instance_variable_get(:@meta_refresh)
assert_equal 'UTF-8', page.encoding
assert_equal 'UTF-8', page.parser.encoding
end
def test_page_encoding_error?
page = util_page
page.parser.errors.clear
assert_equal false, page.encoding_error?
end
def test_detect_libxml2error_indicate_encoding
page = util_page
page.parser.errors.clear
# error in libxml2-2.7.8/parser.c, HTMLparser.c or parserInternals.c
page.parser.errors = [ENCODING_ERROR_CLASS.new("Input is not proper UTF-8, indicate encoding !\n")]
assert_equal true, page.encoding_error?
end
def test_detect_libxml2error_invalid_char
page = util_page
page.parser.errors.clear
# error in libxml2-2.7.8/HTMLparser.c
page.parser.errors = [ENCODING_ERROR_CLASS.new("Invalid char in CDATA 0x%X\n")]
assert_equal true, page.encoding_error?
end
def test_detect_libxml2error_input_conversion_failed
page = util_page
page.parser.errors.clear
# error in libxml2-2.7.8/encoding.c
page.parser.errors = [ENCODING_ERROR_CLASS.new("input conversion failed due to input error\n")]
assert_equal true, page.encoding_error?
end
def test_detect_libxml2error_which_unsupported_by_mechanize
page = util_page
page.parser.errors.clear
# error in libxml2-2.7.8/HTMLparser.c
page.parser.errors = [ENCODING_ERROR_CLASS.new("encoder error\n")]
assert_equal false, page.encoding_error?
end
def test_encoding_equals_before_parser
# document has a bad encoding information - windows-1255
page = util_page BAD
# encoding is wrong, so user wants to force ISO-8859-2
page.encoding = 'ISO-8859-2'
assert_equal false, page.encoding_error?
assert_equal 'ISO-8859-2', page.encoding
assert_equal 'ISO-8859-2', page.parser.encoding
end
def test_encoding_equals_after_parser
# document has a bad encoding information - windows-1255
page = util_page BAD
page.parser
# autodetection sets encoding to windows-1255
assert_equal 'windows-1255', page.encoding
# believe in yourself, not machine
assert_equal false, page.encoding_error?
# encoding is wrong, so user wants to force ISO-8859-2
page.encoding = 'ISO-8859-2'
assert_equal false, page.encoding_error?
assert_equal 'ISO-8859-2', page.encoding
assert_equal 'ISO-8859-2', page.parser.encoding
end
def test_frames_with
page = @mech.get("http://localhost/frame_test.html")
assert_equal(3, page.frames.size)
find_orig = page.frames.find_all { |f| f.name == 'frame1' }
find1 = page.frames_with(:name => 'frame1')
find_orig.zip(find1).each { |a,b|
assert_equal(a, b)
}
end
def test_links_with_dom_id
page = @mech.get("http://localhost/tc_links.html")
link = page.links_with(:dom_id => 'bold_aaron_link')
link_by_id = page.links_with(:id => 'bold_aaron_link')
assert_equal(1, link.length)
assert_equal('Aaron Patterson', link.first.text)
assert_equal(link, link_by_id)
end
def test_links_with_dom_class
page = @mech.get("http://localhost/tc_links.html")
link = page.links_with(:dom_class => 'thing_link')
link_by_class = page.links_with(:class => 'thing_link')
assert_equal(1, link.length)
assert_equal(link, link_by_class)
end
def test_link_with_encoded_space
page = @mech.get("http://localhost/tc_links.html")
link = page.link_with(:text => 'encoded space')
page = @mech.click link
end
def test_link_with_space
page = @mech.get("http://localhost/tc_links.html")
link = page.link_with(:text => 'not encoded space')
page = @mech.click link
end
def test_link_with_unusual_characters
page = @mech.get("http://localhost/tc_links.html")
link = page.link_with(:text => 'unusual characters')
@mech.click link
# HACK no assertion
end
def test_links
page = @mech.get("http://localhost/find_link.html")
assert_equal(18, page.links.length)
end
def test_links_with_bold
page = @mech.get("http://localhost/tc_links.html")
link = page.links_with(:text => /Bold Dude/)
assert_equal(1, link.length)
assert_equal('Bold Dude', link.first.text)
assert_equal [], link.first.rel
assert !link.first.rel?('me')
assert !link.first.rel?('nofollow')
link = page.links_with(:text => 'Aaron James Patterson')
assert_equal(1, link.length)
assert_equal('Aaron James Patterson', link.first.text)
assert_equal ['me'], link.first.rel
assert link.first.rel?('me')
assert !link.first.rel?('nofollow')
link = page.links_with(:text => 'Aaron Patterson')
assert_equal(1, link.length)
assert_equal('Aaron Patterson', link.first.text)
assert_equal ['me', 'nofollow'], link.first.rel
assert link.first.rel?('me')
assert link.first.rel?('nofollow')
link = page.links_with(:text => 'Ruby Rocks!')
assert_equal(1, link.length)
assert_equal('Ruby Rocks!', link.first.text)
end
def test_meta_refresh
page = @mech.get("http://localhost/find_link.html")
assert_equal(3, page.meta_refresh.length)
assert_equal(%w{
http://www.drphil.com/
http://www.upcase.com/
http://tenderlovemaking.com/ }.sort,
page.meta_refresh.map { |x| x.href.downcase }.sort)
end
def test_title
page = util_page
assert_equal('hi', page.title)
end
def test_title_none
page = util_page '' # invalid HTML
assert_equal(nil, page.title)
end
def test_page_decoded_with_charset
page = util_page @body, 'content-type' => 'text/html; charset=EUC-JP'
assert_equal 'EUC-JP', page.encoding
assert_equal 'EUC-JP', page.parser.encoding
end
def test_form
page = @mech.get("http://localhost/tc_form_action.html")
form = page.form(:name => 'post_form1')
assert form
yielded = false
form = page.form(:name => 'post_form1') { |f|
yielded = true
assert f
assert_equal(form, f)
}
assert yielded
form_by_action = page.form(:action => '/form_post?a=b&b=c')
assert form_by_action
assert_equal(form, form_by_action)
end
end
mechanize-2.7.2/test/test_mechanize_form_file_upload.rb 0000644 0000041 0000041 00000000626 12222372210 023406 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFormFileUpload < Mechanize::TestCase
def test_file_name
field = node 'input'
field = Mechanize::Form::FileUpload.new field, 'a&b'
assert_equal 'a&b', field.file_name
end
def test_file_name_entity
field = node 'input'
field = Mechanize::Form::FileUpload.new field, 'a&b'
assert_equal 'a&b', field.file_name
end
end
mechanize-2.7.2/test/test_mechanize_form_option.rb 0000644 0000041 0000041 00000002042 12222372210 022425 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFormOption < Mechanize::TestCase
def setup
super
page = html_page <<-BODY
BODY
form = page.forms.first
@select = form.fields.first
@option1 = @select.options.first
@option2 = @select.options.last
end
def test_inspect
assert_match "value: 2", @select.inspect
end
def test_value_missing_value
option = node 'option'
option.inner_html = 'blah'
option = Mechanize::Form::Option.new option, nil
assert_equal 'blah', option.value
end
def test_click
@option1.click
assert @option1.selected?
end
def test_select
@option1.select
assert @option1.selected?
end
def test_unselect
@option2.unselect
refute @option2.selected?
end
def test_selected_eh
refute @option1.selected?
assert @option2.selected?
end
end
mechanize-2.7.2/test/test_mechanize_file_request.rb 0000644 0000041 0000041 00000000746 12222372210 022572 0 ustar www-data www-data require 'mechanize/test_case'
class TestMechanizeFileRequest < Mechanize::TestCase
def setup
@uri = URI.parse 'file:///nonexistent'
@r = Mechanize::FileRequest.new @uri
end
def test_initialize
assert_equal @uri, @r.uri
assert_equal '/nonexistent', @r.path
assert_respond_to @r, :[]=
assert_respond_to @r, :add_field
assert_respond_to @r, :each_header
end
def test_response_body_permitted_eh
assert @r.response_body_permitted?
end
end
mechanize-2.7.2/test/htdocs/ 0000755 0000041 0000041 00000000000 12222372210 015751 5 ustar www-data www-data mechanize-2.7.2/test/htdocs/index.html 0000644 0000041 0000041 00000000145 12222372210 017746 0 ustar www-data www-data
Page Title
Hello World!
mechanize-2.7.2/test/htdocs/unusual______.html 0000644 0000041 0000041 00000000126 12222372210 021424 0 ustar www-data www-data
This is a webpage that has a very unusual name.
mechanize-2.7.2/test/htdocs/tc_referer.html 0000644 0000041 0000041 00000001261 12222372210 020757 0 ustar www-data www-data
Referer Servlet
Referer Servlet forced to http
Referer Servlet forced to https
Referer Servlet (noreferrer)
Referer Servlet forced to http (noreferrer)
Referer Servlet forced to https (noreferrer)
mechanize-2.7.2/test/htdocs/tc_follow_meta.html 0000644 0000041 0000041 00000000244 12222372210 021635 0 ustar www-data www-data
This page has a meta refresh.
mechanize-2.7.2/test/htdocs/tc_checkboxes.html 0000644 0000041 0000041 00000001404 12222372210 021442 0 ustar www-data www-data
tc_checkboxbuttons.html
mechanize-2.7.2/test/htdocs/form_no_action.html 0000644 0000041 0000041 00000000565 12222372210 021641 0 ustar www-data www-data
Page Title
mechanize-2.7.2/test/htdocs/file_upload.html 0000644 0000041 0000041 00000002027 12222372210 021123 0 ustar www-data www-data
File Upload Form
File Upload Test
mechanize-2.7.2/test/htdocs/meta_cookie.html 0000644 0000041 0000041 00000000601 12222372210 021113 0 ustar www-data www-data
no image
mechanize-2.7.2/test/htdocs/link with space.html 0000644 0000041 0000041 00000000132 12222372210 021600 0 ustar www-data www-data
This is a webpage that has a space in the filename.
mechanize-2.7.2/test/htdocs/robots.txt 0000644 0000041 0000041 00000000042 12222372210 020016 0 ustar www-data www-data User-Agent: *
Disallow: /norobots
mechanize-2.7.2/test/htdocs/empty_form.html 0000644 0000041 0000041 00000000071 12222372210 021016 0 ustar www-data www-data
mechanize-2.7.2/test/htdocs/canonical_uri.html 0000644 0000041 0000041 00000000264 12222372210 021447 0 ustar www-data www-data
test
mechanize-2.7.2/test/htdocs/tc_meta_in_body.html 0000644 0000041 0000041 00000000245 12222372210 021757 0 ustar www-data www-data
This page has a meta refresh.
mechanize-2.7.2/test/htdocs/tc_field_precedence.html 0000644 0000041 0000041 00000000542 12222372210 022566 0 ustar www-data www-data
tc_field_precedence.html
mechanize-2.7.2/test/htdocs/rails_3_encoding_hack_form_test.html 0000644 0000041 0000041 00000002102 12222372210 025104 0 ustar www-data www-data
mechanize-2.7.2/test/htdocs/tc_follow_meta_loop_1.html 0000644 0000041 0000041 00000000264 12222372210 023110 0 ustar www-data www-data
This page has a meta refresh.
mechanize-2.7.2/test/htdocs/tc_pretty_print.html 0000644 0000041 0000041 00000001215 12222372210 022067 0 ustar www-data www-data
tc_pretty_print.html
Google
mechanize-2.7.2/test/htdocs/dir with spaces/ 0000755 0000041 0000041 00000000000 12222372210 020722 5 ustar www-data www-data mechanize-2.7.2/test/htdocs/dir with spaces/foo.html 0000644 0000041 0000041 00000000006 12222372210 022367 0 ustar www-data www-data HELLO
mechanize-2.7.2/test/htdocs/tc_relative_links.html 0000644 0000041 0000041 00000001156 12222372210 022343 0 ustar www-data www-data
forward
mechanize-2.7.2/test/htdocs/button.jpg 0000644 0000041 0000041 00000001727 12222372210 017775 0 ustar www-data www-data ุเ JFIF H H แ Exif MM * Created with The GIMP C !"$"$ Cภ d" ฤ ฤ ( !1A"Q2Bกฤ ฤ ฺ ? ูxฦ0<ทุซจg(๔ฤF๛ง๚JTเส ๓๖แซ9หgZถq.ษ qฯฒXO'่๙ห๕ ปt๐fฺอ
l๋+u๊ฬhQึ๓ห๙i^(@$๔จ ส/\ขซ3ฎาต>EK๔ำcUm1dถc%/-คJ%-บดH๖เ`j7v
งอํks วิฦ)ศ์๕฿ศโ{ํ๋C9[ใฺ[zช^ฯ\ทถๅ^ถdถถ฿ะqK
๑JAJU฿J ู(D;ดKพv๖
จตฏลฎZุ[๘Tด,{_a} (ณะ
#ฎงMง็:3XฐIAคQfตปMฅAว:๑G๐I จdu๗iiฑ mn^ฆeฏqบ's^\!ฐฏ**๖ื~โOั99oิๆPศฟดRHจ฿ฯ=ฉํ.;]}๙8โปg๓Qี6u
Vล lื1ตุXm๕จงqNบ๊บ1T๋ษ๖S๙่๛#K๎ZVใgง๒=ญfฃiPฯ ีมRิ3๓Eสฟง@! ฟUๅื]ฦฅชฺตk+ชถJy๓Zd>ไhำuิ6z้e)Q!'ฑ๏ุ๋ศ>ษmผSจ๒฿}2>RถqM;๑O]]zฮTัu4๋ีฝ^Ui๖uิtzs๕ฒกK2tS !๕ค๚WGพ2ๆโzบฟ๋tั!
Bญeพค3๑:Uเ
ัู๐QQ$งณั$vp:|cccccccccู mechanize-2.7.2/test/htdocs/form_select.html 0000644 0000041 0000041 00000000736 12222372210 021147 0 ustar www-data www-data
mechanize-2.7.2/test/htdocs/tc_follow_meta_loop_2.html 0000644 0000041 0000041 00000000264 12222372210 023111 0 ustar www-data www-data
This page has a meta refresh.
mechanize-2.7.2/test/htdocs/no_title_test.html 0000644 0000041 0000041 00000000122 12222372210 021506 0 ustar www-data www-data
No title in the title tag
mechanize-2.7.2/test/htdocs/tc_base_link.html 0000644 0000041 0000041 00000000173 12222372210 021255 0 ustar www-data www-data
test
mechanize-2.7.2/test/htdocs/google.html 0000755 0000041 0000041 00000004615 12222372210 020124 0 ustar www-data www-data Google

Advertising Programs - Business Solutions - About Google©2006 Google
mechanize-2.7.2/test/htdocs/form_multi_select.html 0000644 0000041 0000041 00000000760 12222372210 022356 0 ustar www-data www-data
mechanize-2.7.2/test/htdocs/tc_links.html 0000644 0000041 0000041 00000001474 12222372210 020453 0 ustar www-data www-data
Bold Dude
Dude
Aaron James Patterson
Aaron Patterson
Thing!
Ruby Rocks!
encoded space
not encoded space
unusual characters
empty href
javascript link
mechanize-2.7.2/test/htdocs/find_link.html 0000644 0000041 0000041 00000003562 12222372210 020602 0 ustar www-data www-data
Testing the links
blargle
CPAN A
CPAN B
CPAN C
CPAN D
MSNBC
CNN
BBC
News
News
News
Rebuild Index
NoWhere
NoWhere
Blongo!
mechanize-2.7.2/test/htdocs/tc_bad_charset.html 0000644 0000041 0000041 00000000260 12222372210 021562 0 ustar www-data www-data
Biaณystok
mechanize-2.7.2/test/htdocs/noindex.html 0000644 0000041 0000041 00000000271 12222372210 020303 0 ustar www-data www-data
noindex test
Do not index nor archive this page!
mechanize-2.7.2/test/htdocs/form_test.html 0000644 0000041 0000041 00000013655 12222372210 020653 0 ustar www-data www-data
Page Title
Post Form 1
Get Form 1
Post Form 2
Get Form 2
Post Form 3
Post Form 4 - Multipart
Get Form 3
form test
mechanize-2.7.2/test/htdocs/bad_form_test.html 0000644 0000041 0000041 00000000345 12222372210 021451 0 ustar www-data www-data
Page Title
mechanize-2.7.2/test/htdocs/tc_form_action.html 0000644 0000041 0000041 00000002417 12222372210 021631 0 ustar www-data www-data
Page Title
Post Form 1
Post Form 2
Post Form 3
Post Form 4
mechanize-2.7.2/test/htdocs/tc_textarea.html 0000644 0000041 0000041 00000001241 12222372210 021140 0 ustar www-data www-data
tc_textarea.html
mechanize-2.7.2/test/htdocs/form_multival.html 0000644 0000041 0000041 00000001725 12222372210 021524 0 ustar www-data www-data
Page Title
mechanize-2.7.2/test/htdocs/tc_charset.html 0000644 0000041 0000041 00000000170 12222372210 020754 0 ustar www-data www-data
mechanize-2.7.2/test/htdocs/frame_referer_test.html 0000644 0000041 0000041 00000000377 12222372210 022511 0 ustar www-data www-data
A simple frameset document
mechanize-2.7.2/test/htdocs/robots.html 0000644 0000041 0000041 00000000154 12222372210 020147 0 ustar www-data www-data
Welcome!
Welcome, robot!
mechanize-2.7.2/test/htdocs/frame_test.html 0000644 0000041 0000041 00000001672 12222372210 020776 0 ustar www-data www-data
A simple frameset document
This frameset document contains:
mechanize-2.7.2/test/htdocs/tc_encoded_links.html 0000644 0000041 0000041 00000000125 12222372210 022124 0 ustar www-data www-data
test link
mechanize-2.7.2/test/htdocs/tc_blank_form.html 0000644 0000041 0000041 00000000504 12222372210 021436 0 ustar www-data www-data
mechanize-2.7.2/test/htdocs/form_order_test.html 0000644 0000041 0000041 00000000516 12222372210 022036 0 ustar www-data www-data
Page Title
mechanize-2.7.2/test/htdocs/form_no_input_name.html 0000644 0000041 0000041 00000000701 12222372210 022513 0 ustar www-data www-data
Input with no name
mechanize-2.7.2/test/htdocs/alt_text.html 0000644 0000041 0000041 00000000541 12222372210 020463 0 ustar www-data www-data
no image
mechanize-2.7.2/test/htdocs/test_click.html 0000644 0000041 0000041 00000000521 12222372210 020761 0 ustar www-data www-data
Page Title
This link is not called "A Link"
A Link