2010-07-03 06:41:59 -04:00
|
|
|
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
2010-05-25 14:05:41 -04:00
|
|
|
|
|
|
|
require 'webmock/rspec'
|
2012-11-08 23:24:31 -05:00
|
|
|
include WebMock::API
|
2010-05-25 14:05:41 -04:00
|
|
|
|
|
|
|
describe RestClient::Request do
|
2010-05-30 03:51:59 -04:00
|
|
|
|
2010-05-25 14:05:41 -04:00
|
|
|
it "manage params for get requests" do
|
|
|
|
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
|
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should == 'foo'
|
2010-05-30 03:51:59 -04:00
|
|
|
|
|
|
|
stub_request(:get, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar', 'params' => 'a'}).to_return(:body => 'foo', :status => 200)
|
|
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should == 'foo'
|
2010-05-25 14:05:41 -04:00
|
|
|
end
|
2010-05-30 03:51:59 -04:00
|
|
|
|
2010-12-07 13:50:54 -05:00
|
|
|
it "can use a block to process response" do
|
|
|
|
response_value = nil
|
|
|
|
block = Proc.new do |http_response|
|
|
|
|
response_value = http_response.body
|
|
|
|
end
|
|
|
|
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
|
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}, :block_response => block)
|
|
|
|
response_value.should == "foo"
|
|
|
|
end
|
|
|
|
|
2011-07-05 18:56:27 -04:00
|
|
|
it 'closes payload if not nil' do
|
|
|
|
test_file = File.new(File.join( File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))
|
|
|
|
initial_count = tmp_count
|
|
|
|
|
|
|
|
stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
|
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
|
|
|
|
|
|
|
|
tmp_count.should == initial_count
|
|
|
|
end
|
|
|
|
|
2010-05-25 14:05:41 -04:00
|
|
|
end
|
|
|
|
|
2011-07-05 18:56:27 -04:00
|
|
|
def tmp_count
|
|
|
|
Dir.glob(Dir::tmpdir + "/*").size
|
|
|
|
end
|