Sha256: 98cf4614076095194bc8547ee5ebecc4c43b79955e11a4a4c0d19b519d2f08d0

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require 'test/unit'
require 'bitly'

class TestBitly < Test::Unit::TestCase
  
  def setup
    @api_key = 'R_7776acc394294b2b0ad2c261a91c483d'
    @login = 'philnash'
    @bitly = Bitly.new(@login,@api_key)
  end
  
  # not a good test, but it makes sure things are working for now.
  def test_returns_short_url
    url = @bitly.shorten("http://google.com")
    assert_equal url.class, Bitly::Url
    assert_equal url.long_url, "http://google.com"
    assert_equal url.short_url, "http://bit.ly/wQaT"
    urls = @bitly.shorten(["http://google.com","http://cnn.com"])
    assert_equal urls[0].long_url, "http://google.com"
    assert_equal urls[0].short_url, "http://bit.ly/wQaT"
  end
  
  def test_returns_a_long_url
    urls = @bitly.expand(["2bYgqR","1RmnUT"])
    assert_equal urls[0].class, Bitly::Url
    assert_equal urls[0].long_url, "http://cnn.com"
    assert_equal urls[0].hash, "2bYgqR"
    assert_equal urls[1].long_url, "http://google.com"
    assert_equal urls[1].hash, "1RmnUT"
    url = @bitly.expand("http://bit.ly/wQaT")
    assert_equal url.class, Bitly::Url
    assert_equal url.short_url, "http://bit.ly/wQaT"
    assert_equal url.long_url, "http://google.com/"
    assert_equal url.hash, "wQaT"
    url2 = @bitly.expand("wQaT")
    assert_equal url2.class, Bitly::Url
    assert_equal url2.hash, "wQaT"
    assert_equal url2.short_url, "http://bit.ly/wQaT"
    assert_equal url2.long_url, "http://google.com/"
  end
  
  def test_returns_keyword_url
    #kind of ghetto test but we need it to be different every time
    require 'digest/sha1'
    keyword = Digest::SHA1.hexdigest(DateTime.now.to_s)

    url = @bitly.shorten("http://google.com", keyword)
    assert_equal url.short_keyword_url, "http://bit.ly/#{keyword}"
  end

  def test_returns_error_on_existing_keyword
    keyword = 'apple'
    assert_raise BitlyError do
      @bitly.shorten("http://apple.com/itunes", keyword)
    end
  end

  
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
philnash-bitly-0.1.2 test/test_bitly.rb