spec/session_spec.rb in patron-0.3.2 vs spec/session_spec.rb in patron-0.4.0
- old
+ new
@@ -22,10 +22,11 @@
##
## -------------------------------------------------------------------
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'webrick'
require 'base64'
+require 'fileutils'
describe Patron::Session do
before(:each) do
@session = Patron::Session.new
@@ -37,10 +38,14 @@
escaped = @session.escape(string)
unescaped = @session.unescape(escaped)
unescaped.should == string
end
+ it "should raise an error when passed an invalid action" do
+ lambda { @session.request(:bogus, "/test", {}) }.should raise_error(ArgumentError)
+ end
+
it "should raise an error when no URL is provided" do
@session.base_url = nil
lambda {@session.get(nil)}.should raise_error(ArgumentError)
end
@@ -48,10 +53,19 @@
response = @session.get("/test")
body = YAML::load(response.body)
body.request_method.should == "GET"
end
+ it "should download content with :get and a file path" do
+ tmpfile = "/tmp/patron_test.yaml"
+ response = @session.get_file "/test", tmpfile
+ response.body.should be_nil
+ body = YAML::load_file(tmpfile)
+ body.request_method.should == "GET"
+ FileUtils.rm tmpfile
+ end
+
it "should include custom headers in a request" do
response = @session.get("/test", {"User-Agent" => "PatronTest"})
body = YAML::load(response.body)
body.header["user-agent"].should == ["PatronTest"]
end
@@ -101,23 +115,59 @@
response = @session.delete("/test")
body = YAML::load(response.body)
body.request_method.should == "DELETE"
end
+ it "should send a COPY request with :copy" do
+ response = @session.copy("/test", "/test2")
+ body = YAML::load(response.body)
+ body.request_method.should == "COPY"
+ end
+
+ it "should include a Destination header in COPY requests" do
+ response = @session.copy("/test", "/test2")
+ body = YAML::load(response.body)
+ body.header['destination'].first.should == "/test2"
+ end
+
it "should upload data with :put" do
data = "upload data"
response = @session.put("/test", data)
body = YAML::load(response.body)
body.request_method.should == "PUT"
body.header['content-length'].should == [data.size.to_s]
end
+ it "should upload a file with :put" do
+ response = @session.put_file("/test", "VERSION.yml")
+ body = YAML::load(response.body)
+ body.request_method.should == "PUT"
+ end
+
+ it "should use chunked encoding when uploading a file with :put" do
+ response = @session.put_file("/test", "VERSION.yml")
+ body = YAML::load(response.body)
+ body.header['transfer-encoding'].first.should == "chunked"
+ end
+
it "should upload data with :post" do
data = "upload data"
response = @session.post("/test", data)
body = YAML::load(response.body)
body.request_method.should == "POST"
body.header['content-length'].should == [data.size.to_s]
+ end
+
+ it "should upload a file with :post" do
+ response = @session.post_file("/test", "VERSION.yml")
+ body = YAML::load(response.body)
+ body.request_method.should == "POST"
+ end
+
+ it "should use chunked encoding when uploading a file with :post" do
+ response = @session.post_file("/test", "VERSION.yml")
+ body = YAML::load(response.body)
+ body.header['transfer-encoding'].first.should == "chunked"
end
it "should pass credentials as http basic auth" do
@session.username = "foo"
@session.password = "bar"