spec/uncoil_spec.rb in uncoil-1.1.0 vs spec/uncoil_spec.rb in uncoil-1.2.0
- old
+ new
@@ -1,102 +1,91 @@
require 'spec_helper'
-require 'uncoil'
describe Uncoil do
subject { Uncoil.new(:bitlyuser => CREDENTIALS['bitlyuser'], :bitlykey => CREDENTIALS['bitlykey'])}
- describe "#expand class method" do
- it "should successfully return a response object" do
- Uncoil.expand("http://tinyurl.com/736swvl").class.should eq Uncoil::Response
+ describe '#expand class method', :vcr => { :cassette_name => 'isgd_response' } do
+ it 'should successfully return a response object' do
+ Uncoil.expand('http://is.gd/gbKNRq').class.should eq Uncoil::Response
end
it "should bring back the correct link" do
- response = Uncoil.expand("http://tinyurl.com/736swvl")
- response.long_url.should eq "http://www.chinadaily.com.cn/usa/business/2011-11/08/content_14057648.htm"
+ response = Uncoil.expand('http://is.gd/gbKNRq')
+ response.long_url.should eq "http://www.google.com"
end
end
- describe "when using the submethods" do
+ describe "#expand instance method" do
- context "when trying to undo a bit.ly and bit.ly pro link" do
- it "should bring back the correct long link" do
- {"http://bit.ly/2EEjBl" => "http://www.cnn.com/", "http://cs.pn/vsZpra" => "http://www.c-spanvideo.org/program/CainNew" }.each { |short_url, long_url|
- subject.uncoil_bitly(short_url).should eq long_url
- }
- end
- end
-
- context "when trying to undo an is.gd link" do
- it "should bring back the correct long link" do
- subject.uncoil_isgd("http://is.gd/gbKNRq").should eq "http://www.google.com"
- end
- end
-
- context "when trying to undo from other services" do
- it "should bring back the correct long link" do
- subject.uncoil_other("http://tinyurl.com/736swvl").should eq "http://www.chinadaily.com.cn/usa/business/2011-11/08/content_14057648.htm"
- end
- end
- end
-
- describe "the main expand method" do
-
it "should raise an error for non-urls" do
subject.expand("a").error.should_not be_nil
end
- context "when expanding a link" do
+ def check_response(response, expected_result)
+ response.long_url.should eq expected_result[:long_url]
+ response.short_url.should eq expected_result[:short_url]
+ response.error.should eq expected_result[:error]
+ end
+
+ context 'for bitly api', :vcr => { :cassette_name => 'bitly_api' } do
- def check_response response, expected_result
- response.long_url.should eq expected_result[:long_url]
- response.short_url.should eq expected_result[:short_url]
- response.error.should eq expected_result[:error]
- end
-
- it "should expand bitly correctly" do
- expected_result = Hash[:long_url => "http://www.cnn.com/", :short_url => "http://bit.ly/2EEjBl", :error => nil]
- response = subject.expand("http://bit.ly/2EEjBl")
+ it 'should expand bitly correctly' do
+ expected_result = Hash[:long_url => 'http://www.cnn.com/', :short_url => 'http://bit.ly/2EEjBl', :error => nil]
+ response = subject.expand('http://bit.ly/2EEjBl')
check_response response, expected_result
end
- it "should expand bitlypro domains correctly" do
- expected_result = Hash[:long_url => "http://www.c-spanvideo.org/program/CainNew", :short_url => "http://cs.pn/vsZpra", :error => nil]
- response = subject.expand("http://cs.pn/vsZpra")
+ it 'should expand bitlypro domains correctly' do
+ expected_result = Hash[:long_url => 'http://www.c-spanvideo.org/program/CainNew', :short_url => 'http://cs.pn/vsZpra', :error => nil]
+ response = subject.expand('http://cs.pn/vsZpra')
check_response response, expected_result
end
-
- it "should expand isgd domains correctly" do
- expected_result = Hash[:long_url => "http://www.google.com", :short_url => "http://is.gd/gbKNRq", :error => nil]
- response = subject.expand("http://is.gd/gbKNRq")
+ end
+
+ context 'for isgd api', :vcr => { :cassette_name => 'isgd_api' } do
+ it 'should expand isgd domains correctly' do
+ expected_result = Hash[:long_url => 'http://www.google.com', :short_url => 'http://is.gd/gbKNRq', :error => nil]
+ response = subject.expand('http://is.gd/gbKNRq')
check_response response, expected_result
end
-
- it "should expand other shortened urls correctly" do
- expected_result = Hash[:long_url => "http://www.chinadaily.com.cn/usa/business/2011-11/08/content_14057648.htm", :short_url => "http://tinyurl.com/736swvl", :error => nil]
- response = subject.expand("http://tinyurl.com/736swvl")
+ end
+
+ context 'for other requests' do
+ it 'should expand other shortened urls correctly' do
+ expected_result = Hash[:long_url => 'http://paulgraham.com/', :short_url => 'http://tinyurl.com/p8o2', :error => nil]
+ response = subject.expand('http://tinyurl.com/p8o2')
check_response response, expected_result
end
+
+ it 'should expand https urls correctly' do
+ expected_result = Hash[:long_url => 'https://www.facebook.com/photo.php?fbid=436380063146407&l=7554e08219', :short_url => 'http://fb.me/6txI6APS5', :error => nil]
+ response = subject.expand('http://fb.me/6txI6APS5')
+ check_response response, expected_result
+ end
+ end
- context "with an array input" do
+ describe 'with an array input', :vcr => { :cassette_name => 'array_of_links' } do
- before(:all) {
- arr_of_links = ["http://bit.ly/2EEjBl","http://is.gd/gbKNRq","http://cs.pn/vsZpra"]
- @response = subject.expand(arr_of_links)
- }
+ arr_of_links = %w[http://bit.ly/2EEjBl http://is.gd/gbKNRq http://cs.pn/vsZpra]
- it "should return an array" do
- @response.class.should eq Array
- end
+ let(:resp) {subject.expand(arr_of_links) }
- it "should return an array of response objects" do
- @response.each { |r| r.class.should eq Uncoil::Response }
+ it 'should return an array' do
+ resp.class.should eq Array
end
- it "should successfully expand all links" do
- @expected_result = [Hash[:long_url => "http://www.cnn.com/", :short_url => "http://bit.ly/2EEjBl", :error => nil], Hash[:long_url => "http://www.google.com", :short_url => "http://is.gd/gbKNRq", :error => nil],Hash[:long_url => "http://www.c-spanvideo.org/program/CainNew", :short_url => "http://cs.pn/vsZpra", :error => nil]]
- @response.each_with_index { |response_array, index| check_response response_array, @expected_result[index] }
+ it 'should return an array of response objects' do
+ resp.each { |r| r.class.should eq Uncoil::Response }
end
+
+ it 'should successfully expand all links' do
+ @expected_result = [Hash[:long_url => 'http://www.cnn.com/', :short_url => 'http://bit.ly/2EEjBl', :error => nil],
+ Hash[:long_url => 'http://www.google.com', :short_url => 'http://is.gd/gbKNRq', :error => nil],
+ Hash[:long_url => 'http://www.c-spanvideo.org/program/CainNew', :short_url => 'http://cs.pn/vsZpra', :error => nil]]
+ resp.each_with_index { |response, index|
+ check_response(response, @expected_result[index])
+ }
end
end
end
end