Sha256: 7df2d8c13403bfbe748972770c3eb33203d0dd486cf978f6ffdd3144b5f94ec2

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

# tc_shortcut.rb
#
#   Created by Vincent Foley on 2005-06-01

$test_lib_dir = File.join(File.dirname(__FILE__), "..", "lib")
$:.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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shorturl-0.1.0 test/tc_shorturl.rb