test/tc_shorturl.rb in shorturl-0.0.1 vs test/tc_shorturl.rb in shorturl-0.1.0

- old
+ new

@@ -6,17 +6,55 @@ $:.unshift($test_lib_dir) require "test/unit" require "shorturl" +# Make +get_short_url+ public so we can test it +class ShortURLModified < ShortURL + public_class_method :get_short_url +end + + + class TestShortURL < Test::Unit::TestCase def setup @url = "http://darkhost.mine.nu:81/~vince/rails/tutorial.html" end def test_shorten assert ShortURL.shorten(@url) == "http://rubyurl.com/Q9ToW" assert ShortURL.shorten(@url, :rubyurl) == "http://rubyurl.com/Q9ToW" assert ShortURL.shorten(@url, :tinyurl) == "http://tinyurl.com/9mop8" assert_raise(ArgumentError) { ShortURL.shorten(@url, :foobar) } + end + + def test_get_short_url + post_string = "post('/create.php', 'url=#@url')" + assert_raise(NoMethodError) { ShortURL.get_short_url(nil, nil, nil) {} } + + assert_nothing_raised do + ShortURLModified.get_short_url("tinyurl.com", + 200, + post_string) { |body| } + end + + assert_nil(ShortURLModified.get_short_url("askjldakjsbfk", + 200, + "") { |body| } ) + + assert_nil(ShortURLModified.get_short_url("tinyurl.com", + 404, + post_string) { |body| } ) + + assert_nil(ShortURLModified.get_short_url("tinyurl.com", + 200, + "post('/foobar.php', nil)") { |body| } ) + end + + def test_rubyurl + assert_raise(NoMethodError) { ShortURL.rubyurl(@url) } + end + + def test_tinyurl + assert_raise(NoMethodError) { ShortURL.tinyurl(@url) } end end