This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test shorten_url with faraday helpers
- Loading branch information
1 parent
709301d
commit c70fa42
Showing
2 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'test/unit' | ||
require File.expand_path('../../config/load', __FILE__) | ||
|
||
class ServiceTest < Test::Unit::TestCase | ||
class TestService < Service | ||
end | ||
|
||
def setup | ||
@stubs = Faraday::Adapter::Test::Stubs.new | ||
@service = TestService.new(:push, 'data', 'payload') | ||
@service.faraday = Faraday.new { |b| b.adapter(:test, @stubs) } | ||
end | ||
|
||
def test_url_shorten | ||
url = "http://github.com" | ||
bitly = "/shorten?apiKey=%s&login=%s&longUrl=%s&version=%s" % [ | ||
'R_261d14760f4938f0cda9bea984b212e4', 'github', 'http%3A%2F%2Fgithub.com', '2.0.1' ] | ||
@stubs.get bitly do | ||
[200, {}, { | ||
'errorCode' => 0, | ||
'results' => { | ||
url => {'shortUrl' => 'short'} | ||
} | ||
}.to_json] | ||
end | ||
|
||
assert_equal 'short', @service.shorten_url(url) | ||
end | ||
end |