Sha256: a8391576ac4169a3c08219feb74d6895c29ff9d12b4a375c60d1742039ebc44b

Contents?: true

Size: 1.93 KB

Versions: 40

Compression:

Stored size: 1.93 KB

Contents

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

describe Typhoeus::Easy do
  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
    JSON.parse(easy.response_body)["REQUEST_METHOD"].should == "GET"
    
    e2 = Typhoeus::Easy.new
    e2.url = "http://localhost:3002"
    e2.method = :post
    multi.add(e2)
    multi.perform
    
    e2.response_code.should == 200
    JSON.parse(e2.response_body)["REQUEST_METHOD"].should == "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
    JSON.parse(easy.response_body)["REQUEST_METHOD"].should == "GET"
    e2.response_code.should == 200
    JSON.parse(e2.response_body)["REQUEST_METHOD"].should == "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

40 entries across 40 versions & 5 rubygems

Version Path
typhoeus-0.2.0 spec/typhoeus/multi_spec.rb
fblee-typhoeus-0.1.31 spec/typhoeus/multi_spec.rb
tech-angels-typhoeus-0.1.36 spec/typhoeus/multi_spec.rb
typhoeus-0.1.31 spec/typhoeus/multi_spec.rb
typhoeus-0.1.30 spec/typhoeus/multi_spec.rb
typhoeus-0.1.29 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.36 spec/typhoeus/multi_spec.rb
typhoeus-0.1.28 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.35 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.34 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.33 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.32 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.31 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.30 spec/typhoeus/multi_spec.rb
gravis-typhoeus-0.1.29 spec/typhoeus/multi_spec.rb
typhoeus-0.1.27 spec/typhoeus/multi_spec.rb
typhoeus-0.1.26 spec/typhoeus/multi_spec.rb
typhoeus-0.1.25 spec/typhoeus/multi_spec.rb
typhoeus-0.1.24 spec/typhoeus/multi_spec.rb
typhoeus-0.1.23 spec/typhoeus/multi_spec.rb