Sha256: 8e348130b81bcc13b315f7c8040f0043af99d5621f4b9b4f140b15c9db2b4446

Contents?: true

Size: 1.94 KB

Versions: 14

Compression:

Stored size: 1.94 KB

Contents

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

14 entries across 14 versions & 4 rubygems

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