Permalink
Browse files

Convert to minitest to avoid 1.9 vs 1.8 assertion availability in tes…

…t/unit
  • Loading branch information...
1 parent 77aafeb commit fd76666329cfee1554868840102c3291a71e844e @drbrain drbrain committed Jun 28, 2011
Showing with 348 additions and 438 deletions.
  1. +6 −0 .autotest
  2. +2 −2 Rakefile
  3. +1 −1 test/helper.rb
  4. +12 −12 test/test_cookies.rb
  5. +1 −1 test/test_form_action.rb
  6. +5 −7 test/test_form_as_hash.rb
  7. +1 −1 test/test_form_button.rb
  8. +1 −1 test/test_frames.rb
  9. +1 −1 test/test_headers.rb
  10. +1 −1 test/test_history.rb
  11. +1 −1 test/test_history_added.rb
  12. +1 −1 test/test_html_unscape_forms.rb
  13. +1 −1 test/test_if_modified_since.rb
  14. +1 −1 test/test_images.rb
  15. +24 −27 test/test_mechanize.rb
  16. +6 −6 test/test_mechanize_cookie.rb
  17. +5 −4 test/test_mechanize_cookie_jar.rb
  18. +1 −1 test/test_mechanize_file.rb
  19. +1 −1 test/test_mechanize_file_request.rb
  20. +1 −1 test/test_mechanize_file_response.rb
  21. +148 −233 test/test_mechanize_form.rb
  22. +1 −1 test/test_mechanize_form_check_box.rb
  23. +8 −6 test/test_mechanize_form_encoding.rb
  24. +1 −1 test/test_mechanize_form_field.rb
  25. +1 −1 test/test_mechanize_form_image_button.rb
  26. +9 −3 test/test_mechanize_form_textarea.rb
  27. +2 −2 test/test_mechanize_http_agent.rb
  28. +8 −7 test/test_mechanize_link.rb
  29. +1 −1 test/test_mechanize_page_encoding.rb
  30. +5 −2 test/test_mechanize_page_link.rb
  31. +1 −1 test/test_mechanize_page_meta_refresh.rb
  32. +1 −1 test/test_mechanize_redirect_not_get_or_head_error.rb
  33. +1 −1 test/test_mechanize_subclass.rb
  34. +18 −18 test/test_mechanize_util.rb
  35. +1 −1 test/test_multi_select.rb
  36. +4 −4 test/test_no_attributes.rb
  37. +1 −1 test/test_option.rb
  38. +11 −20 test/test_pluggable_parser.rb
  39. +9 −13 test/test_post_form.rb
  40. +1 −1 test/test_pretty_print.rb
  41. +1 −1 test/test_radiobutton.rb
  42. +1 −1 test/test_redirect_limit_reached.rb
  43. +1 −1 test/test_referer.rb
  44. +2 −2 test/test_relative_links.rb
  45. +1 −1 test/test_request.rb
  46. +1 −1 test/test_response_code.rb
  47. +18 −29 test/test_robots.rb
  48. +1 −1 test/test_save_file.rb
  49. +3 −3 test/test_scheme.rb
  50. +5 −2 test/test_select.rb
  51. +1 −1 test/test_select_all.rb
  52. +1 −1 test/test_select_none.rb
  53. +5 −3 test/test_select_noopts.rb
  54. +1 −1 test/test_set_fields.rb
  55. +1 −1 test/test_ssl_server.rb
