Sha256: 6ed6e2d2a7b61128592d5846a5204fcf96921d8e8eec1a53cba5ebd031606cf2

Contents?: true

Size: 1.98 KB

Versions: 14

Compression:

Stored size: 1.98 KB

Contents

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

describe Typhoeus::Easy do
  before(:all) do
    @pid = start_method_server(3002)
  end
  
  after(:all) do
    stop_method_server(@pid)
  end

  it "should save easy handles that get added" do
    multi = Typhoeus::Multi.new
    easy = Typhoeus::Easy.new
    easy.url = "http://localhost:3002"
    easy.method = :get

    multi.add(easy)
    multi.easy_handles.should == [easy]
    multi.perform
    multi.easy_handles.should == []
  end
  
  it "should be reusable" do
    easy = Typhoeus::Easy.new
    easy.url = "http://localhost:3002"
    easy.method = :get
    
    multi = Typhoeus::Multi.new
    multi.add(easy)
    multi.perform
    easy.response_code.should == 200
    easy.response_body.should include("METHOD=GET")
    
    e2 = Typhoeus::Easy.new
    e2.url = "http://localhost:3002"
    e2.method = :post
    multi.add(e2)
    multi.perform
    
    e2.response_code.should == 200
    e2.response_body.should include("METHOD=POST")
  end
  
  it "should perform easy handles added after the first one runs" do
    easy = Typhoeus::Easy.new
    easy.url = "http://localhost:3002"
    easy.method = :get
    multi = Typhoeus::Multi.new
    multi.add(easy)

    e2 = Typhoeus::Easy.new
    e2.url = "http://localhost:3002"
    e2.method = :post
    easy.on_success do |e|
      multi.add(e2)
    end
    
    multi.perform
    easy.response_code.should == 200
    easy.response_body.should include("METHOD=GET")    
    e2.response_code.should == 200
    e2.response_body.should include("METHOD=POST")    
  end
  
  # it "should do multiple gets" do
    # multi = Typhoeus::Multi.new
    # 
    # handles = []
    # 5.times do |i|
    #   easy = Typhoeus::Easy.new
    #   easy.url = "http://localhost:3002"
    #   easy.method = :get
    #   easy.on_success {|e| puts "get #{i} succeeded"}
    #   easy.on_failure {|e| puts "get #{i} failed with #{e.response_code}"}
    #   handles << easy
    #   multi.add(easy)
    # end
    # 
    # multi.perform
  # end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
abhay-typhoeus-0.0.22 spec/typhoeus/multi_spec.rb
dbalatero-typhoeus-0.0.20 spec/typhoeus/multi_spec.rb
dbalatero-typhoeus-0.0.21 spec/typhoeus/multi_spec.rb
dbalatero-typhoeus-0.0.22 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.0.20 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.0.22 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.0.23 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.0.24 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.1.0 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.1.1 spec/typhoeus/multi_spec.rb
pauldix-typhoeus-0.1.2 spec/typhoeus/multi_spec.rb
sandofsky-typhoeus-0.1.3 spec/typhoeus/multi_spec.rb
typhoeus-0.1.3 spec/typhoeus/multi_spec.rb
typhoeus-0.1.2 spec/typhoeus/multi_spec.rb