Skip to content

Commit

Permalink
implemented most of the tests and added main test case test.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Landgraf committed Jan 31, 2011
1 parent 30f2c28 commit 7416856
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 25 deletions.
17 changes: 0 additions & 17 deletions base.rb

This file was deleted.

30 changes: 30 additions & 0 deletions test.rb
@@ -0,0 +1,30 @@
require 'rubygems'
require 'uri'
require 'benchmark'
require 'yajl'
require 'yajl/json_gem'

ITERATIONS = 1000
TESTS = []

def test_http(name, &block)
TESTS << [name, block]
end

URL = URI.parse("http://localhost/~vincentlandgraf/test.json")

dir = File.dirname(__FILE__)

Dir[File.join(dir, "test_*.rb")].each do |file|
require file
end

at_exit do
Benchmark.bm(20) do |x|
for name, block in TESTS do
x.report("testing #{name}") do
ITERATIONS.times(&block)
end
end
end
end
10 changes: 10 additions & 0 deletions test_curb.rb
@@ -0,0 +1,10 @@
require "curb"

c = Curl::Easy.new
test_http("curb") do
c.url = URL.to_s
c.headers["X-Test"] = "test"
c.perform
data = JSON.parse(c.body_str)
raise Exception.new unless data.first["number"] != 123123
end
8 changes: 8 additions & 0 deletions test_curl.rb
@@ -0,0 +1,8 @@
test_http("curl") do
header = {"X-Test" => "test"}
header_str = ""
header.each { |key, value| header_str += "-H \"#{key}: #{value}\" "}
response = `curl #{header_str} -s #{URL.to_s.inspect}`
data = JSON.parse(response)
raise Exception.new unless data.first["number"] != 123123
end
17 changes: 17 additions & 0 deletions test_em_http.rb
@@ -0,0 +1,17 @@
# require 'em-http'
#
# evm_count = ITERATIONS
# EventMachine.run do
# test_http("em-http") do
# http = EventMachine::HttpRequest.new(URL.to_s).get :head => {"X-Test" => "test"},
# :timeout => 60
#
# http.callback do
# data = JSON.parse(http.response)
# raise Exception.new unless data.first["number"] != 123123
# evm_count -= 1
# EventMachine.stop if evm_count <= 0
# end
# end
# end
#
16 changes: 16 additions & 0 deletions test_httparty.rb
@@ -0,0 +1,16 @@
require "httparty"

class PartyService
include HTTParty
base_uri URL.to_s

def fetch!
data = self.class.get(URL.path, "X-Test" => "test")
raise Exception.new unless data.first["number"] != 123123
end
end

party_service = PartyService.new
test_http("httparty") do
party_service.fetch!
end
1 change: 0 additions & 1 deletion test_httpclient.rb
@@ -1,4 +1,3 @@
require 'base'
require 'httpclient'

client = HTTPClient.new
Expand Down
1 change: 0 additions & 1 deletion test_httprb.rb
@@ -1,4 +1,3 @@
require 'base'
require 'httprb'

test_http("httprb") do
Expand Down
1 change: 0 additions & 1 deletion test_net_http.rb
@@ -1,4 +1,3 @@
require 'base'
require 'net/http'

test_http("net/http") do
Expand Down
1 change: 0 additions & 1 deletion test_patron.rb
@@ -1,4 +1,3 @@
require 'base'
require 'patron'

sess = Patron::Session.new
Expand Down
1 change: 0 additions & 1 deletion test_rest_client.rb
@@ -1,4 +1,3 @@
require 'base'
require 'restclient'

test_http("RestClient") do
Expand Down
1 change: 0 additions & 1 deletion test_righttp.rb
@@ -1,4 +1,3 @@
require 'base'
require 'righttp'

test_http("righttp") do
Expand Down
3 changes: 1 addition & 2 deletions test_rufus_jig.rb
@@ -1,8 +1,7 @@
require 'base'
require 'patron'
require 'rufus/jig'

h = Rufus::Jig::Http.new(URL.host, URL.port)
h = Rufus::Jig::Http.new(URL.host, URL.port, :timeout => 60)
test_http("rufus-jig") do
data = h.get(URL.path, "X-Test" => "test")
raise Exception.new unless data.first["number"] != 123123
Expand Down

0 comments on commit 7416856

Please sign in to comment.