Skip to content

Commit ba69266

Browse files
committed
Update the tests for the shorten command
1. Retain a test for the older 201 response but use https. 2. Add a test for the 200 response that git.io currently returns. Updates: #240
1 parent f979cd0 commit ba69266

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/gist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def shorten(url)
268268
response = http(GIT_IO_URL, request)
269269
case response.code
270270
when "200"
271-
URI.join(GIT_IO_URL, response.body)
271+
URI.join(GIT_IO_URL, response.body).to_s
272272
when "201"
273273
response['Location']
274274
else

spec/shorten_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
describe '...' do
22
before do
33
stub_request(:post, /api\.github.com\/gists/).to_return(:body => '{"html_url": "http://github.com/"}')
4-
stub_request(:post, "http://git.io/").to_return(:status => 201, :headers => { 'Location' => 'http://git.io/XXXXXX' })
54
end
65

7-
it "should return a shortened version of the URL" do
8-
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "http://git.io/XXXXXX"
6+
it "should return a shortened version of the URL when response is 200" do
7+
stub_request(:post, "https://git.io/create").to_return(:status => 200, :body => 'XXXXXX')
8+
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
99
end
10-
end
1110

11+
it "should return a shortened version of the URL when response is 201" do
12+
stub_request(:post, "https://git.io/create").to_return(:status => 201, :headers => { 'Location' => 'https://git.io/XXXXXX' })
13+
Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX"
14+
end
15+
end

0 commit comments

Comments
 (0)