Sha256: a3a35f696dcf5ad871fcbcacc23ea689557570efddcdbea12f46498365415653

Contents?: true

Size: 1.33 KB

Versions: 11

Compression:

Stored size: 1.33 KB

Contents

$test_lib_dir = File.join(File.dirname(__FILE__), "..", "lib")
$:.unshift($test_lib_dir)

require "test/unit"
require "uri"
require "longurl/exceptions"
require "longurl/url"

class TestURL < Test::Unit::TestCase
  
  BadURLs = ["http:",
             "http://",
             "http://hoth.entp..."]
  
  NotHTTPURLs = ["bleh",
                 "bleh://",
                 "bleh://asfd.com",
                 "ftp://asdf.com",
                 "google.com",
                 "asdf@toto.com",
                 "httpd://asdf.com"]
                 
  GoodURLs = ["http://www.google.com", "https://rubyonrails.org"]

  def test_check_should_raise_invalid_url_if_url_is_nil
    assert_raise(LongURL::InvalidURL) { LongURL::URL.check nil }
  end
  
  def test_check_should_raise_invalid_url_if_url_is_empty
    assert_raise(LongURL::InvalidURL) { LongURL::URL.check "" }
  end
  
  def test_check_should_raise_invalid_url_if_url_is_invalid
    BadURLs.each {|bad_url| assert_raise(LongURL::InvalidURL) { LongURL::URL.check bad_url } }
  end
  
  def test_check_should_raise_invalid_url_if_url_is_not_http
    NotHTTPURLs.each {|bad_url| assert_raise(LongURL::InvalidURL) { LongURL::URL.check bad_url } }
  end
  
  def test_check_should_returns_parsed_url_on_success
    GoodURLs.each {|good_url| assert_equal URI.parse(good_url), LongURL::URL.check(good_url)}
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
chuyeow-longurl-0.1.5 test/url_test.rb
jakimowicz-longurl-0.1.3 test/url_test.rb
jakimowicz-longurl-0.1.4 test/url_test.rb
jakimowicz-longurl-0.1.5 test/url_test.rb
jakimowicz-longurl-0.1.6 test/url_test.rb
ivey-longurl-0.1.7 test/url_test.rb
longurl-0.1.6 test/url_test.rb
longurl-0.1.5 test/url_test.rb
longurl-0.1.4 test/url_test.rb
longurl-0.1.3 test/url_test.rb
longurl-0.1.2 test/url_test.rb