test/tc_shorturl.rb in shorturl-0.6.0 vs test/tc_shorturl.rb in shorturl-0.7.0
- old
+ new
@@ -6,37 +6,30 @@
$:.unshift($test_lib_dir)
require "test/unit"
require "shorturl"
+class String
+ def url?
+ self[0..6].downcase == "http://"
+ end
+end
class TestShortURL < Test::Unit::TestCase
def setup
- @url = "http://darkhost.mine.nu:81/~vince/rails/tutorial.html"
+ @url = "http://groups.google.com/group/comp.lang.ruby/"
end
def test_shorten
# Default service (RubyURL)
- assert ShortURL.shorten(@url) == "http://rubyurl.com/Q9ToW"
+ assert ShortURL.shorten(@url).url?
- # All the services (in the order in which they were added)
- assert ShortURL.shorten(@url, :rubyurl) == "http://rubyurl.com/Q9ToW"
- assert ShortURL.shorten(@url, :tinyurl) == "http://tinyurl.com/9mop8"
- assert ShortURL.shorten(@url, :shorl) =~ /^http:\/\/shorl.com/ # Never the same URL
- assert ShortURL.shorten(@url, :snipurl) == "http://snipurl.com/fbkl"
- assert ShortURL.shorten(@url, :metamark) == "http://xrl.us/ga8c"
- assert ShortURL.shorten(@url, :makeashorterlink) == "http://makeashorterlink.com/?O1752235A"
- assert ShortURL.shorten(@url, :skinnylink) == "http://skinnylink.com?nqvcce"
- assert ShortURL.shorten(@url, :linktrim) =~ /http:\/\/linktrim/ # Never the same URL
- assert ShortURL.shorten(@url, :shorterlink) == "http://shorterlink.com/?PQD096"
- assert ShortURL.shorten(@url, :minilink) == "http://lnk.nu/darkhost.mine.nu:81/2zr.html"
- assert ShortURL.shorten(@url, :lns) == "http://ln-s.net/5UL"
- assert ShortURL.shorten(@url, :fyad) == "http://fyad.org/15zu"
- assert ShortURL.shorten(@url, :d62) == "http://y5o49.d62.net"
- assert ShortURL.shorten(@url, :shiturl) == "http://www.shiturl.com/b53b3a"
- assert ShortURL.shorten(@url, :littlink) == "http://littlink.com/2kc87"
- assert ShortURL.shorten(@url, :clipurl) == "http://clipurl.com?BH"
+ # All the services (I can't test exact URLs since they seem to
+ # change semi regularly)
+ ShortURL.valid_services.each do |service|
+ assert ShortURL.shorten(@url, service).url?
+ end
-
+ # An invalid service
assert_raise(InvalidService) { ShortURL.shorten(@url, :foobar) }
end
end