Sha256: 33e2cf1e6c5cc12e5a673630a86db711048aa02d36d36a7df682a9efd284ebf9

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

require 'rspec'
require 'fakeweb'
require 'pixy'

FakeWeb.allow_net_connect = false

def escape_url(url)
  URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

API_URL                 = 'http://p.tl/api/api_simple.php'
url_to_shorten          = escape_url("https://github.com/narkoz/pixy")
invalid_url_to_shorten  = escape_url("^_^")

def load_fixture(name)
  File.open(File.dirname(__FILE__) + "/fixtures/#{name}.json").read
end

def fake_url(url, fixture_name)
  FakeWeb.register_uri(:get, url, :body => load_fixture(fixture_name))
end

fake_url "#{API_URL}?key=API_KEY&url=#{url_to_shorten}", 'ok'
fake_url "#{API_URL}?key=API_KEY&url=", 'empty_long_url'
fake_url "#{API_URL}?key=&url=#{url_to_shorten}", 'empty_api_key'
fake_url "#{API_URL}?key=invalid_API_KEY&url=#{url_to_shorten}", 'invalid_api_key'
fake_url "#{API_URL}?key=API_KEY&url=#{invalid_url_to_shorten}", 'invalid_long_url'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pixy-0.1.0 spec/spec_helper.rb