View
@@ -0,0 +1,6 @@
+require 'autotest/restart'
+
+Autotest.add_hook :initialize do |at|
+ at.testlib = 'minitest/autorun'
+end
+
View
@@ -1,8 +1,8 @@
require 'rubygems'
require 'hoe'
-Hoe.plugin :bundler
-Hoe.plugin :gemspec
+
Hoe.plugin :git
+Hoe.plugin :minitest
Hoe.spec 'mechanize' do
developer 'Eric Hodel', 'drbrain@segment7.net'
View
@@ -1,5 +1,5 @@
-require 'test/unit'
require 'rubygems'
+require 'minitest/autorun'
require 'mechanize'
require 'webrick/httputils'
require 'servlets'
View
@@ -1,6 +1,6 @@
require "helper"
-class CookiesMechTest < Test::Unit::TestCase
+class CookiesMechTest < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end
@@ -21,15 +21,15 @@ def test_send_cookies
page = @agent.get("http://localhost/many_cookies")
page = @agent.get("http://localhost/send_cookies")
assert_equal(3, page.links.length)
- assert_not_nil(page.links.find { |l| l.text == "name:Aaron" })
- assert_not_nil(page.links.find { |l| l.text == "no_expires:nope" })
+ assert(page.links.find { |l| l.text == "name:Aaron" })
+ assert(page.links.find { |l| l.text == "no_expires:nope" })
end
def test_no_space_cookies
@agent.get("http://localhost/one_cookie_no_space")
assert_equal(1, @agent.cookies.length)
foo_cookie = @agent.cookies.find { |k| k.name == 'foo' }
- assert_not_nil(foo_cookie, 'Foo cookie was nil')
+ assert(foo_cookie, 'Foo cookie was nil')
assert_equal('bar', foo_cookie.value)
assert_equal('/', foo_cookie.path)
assert_equal(true, Time.now < foo_cookie.expires)
@@ -40,7 +40,7 @@ def test_many_cookies_as_string
assert_equal(4, @agent.cookies.length)
name_cookie = @agent.cookies.find { |k| k.name == "name" }
- assert_not_nil(name_cookie, "Name cookie was nil")
+
assert_equal("Aaron", name_cookie.value)
assert_equal("/", name_cookie.path)
assert_equal(true, Time.now < name_cookie.expires)
@@ -49,18 +49,18 @@ def test_many_cookies_as_string
assert_nil(expired_cookie, "Expired cookie was not nil")
no_exp_cookie = @agent.cookies.find { |k| k.name == "no_expires" }
- assert_not_nil(no_exp_cookie, "No expires cookie is nil")
+
assert_equal("nope", no_exp_cookie.value)
assert_equal("/", no_exp_cookie.path)
assert_nil(no_exp_cookie.expires)
path_cookie = @agent.cookies.find { |k| k.name == "a_path" }
- assert_not_nil(path_cookie, "Path cookie is nil")
+
assert_equal("some_path", path_cookie.value)
assert_equal(true, Time.now < path_cookie.expires)
no_path_cookie = @agent.cookies.find { |k| k.name == "no_path" }
- assert_not_nil(no_path_cookie, "No path cookie is nil")
+
assert_equal("no_path", no_path_cookie.value)
assert_equal("/", no_path_cookie.path)
assert_equal(true, Time.now < no_path_cookie.expires)
@@ -71,7 +71,7 @@ def test_many_cookies
assert_equal(4, @agent.cookies.length)
name_cookie = @agent.cookies.find { |k| k.name == "name" }
- assert_not_nil(name_cookie, "Name cookie was nil")
+ assert(name_cookie, "Name cookie was nil")
assert_equal("Aaron", name_cookie.value)
assert_equal("/", name_cookie.path)
assert_equal(true, Time.now < name_cookie.expires)
@@ -80,18 +80,18 @@ def test_many_cookies
assert_nil(expired_cookie, "Expired cookie was not nil")
no_exp_cookie = @agent.cookies.find { |k| k.name == "no_expires" }
- assert_not_nil(no_exp_cookie, "No expires cookie is nil")
+ assert(no_exp_cookie, "No expires cookie is nil")
assert_equal("nope", no_exp_cookie.value)
assert_equal("/", no_exp_cookie.path)
assert_nil(no_exp_cookie.expires)
path_cookie = @agent.cookies.find { |k| k.name == "a_path" }
- assert_not_nil(path_cookie, "Path cookie is nil")
+ assert(path_cookie, "Path cookie is nil")
assert_equal("some_path", path_cookie.value)
assert_equal(true, Time.now < path_cookie.expires)
no_path_cookie = @agent.cookies.find { |k| k.name == "no_path" }
- assert_not_nil(no_path_cookie, "No path cookie is nil")
+ assert(no_path_cookie, "No path cookie is nil")
assert_equal("no_path", no_path_cookie.value)
assert_equal("/", no_path_cookie.path)
assert_equal(true, Time.now < no_path_cookie.expires)
View
@@ -1,6 +1,6 @@
require "helper"
-class TestFormAction < Test::Unit::TestCase
+class TestFormAction < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
@page = @agent.get("http://localhost/tc_form_action.html")
View
@@ -1,6 +1,6 @@
require "helper"
-class TestFormHash < Test::Unit::TestCase
+class TestFormHash < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
@page = @agent.get('http://localhost/form_multival.html')
@@ -9,31 +9,28 @@ def setup
def test_form_hash
form = @page.form_with(:name => 'post_form')
- assert_not_nil(form)
field_length = form.fields.length
assert_nil(form['intarweb'])
form['intarweb'] = 'Aaron'
- assert_not_nil(form['intarweb'])
+ assert form['intarweb']
assert_equal(field_length + 1, form.fields.length)
end
def test_add_field_via_hash
form = @page.form_with(:name => 'post_form')
- assert_not_nil(form)
field_length = form.fields.length
assert_nil(form['intarweb'])
form['intarweb'] = 'Aaron'
- assert_not_nil(form['intarweb'])
+ assert form['intarweb']
assert_equal(field_length + 1, form.fields.length)
end
def test_fields_as_hash
form = @page.form_with(:name => 'post_form')
- assert_not_nil(form)
assert_equal(2, form.fields_with(:name => 'first').length)
form['first'] = 'Aaron'
@@ -45,12 +42,13 @@ def test_keys
@page = @agent.get('http://localhost/empty_form.html')
form = @page.forms.first
- assert_not_nil(form)
assert(!form.has_field?('name'))
assert(!form.has_value?('Aaron'))
assert_equal(0, form.keys.length)
assert_equal(0, form.values.length)
+
form['name'] = 'Aaron'
+
assert(form.has_field?('name'))
assert(form.has_value?('Aaron'))
assert_equal(1, form.keys.length)
View
@@ -1,6 +1,6 @@
require "helper"
-class TestFormButtons < Test::Unit::TestCase
+class TestFormButtons < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end
View
@@ -1,6 +1,6 @@
require "helper"
-class FramesMechTest < Test::Unit::TestCase
+class FramesMechTest < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end
View
@@ -1,6 +1,6 @@
require "helper"
-class TestHeaders < Test::Unit::TestCase
+class TestHeaders < MiniTest::Unit::TestCase
def setup
@headers = Mechanize::Headers.new
@headers['content-type'] = 'text/html'
View
@@ -1,6 +1,6 @@
require "helper"
-class TestHistory < Test::Unit::TestCase
+class TestHistory < MiniTest::Unit::TestCase
Node = Struct.new :href, :inner_text
@@ -1,6 +1,6 @@
require "helper"
-class HistoryAddedTest < Test::Unit::TestCase
+class HistoryAddedTest < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end
@@ -1,6 +1,6 @@
require "helper"
-class TestCheckBoxes < Test::Unit::TestCase
+class TestCheckBoxes < MiniTest::Unit::TestCase
def test_field
f = Mechanize::Form::Field.new({'name' => 'a&amp;b'}, 'a&amp;b')
assert_equal('a&b', f.name)
@@ -1,6 +1,6 @@
require "helper"
-class TestIfModifiedSince < Test::Unit::TestCase
+class TestIfModifiedSince < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end
View
@@ -1,6 +1,6 @@
require "helper"
-class ImagesMechTest < Test::Unit::TestCase
+class ImagesMechTest < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end
View
@@ -2,7 +2,7 @@
require 'helper'
-class TestMechanize < Test::Unit::TestCase
+class TestMechanize < MiniTest::Unit::TestCase
KEY = OpenSSL::PKey::RSA.new 512
name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
@@ -91,32 +91,31 @@ def test_click
@mech.user_agent_alias = 'Mac Safari'
page = @mech.get("http://localhost/frame_test.html")
link = page.link_with(:text => "Form Test")
- assert_not_nil(link)
+
page = @mech.click(link)
+
assert_equal("http://localhost/form_test.html",
- @mech.history.last.uri.to_s)
+ @mech.history.last.uri.to_s)
end
def test_click_frame_hpricot_style
page = @mech.get("http://localhost/frame_test.html")
-
link = (page/"//frame[@name='frame2']").first
- assert_not_nil(link)
+
page = @mech.click(link)
+
assert_equal("http://localhost/form_test.html",
- @mech.history.last.uri.to_s)
+ @mech.history.last.uri.to_s)
end
def test_click_hpricot_style # HACK move to test_divide in Page
page = @mech.get("http://localhost/frame_test.html")
-
link = (page/"//a[@class='bar']").first
- assert_not_nil(link)
page = @mech.click(link)
assert_equal("http://localhost/form_test.html",
- @mech.history.last.uri.to_s)
+ @mech.history.last.uri.to_s)
end
def test_click_link
@@ -216,8 +215,8 @@ def test_get_anchor
end
def test_get_bad_url
- assert_raise ArgumentError do
- @mech.get('/foo.html')
+ assert_raises ArgumentError do
+ @mech.get '/foo.html'
end
end
@@ -383,8 +382,9 @@ def test_get_http_refresh_disabled
def test_get_kcode
$KCODE = 'u'
page = @mech.get("http://localhost/?a=#{[0xd6].pack('U')}")
- assert_not_nil(page)
+
assert_equal('http://localhost/?a=%D6', page.uri.to_s)
+
$KCODE = 'NONE'
end unless RUBY_VERSION >= '1.9.0'
@@ -426,9 +426,10 @@ def test_get_referer
end
def test_get_referer_file
- assert_nothing_raised do
- @mech.get('http://localhost', [], Mechanize::File.new(URI.parse('http://tenderlovemaking.com/crossdomain.xml')))
- end
+ uri = URI.parse 'http://tenderlovemaking.com/crossdomain.xml'
+ file = Mechanize::File.new uri
+
+ @mech.get('http://localhost', [], file)
# HACK no assertion of behavior
end
@@ -448,9 +449,9 @@ def test_get_referer_none
end
def test_get_scheme_unsupported
- assert_raise(Mechanize::UnsupportedSchemeError) {
+ assert_raises Mechanize::UnsupportedSchemeError do
@mech.get('ftp://server.com/foo.html')
- }
+ end
end
def test_get_space
@@ -470,15 +471,11 @@ def test_get_tilde
end
def test_get_weird
- assert_nothing_raised {
- @mech.get('http://localhost/?action=bing&bang=boom=1|a=|b=|c=')
- }
- assert_nothing_raised {
- @mech.get('http://localhost/?a=b&#038;b=c&#038;c=d')
- }
- assert_nothing_raised {
- @mech.get("http://localhost/?a=#{[0xd6].pack('U')}")
- }
+ @mech.get('http://localhost/?action=bing&bang=boom=1|a=|b=|c=')
+ @mech.get('http://localhost/?a=b&#038;b=c&#038;c=d')
+ @mech.get("http://localhost/?a=#{[0xd6].pack('U')}")
+
+ # HACK no assertion of behavior
end
def test_get_yield
@@ -650,7 +647,7 @@ def test_set_proxy
def test_submit_bad_form_method
page = @mech.get("http://localhost/bad_form_test.html")
- assert_raise ArgumentError do
+ assert_raises ArgumentError do
@mech.submit(page.forms.first)
end
end
Oops, something went wrong.

0 comments on commit fd76666

Please sign in to comment.