spec/session_spec.rb in patron-0.13.1 vs spec/session_spec.rb in patron-0.13.3
- old
+ new
@@ -14,13 +14,13 @@
context 'when trying a non-HTTP(s) URL' do
forbidden_protos = %w( smb tftp imap smtp telnet dict ftp sftp scp file gopher )
forbidden_protos.each do |forbidden_proto|
it "should deny a #{forbidden_proto.upcase} request" do
- @session.base_url = nil
expect {
- @session.get('%s://localhost' % forbidden_proto)
+ @session.base_url = '%s://localhost' % forbidden_proto
+ @session.get('')
}.to raise_error(Patron::UnsupportedProtocol)
end
end
end
@@ -206,13 +206,13 @@
delta_s = Time.now.to_i - started
expect(delta_s).to be_within(2).of(5)
end
it "is able to terminate the thread that is running a slow request" do
- t = Thread.new do
+ pid = Process.fork do
trap('SIGINT') do
- exit # exit the thread
+ exit # exit the process
end
session = Patron::Session.new
session.timeout = 40
session.base_url = "http://localhost:9001"
session.get("/slow")
@@ -220,12 +220,12 @@
# Our test server starts sending the body only after 20 seconds. We should be able to abort
# using a signal during that time.
started = Time.now.to_i
sleep 5 # Less than what it takes for the server to respond
- Process.kill("INT", Process.pid) # Signal ourselves...
- t.join # wrap up the thread. If Patron is still busy there, this join call will still take 15s.
+ Process.kill("INT", pid) # Signal ourselves...
+ Process.wait(pid) # wrap up the process. If Patron is still busy there, this call will still take 15s.
delta_s = Time.now.to_i - started
expect(delta_s).to be_within(2).of(5)
end
it "receives progress callbacks" do
@@ -456,18 +456,18 @@
end
it "should ignore a wrong Content-Length when asked to" do
expect {
@session.ignore_content_length = true
- @session.get("/wrongcontentlength")
+ @session.get("/wrongcontentlength", { 'Connection' => 'close' })
}.to_not raise_error
end
it "should fail by default with a Content-Length too high" do
expect {
@session.ignore_content_length = nil
- @session.get("/wrongcontentlength")
+ @session.get("/wrongcontentlength", { 'Connection' => 'close' })
}.to raise_error(Patron::PartialFileError)
end
it "should raise exception if cookie store is not writable or readable" do
expect { @session.handle_cookies("/trash/clash/foo") }.to raise_error(ArgumentError)
@@ -515,17 +515,15 @@
end
it "should serialize query params and append them to the url" do
response = @session.request(:get, "/test", {}, :query => {:foo => "bar"})
request = YAML::load(response.body)
- request.parse
expect(request.path + '?' + request.query_string).to be == "/test?foo=bar"
end
it "should merge parameters in the :query option with pre-existing query parameters" do
response = @session.request(:get, "/test?foo=bar", {}, :query => {:baz => "quux"})
request = YAML::load(response.body)
- request.parse
expect(request.path + '?' + request.query_string).to be == "/test?foo=bar&baz=quux"
end
def encode_authz(user, passwd)
"Basic " + Base64.encode64("#{user}:#{passwd}").strip