Sha256: 13f57ab22238f7d0f19b1770fdeeba80408bf3393ffeb671bb087a667dc5712f

Contents?: true

Size: 1.61 KB

Versions: 11

Compression:

Stored size: 1.61 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::TooManyRedirects)
    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

11 entries across 11 versions & 1 rubygems

Version Path
social-avatar-proxy-1.0.1 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-1.0.0 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.9 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.8 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.7 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.6 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.5 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.4 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.3 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.2 spec/social_avatar_proxy/remote_file_resolver_spec.rb
social-avatar-proxy-0.0.1 spec/social_avatar_proxy/remote_file_resolver_spec.rb