Sha256: 78e2fdbf00552cca7699e21fb699ca9c421fec3362c7bb89f470f2fc79dd6994

Contents?: true

Size: 1.97 KB

Versions: 40

Compression:

Stored size: 1.97 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe Typhoeus::RemoteProxyObject do
  before(:each) do
    @easy = Typhoeus::Easy.new
    @easy.method = :get
    @easy.url    = "http://localhost:3001"
  end
  
  it "should take a caller and call the clear_memoized_proxy_objects" do
    clear_proxy = lambda {}
    clear_proxy.should_receive(:call)
    response = Typhoeus::RemoteProxyObject.new(clear_proxy, @easy)
    response.code.should == 200
  end

  it "should take an easy object and return the body when requested" do
    response = Typhoeus::RemoteProxyObject.new(lambda {}, @easy)
    @easy.response_code.should == 0
    response.code.should == 200
  end
  
  it "should perform requests only on the first access" do
    response = Typhoeus::RemoteProxyObject.new(lambda {}, @easy)
    response.code.should == 200
    Typhoeus.should_receive(:perform_easy_requests).exactly(0).times
    response.code.should == 200
  end

  it "should set the requested_url and requested_http_method on the response" do
    response = Typhoeus::RemoteProxyObject.new(lambda {}, @easy)
    response.requested_url.should == "http://localhost:3001"
    response.requested_http_method.should == :get
  end
  
  it "should call the on_success method with an easy object and proxy to the result of on_success" do
    klass = Class.new do
      def initialize(r)
        @response = r
      end
      
      def blah
        @response.code
      end
    end
    
    k = Typhoeus::RemoteProxyObject.new(lambda {}, @easy, :on_success => lambda {|e| klass.new(e)})
    k.blah.should == 200
  end
  
  it "should call the on_failure method with an easy object and proxy to the result of on_failure" do
    klass = Class.new do
      def initialize(r)
        @response = r
      end
      
      def blah
        @response.code
      end
    end
    @easy.url = "http://localhost:3005" #bad port
    k = Typhoeus::RemoteProxyObject.new(lambda {}, @easy, :on_failure => lambda {|e| klass.new(e)})
    k.blah.should == 0
  end
end

Version data entries

40 entries across 40 versions & 5 rubygems

Version Path
typhoeus-0.1.22 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.21 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.20 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.19 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.18 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.17 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.16 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.15 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus_curly-0.1.14 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.14 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.13 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.12 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.11 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.10 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.9 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.8 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.7 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.6 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.5 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.1.4 spec/typhoeus/remote_proxy_object_spec.rb