spec/session_spec.rb in patron-0.4.9 vs spec/session_spec.rb in patron-0.4.10
- old
+ new
@@ -19,11 +19,11 @@
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
## THE SOFTWARE.
##
## -------------------------------------------------------------------
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require File.expand_path("./spec") + '/spec_helper.rb'
require 'webrick'
require 'base64'
require 'fileutils'
describe Patron::Session do
@@ -172,10 +172,16 @@
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 upload a multipart with :post" do
+ response = @session.post_multipart("/test", { :test_data => "123" }, { :test_file => "VERSION.yml" } )
+ body = YAML::load(response.body)
+ body.request_method.should == "POST"
+ end
it "should raise when no file is provided to :post" do
lambda { @session.post_file("/test", nil) }.should raise_error(ArgumentError)
end
@@ -216,9 +222,27 @@
session.base_url = "http://localhost:9001"
session.post_file("/test", "VERSION.yml")
end
end
threads.each {|t| t.join }
+ end
+
+ it "should limit the buffer_size" do
+ # Buffer size is tricky to test, as it only affects the buffer size for each
+ # read and it's not really visible at this, higher level. It's also only a
+ # suggestion rather than a command so it may not even take affect. Currently
+ # we just test that the response completes without any issues, it would be nice
+ # to have a more robust test here.
+ @session.buffer_size = 1
+
+ body = nil
+
+ lambda {
+ response = @session.get("/test")
+ body = YAML::load(response.body)
+ }.should_not raise_error
+
+ body.request_method.should == "GET"
end
def encode_authz(user, passwd)
"Basic " + Base64.encode64("#{user}:#{passwd}").strip
end