Sha256: 477d375f7bd6cfe62b05c73ed43d6f1440da80eb8bcf9b41a6b685211f9303b9

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 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"]
                 
  GoodURL = "http://www.google.com"

  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
    assert_equal URI.parse(GoodURL), LongURL::URL.check(GoodURL)
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
jakimowicz-longurl-0.1.1 test/url_test.rb
longurl-0.1.0 test/url_test.rb
longurl-0.1.1 test/url_test.rb