From ba692665b19999b761fd523b4ea632bf94635118 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 19 Mar 2016 07:45:33 +0530 Subject: [PATCH] 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: https://github.com/defunkt/gist/pull/240 --- lib/gist.rb | 2 +- spec/shorten_spec.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/gist.rb b/lib/gist.rb index 79933a1..5d395b7 100644 --- a/lib/gist.rb +++ b/lib/gist.rb @@ -268,7 +268,7 @@ def shorten(url) response = http(GIT_IO_URL, request) case response.code when "200" - URI.join(GIT_IO_URL, response.body) + URI.join(GIT_IO_URL, response.body).to_s when "201" response['Location'] else diff --git a/spec/shorten_spec.rb b/spec/shorten_spec.rb index 504e6d7..b65d705 100644 --- a/spec/shorten_spec.rb +++ b/spec/shorten_spec.rb @@ -1,11 +1,15 @@ describe '...' do before do stub_request(:post, /api\.github.com\/gists/).to_return(:body => '{"html_url": "http://github.com/"}') - stub_request(:post, "http://git.io/").to_return(:status => 201, :headers => { 'Location' => 'http://git.io/XXXXXX' }) end - it "should return a shortened version of the URL" do - Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "http://git.io/XXXXXX" + it "should return a shortened version of the URL when response is 200" do + stub_request(:post, "https://git.io/create").to_return(:status => 200, :body => 'XXXXXX') + Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX" end -end + it "should return a shortened version of the URL when response is 201" do + stub_request(:post, "https://git.io/create").to_return(:status => 201, :headers => { 'Location' => 'https://git.io/XXXXXX' }) + Gist.gist("Test gist", :output => :short_url, :anonymous => true).should == "https://git.io/XXXXXX" + end +end