Sha256: bbd8382d21637c9361a3355941a84a2885a0a543f43d69d10f5e28aa435ebe67

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

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

require "test/unit"
require "longurl/exceptions"
require "longurl/service"

class TestService < Test::Unit::TestCase
  
  ShortToLong = {:tiny_url => {
                  "http://tinyurl.com/cnuw9a" => "http://fabien.jakimowicz.com",
                  "http://tinyurl.com/blnhsg" => "http://www.google.com/search?q=number+of+horns+on+a+unicorn&ie=UTF-8"
                              },
                 :is_gd => {
                   "http://is.gd/iUKg" => "http://fabien.jakimowicz.com",
                   "http://is.gd/iYCo" => "http://www.google.com/search?q=number+of+horns+on+a+unicorn&ie=UTF-8"
                 }
                }

  def setup
    @service = LongURL::Service.new
  end
  
  def test_query_should_raise_invalid_url_if_url_is_nil
    assert_raise(LongURL::InvalidURL) { @service.query(nil) }
  end

  def test_query_should_raise_invalid_url_if_url_is_empty
    assert_raise(LongURL::InvalidURL) { @service.query('') }
  end

  def test_query_should_returns_given_url_if_not_shorten_url
    assert_equal "http://www.google.com", @service.query("http://www.google.com")
  end

  def test_query_should_returns_expanded_url_for_tiny_url
    ShortToLong[:tiny_url].each {|short, long| assert_equal long, @service.query(short)}
  end

  def test_query_should_returns_expanded_url_for_is_gd
    ShortToLong[:is_gd].each {|short, long| assert_equal long, @service.query(short)}
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
jakimowicz-longurl-0.0.2 test/service_test.rb
jakimowicz-longurl-0.0.3 test/service_test.rb
jakimowicz-longurl-0.0.4 test/service_test.rb
longurl-0.0.3 test/service_test.rb
longurl-0.0.4 test/service_test.rb
longurl-0.0.2 test/service_test.rb