Permalink
Browse files

Allow to run requests individually on client

  • Loading branch information...
1 parent a6218f8 commit b2b57c14a14a81b127a1461d0205842f63b6ed16 @drogus drogus committed Mar 7, 2011
Showing with 32 additions and 0 deletions.
  1. +4 −0 lib/kirk/client.rb
  2. +28 −0 spec/client/client_spec.rb
View
4 lib/kirk/client.rb
@@ -23,6 +23,10 @@ def self.group(opts = {}, &blk)
%w(request head get post put delete).each do |method|
class_eval <<-RUBY
def self.#{method}(*args, &blk)
+ client.#{method}(*args, &blk)
+ end
+
+ def #{method}(*args, &blk)
g = group { |g| g.#{method}(*args, &blk) }
g.responses.first
end
View
28 spec/client/client_spec.rb
@@ -10,6 +10,34 @@
start echo_app_path('config.ru')
end
+ it "allows to run individual request" do
+ client = Kirk::Client.new
+ response = client.request :GET, "http://localhost:9090/foo", nil, "foobar"
+
+ response = parse_response(response)
+ response["PATH_INFO"].should == "/foo"
+ response["rack.input"].should == "foobar"
+ end
+
+ it "allows to run requests shortcuts on client" do
+ client = Kirk::Client.new
+ response = parse_response client.get("http://localhost:9090/foo")
+ response["PATH_INFO"].should == "/foo"
+ response["REQUEST_METHOD"].should == "GET"
+
+ response = parse_response client.post("http://localhost:9090/foo")
+ response["PATH_INFO"].should == "/foo"
+ response["REQUEST_METHOD"].should == "POST"
+
+ response = parse_response client.put("http://localhost:9090/foo")
+ response["PATH_INFO"].should == "/foo"
+ response["REQUEST_METHOD"].should == "PUT"
+
+ response = parse_response client.delete("http://localhost:9090/foo")
+ response["PATH_INFO"].should == "/foo"
+ response["REQUEST_METHOD"].should == "DELETE"
+ end
+
it "allows to pass block for request" do
handler = Class.new do
def initialize(buffer)

0 comments on commit b2b57c1

Please sign in to comment.