Sha256: 9043db80dee43cc19990f4b1662e5f02eeedea6240212ed2c1863cae1937aaf3

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

require File.expand_path(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

14 entries across 14 versions & 4 rubygems

Version Path
marnen-typhoeus-0.3.7 spec/typhoeus/remote_proxy_object_spec.rb
marnen-typhoeus-0.3.6 spec/typhoeus/remote_proxy_object_spec.rb
marnen-typhoeus-0.3.5 spec/typhoeus/remote_proxy_object_spec.rb
marnen-typhoeus-0.3.4 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.3.3 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.3.2 spec/typhoeus/remote_proxy_object_spec.rb
xenda-typhoeus-0.2.4 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.2.4 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.2.3 spec/typhoeus/remote_proxy_object_spec.rb
arachni-typhoeus-0.2.0.2 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.2.2 spec/typhoeus/remote_proxy_object_spec.rb
arachni-typhoeus-0.2.0.1 spec/typhoeus/remote_proxy_object_spec.rb
arachni-typhoeus-0.2.0 spec/typhoeus/remote_proxy_object_spec.rb
typhoeus-0.2.1 spec/typhoeus/remote_proxy_object_spec.rb