1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Cleanup timeout option specs

This commit is contained in:
Sandro Turriate 2009-09-12 22:32:56 -04:00
parent 30e393142f
commit 0cbdb7dfbf
2 changed files with 18 additions and 24 deletions

View file

@ -41,12 +41,6 @@ module HTTParty
end
private
# def http
# http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
# http.use_ssl = (uri.port == 443)
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
# http
# end
def http
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
@ -58,7 +52,6 @@ module HTTParty
end
http
end
def body
options[:body].is_a?(Hash) ? options[:body].to_params : options[:body]

View file

@ -46,25 +46,26 @@ describe HTTParty::Request do
@request.send(:setup_raw_request)
@request.instance_variable_get(:@raw_request)['authorization'].should_not be_nil
end
it "should change timeout when configured (if an Integer)" do
@request.send(:http).open_timeout.should be_nil
@request.send(:http).read_timeout.should == 60
invalid_timeout = "invalid"
invalid_timeout.is_a?(Integer).should be_false
@request.options[:timeout] = invalid_timeout
@request.send(:http).open_timeout.should be_nil
@request.send(:http).read_timeout.should == 60
timeout = 30
timeout.is_a?(Integer).should be_true
@request.options[:timeout] = timeout
@request.send(:http).open_timeout.should == timeout
@request.send(:http).read_timeout.should == timeout
context "when setting timeout" do
it "does nothing if the timeout option is a string" do
http = mock("http", :null_object => true)
http.should_not_receive(:open_timeout=)
http.should_not_receive(:read_timeout=)
Net::HTTP.stub(:new => http)
request = HTTParty::Request.new(Net::HTTP::Get, 'https://foobar.com', {:timeout => "five seconds"})
request.send(:http)
end
it "sets the timeout to 5 seconds" do
@request.options[:timeout] = 5
@request.send(:http).open_timeout.should == 5
@request.send(:http).read_timeout.should == 5
end
end
end
describe '#format_from_mimetype' do
it 'should handle text/xml' do
["text/xml", "text/xml; charset=iso8859-1"].each do |ct|