Sha256: 3c92cbdce09913766abda9b2edc4a3b192407726e055e2f680531c25c5f71261
Contents?: true
Size: 1.62 KB
Versions: 4
Compression:
Stored size: 1.62 KB
Contents
require "spec_helper" describe SocialAvatarProxy::RemoteFileResolver do subject do SocialAvatarProxy::RemoteFileResolver.new(url, limit) end let(:url) { "http://www.example.com/" } let(:limit) { 5 } let(:redirect_response) do response = Net::HTTPRedirection.new("1.1", 301, "Moved") response["location"] = url response end let(:successful_response) do response = Net::HTTPSuccess.new("1.1", 200, "Success") response.body = "data" response end context "when the response redirects permanently" do before(:each) do subject.class.any_instance.stub(:perform_request).and_return(redirect_response) end it "should throw an exception" do expect { subject.resolve }.to raise_error(SocialAvatarProxy::TooManyRedirectsError) end end context "when the response redirects less times than the limit" do let(:redirect_count) { limit - 1 } let(:responses) do set = (1..redirect_count).to_a.map { redirect_response } set << successful_response set end before(:each) do subject.class.any_instance.stub(:perform_request).and_return do responses.delete_at(0) end end it "should return the successful response" do expect(subject.resolve).to eq(successful_response) end end context "when the response times out" do before(:each) do subject.should_receive(:perform_request).once.and_raise(Timeout::Error) end it "should throw an exception" do expect { subject.resolve }.to raise_error(SocialAvatarProxy::TimeoutError) end end end
Version data entries
4 entries across 4 versions & 1 rubygems