1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPBadResponse" do
it "is a subclass of StandardError" do
Net::HTTPBadResponse.should < StandardError
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPError" do
it "is a subclass of Net::ProtocolError" do
Net::HTTPError.should < Net::ProtocolError
end
it "includes the Net::HTTPExceptions module" do
Net::HTTPError.should < Net::HTTPExceptions
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPFatalError" do
it "is a subclass of Net::ProtoFatalError" do
Net::HTTPFatalError.should < Net::ProtoFatalError
end
it "includes the Net::HTTPExceptions module" do
Net::HTTPFatalError.should < Net::HTTPExceptions
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPHeaderSyntaxError" do
it "is a subclass of StandardError" do
Net::HTTPHeaderSyntaxError.should < StandardError
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPRetriableError" do
it "is a subclass of Net::ProtoRetriableError" do
Net::HTTPRetriableError.should < Net::ProtoRetriableError
end
it "includes the Net::HTTPExceptions module" do
Net::HTTPRetriableError.should < Net::HTTPExceptions
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPServerException" do
it "is a subclass of Net::ProtoServerError" do
Net::HTTPServerException.should < Net::ProtoServerError
end
it "includes the Net::HTTPExceptions module" do
Net::HTTPServerException.should < Net::HTTPExceptions
end
end

View file

@ -0,0 +1,35 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.Proxy" do
it "returns a new subclass of Net::HTTP" do
Net::HTTP.Proxy("localhost").should < Net::HTTP
end
it "returns Net::HTTP when the passed address is nil" do
Net::HTTP.Proxy(nil).should == Net::HTTP
end
it "sets the returned subclasses' proxy options based on the passed arguments" do
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
http_with_proxy.proxy_address.should == "localhost"
http_with_proxy.proxy_port.should eql(1234)
http_with_proxy.proxy_user.should == "rspec"
http_with_proxy.proxy_pass.should == "rocks"
end
end
describe "Net::HTTP#proxy?" do
describe "when self is no proxy class instance" do
it "returns false" do
Net::HTTP.new("localhost", 3333).proxy?.should be_false
end
end
describe "when self is a proxy class instance" do
it "returns false" do
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
http_with_proxy.new("localhost", 3333).proxy?.should be_true
end
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/started', __FILE__)
describe "Net::HTTP#active?" do
it_behaves_like :net_http_started_p, :active?
end

View file

@ -0,0 +1,9 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#address" do
it "returns the current host name" do
net = Net::HTTP.new("localhost")
net.address.should == "localhost"
end
end

View file

@ -0,0 +1,10 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#close_on_empty_response" do
it "needs to be reviewed for spec completeness"
end
describe "Net::HTTP#close_on_empty_response=" do
it "needs to be reviewed for spec completeness"
end

View file

@ -0,0 +1,21 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#copy" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a COPY request to the passed path and returns the response" do
response = @http.copy("/request")
response.should be_kind_of(Net::HTTPResponse)
response.body.should == "Request type: COPY"
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.default_port" do
it "returns 80" do
Net::HTTP.http_default_port.should eql(80)
end
end

View file

@ -0,0 +1,21 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#delete" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a DELETE request to the passed path and returns the response" do
response = @http.delete("/request")
response.should be_kind_of(Net::HTTPResponse)
response.body.should == "Request type: DELETE"
end
end

View file

@ -0,0 +1,29 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#finish" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
describe "when self has been started" do
it "closes the tcp connection" do
@http.start
@http.finish
@http.started?.should be_false
end
end
describe "when self has not been started yet" do
it "raises an IOError" do
lambda { @http.finish }.should raise_error(IOError)
end
end
end

View file

@ -0,0 +1,93 @@
require 'webrick'
require 'webrick/httpservlet/abstract'
module NetHTTPSpecs
class NullWriter
def <<(s) end
def puts(*args) end
def print(*args) end
def printf(*args) end
end
class SpecServlet < WEBrick::HTTPServlet::AbstractServlet
def handle(req, res)
reply(req, res)
end
%w{ do_GET do_HEAD do_POST do_PUT do_PROPPATCH do_LOCK do_UNLOCK
do_OPTIONS do_PROPFIND do_DELETE do_MOVE do_COPY
do_MKCOL do_TRACE }.each do |method|
alias_method method.to_sym, :handle
end
end
class RequestServlet < SpecServlet
def reply(req, res)
res.content_type = "text/plain"
res.body = "Request type: #{req.request_method}"
end
end
class RequestBodyServlet < SpecServlet
def reply(req, res)
res.content_type = "text/plain"
res.body = req.body
end
end
class RequestHeaderServlet < SpecServlet
def reply(req, res)
res.content_type = "text/plain"
res.body = req.header.inspect
end
end
class << self
@server = nil
@server_thread = nil
def port
raise "server not started" unless @server
@server.config[:Port]
end
def start_server
server_config = {
BindAddress: "localhost",
Port: 0,
Logger: WEBrick::Log.new(NullWriter.new),
AccessLog: [],
ServerType: Thread
}
@server = WEBrick::HTTPServer.new(server_config)
@server.mount_proc('/') do |req, res|
res.content_type = "text/plain"
res.body = "This is the index page."
end
@server.mount('/request', RequestServlet)
@server.mount("/request/body", RequestBodyServlet)
@server.mount("/request/header", RequestHeaderServlet)
@server_thread = @server.start
end
def stop_server
if @server
begin
@server.shutdown
rescue Errno::EPIPE
# Because WEBrick is not thread-safe and only catches IOError
end
@server = nil
end
if @server_thread
@server_thread.join
@server_thread = nil
end
timeout = WEBrick::Utils::TimeoutHandler
timeout.terminate if timeout.respond_to?(:terminate)
end
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_get', __FILE__)
describe "Net::HTTP#get2" do
it_behaves_like :net_ftp_request_get, :get2
end

View file

@ -0,0 +1,30 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP.get_print" do
before :each do
NetHTTPSpecs.start_server
@port = NetHTTPSpecs.port
end
after :each do
NetHTTPSpecs.stop_server
end
describe "when passed URI" do
it "it prints the body of the specified uri to $stdout" do
lambda do
Net::HTTP.get_print URI.parse("http://localhost:#{@port}/")
end.should output(/This is the index page\./)
end
end
describe "when passed host, path, port" do
it "it prints the body of the specified uri to $stdout" do
lambda do
Net::HTTP.get_print 'localhost', "/", @port
end.should output(/This is the index page\./)
end
end
end

View file

@ -0,0 +1,30 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP.get_response" do
before :each do
NetHTTPSpecs.start_server
@port = NetHTTPSpecs.port
end
after :each do
NetHTTPSpecs.stop_server
end
describe "when passed URI" do
it "returns the response for the specified uri" do
res = Net::HTTP.get_response(URI.parse("http://localhost:#{@port}/"))
res.content_type.should == "text/plain"
res.body.should == "This is the index page."
end
end
describe "when passed host, path, port" do
it "returns the response for the specified host-path-combination" do
res = Net::HTTP.get_response('localhost', "/", @port)
res.content_type.should == "text/plain"
res.body.should == "This is the index page."
end
end
end

View file

@ -0,0 +1,26 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP.get when passed URI" do
before :each do
NetHTTPSpecs.start_server
@port = NetHTTPSpecs.port
end
after :each do
NetHTTPSpecs.stop_server
end
describe "when passed URI" do
it "returns the body of the specified uri" do
Net::HTTP.get(URI.parse("http://localhost:#{@port}/")).should == "This is the index page."
end
end
describe "when passed host, path, port" do
it "returns the body of the specified host-path-combination" do
Net::HTTP.get('localhost', "/", @port).should == "This is the index page."
end
end
end

View file

@ -0,0 +1,9 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_head', __FILE__)
describe "Net::HTTP#head2" do
it_behaves_like :net_ftp_request_head, :head2
end

View file

@ -0,0 +1,25 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#head" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a HEAD request to the passed path and returns the response" do
response = @http.head("/request")
# HEAD requests have no responses
response.body.should be_nil
end
it "returns a Net::HTTPResponse" do
@http.head("/request").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.http_default_port" do
it "returns 80" do
Net::HTTP.http_default_port.should eql(80)
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.https_default_port" do
it "returns 443" do
Net::HTTP.https_default_port.should eql(443)
end
end

View file

@ -0,0 +1,46 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#initialize" do
it "is private" do
Net::HTTP.should have_private_instance_method(:initialize)
end
describe "when passed address" do
before :each do
@net = Net::HTTP.allocate
@net.send(:initialize, "localhost")
end
it "sets the new Net::HTTP instance's address to the passed address" do
@net.address.should == "localhost"
end
it "sets the new Net::HTTP instance's port to the default HTTP port" do
@net.port.should eql(Net::HTTP.default_port)
end
it "does not start the new Net::HTTP instance" do
@net.started?.should be_false
end
end
describe "when passed address, port" do
before :each do
@net = Net::HTTP.allocate
@net.send(:initialize, "localhost", 3333)
end
it "sets the new Net::HTTP instance's address to the passed address" do
@net.address.should == "localhost"
end
it "sets the new Net::HTTP instance's port to the passed port" do
@net.port.should eql(3333)
end
it "does not start the new Net::HTTP instance" do
@net.started?.should be_false
end
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#inspect" do
before :each do
NetHTTPSpecs.start_server
@port = NetHTTPSpecs.port
@http = Net::HTTP.new("localhost", @port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "returns a String representation of self" do
@http.inspect.should be_kind_of(String)
@http.inspect.should == "#<Net::HTTP localhost:#{@port} open=false>"
@http.start
@http.inspect.should == "#<Net::HTTP localhost:#{@port} open=true>"
end
end

View file

@ -0,0 +1,7 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../shared/version_1_1', __FILE__)
describe "Net::HTTP.is_version_1_1?" do
it_behaves_like :net_http_version_1_1_p, :is_version_1_1?
end

View file

@ -0,0 +1,7 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../shared/version_1_2', __FILE__)
describe "Net::HTTP.is_version_1_2?" do
it_behaves_like :net_http_version_1_2_p, :is_version_1_2?
end

View file

@ -0,0 +1,21 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#lock" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a LOCK request to the passed path and returns the response" do
response = @http.lock("/request", "test=test")
response.should be_kind_of(Net::HTTPResponse)
response.body.should == "Request type: LOCK"
end
end

View file

@ -0,0 +1,21 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#mkcol" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a MKCOL request to the passed path and returns the response" do
response = @http.mkcol("/request")
response.should be_kind_of(Net::HTTPResponse)
response.body.should == "Request type: MKCOL"
end
end

View file

@ -0,0 +1,25 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#head" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a MOVE request to the passed path and returns the response" do
response = @http.move("/request")
# HEAD requests have no responses
response.body.should == "Request type: MOVE"
end
it "returns a Net::HTTPResponse" do
@http.move("/request").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,86 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.new" do
describe "when passed address" do
before :each do
@http = Net::HTTP.new("localhost")
end
it "returns a Net::HTTP instance" do
@http.proxy?.should be_false
@http.instance_of?(Net::HTTP).should be_true
end
it "sets the new Net::HTTP instance's address to the passed address" do
@http.address.should == "localhost"
end
it "sets the new Net::HTTP instance's port to the default HTTP port" do
@http.port.should eql(Net::HTTP.default_port)
end
it "does not start the new Net::HTTP instance" do
@http.started?.should be_false
end
end
describe "when passed address, port" do
before :each do
@http = Net::HTTP.new("localhost", 3333)
end
it "returns a Net::HTTP instance" do
@http.proxy?.should be_false
@http.instance_of?(Net::HTTP).should be_true
end
it "sets the new Net::HTTP instance's address to the passed address" do
@http.address.should == "localhost"
end
it "sets the new Net::HTTP instance's port to the passed port" do
@http.port.should eql(3333)
end
it "does not start the new Net::HTTP instance" do
@http.started?.should be_false
end
end
describe "when passed address, port, *proxy_options" do
it "returns a Net::HTTP instance" do
http = Net::HTTP.new("localhost", 3333, "localhost")
http.proxy?.should be_true
http.instance_of?(Net::HTTP).should be_true
http.should be_kind_of(Net::HTTP)
end
it "correctly sets the passed Proxy options" do
http = Net::HTTP.new("localhost", 3333, "localhost")
http.proxy_address.should == "localhost"
http.proxy_port.should eql(80)
http.proxy_user.should be_nil
http.proxy_pass.should be_nil
http = Net::HTTP.new("localhost", 3333, "localhost", 1234)
http.proxy_address.should == "localhost"
http.proxy_port.should eql(1234)
http.proxy_user.should be_nil
http.proxy_pass.should be_nil
http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec")
http.proxy_address.should == "localhost"
http.proxy_port.should eql(1234)
http.proxy_user.should == "rubyspec"
http.proxy_pass.should be_nil
http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec", "rocks")
http.proxy_address.should == "localhost"
http.proxy_port.should eql(1234)
http.proxy_user.should == "rubyspec"
http.proxy_pass.should == "rocks"
end
end
end

View file

@ -0,0 +1,48 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.newobj" do
before :each do
@net = Net::HTTP.newobj("localhost")
end
describe "when passed address" do
it "returns a new Net::HTTP instance" do
@net.should be_kind_of(Net::HTTP)
end
it "sets the new Net::HTTP instance's address to the passed address" do
@net.address.should == "localhost"
end
it "sets the new Net::HTTP instance's port to the default HTTP port" do
@net.port.should eql(Net::HTTP.default_port)
end
it "does not start the new Net::HTTP instance" do
@net.started?.should be_false
end
end
describe "when passed address, port" do
before :each do
@net = Net::HTTP.newobj("localhost", 3333)
end
it "returns a new Net::HTTP instance" do
@net.should be_kind_of(Net::HTTP)
end
it "sets the new Net::HTTP instance's address to the passed address" do
@net.address.should == "localhost"
end
it "sets the new Net::HTTP instance's port to the passed port" do
@net.port.should eql(3333)
end
it "does not start the new Net::HTTP instance" do
@net.started?.should be_false
end
end
end

View file

@ -0,0 +1,35 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#open_timeout" do
ruby_version_is ""..."2.3" do
it "returns the seconds to wait till the connection is open" do
net = Net::HTTP.new("localhost")
net.open_timeout.should be_nil
net.open_timeout = 10
net.open_timeout.should eql(10)
end
end
ruby_version_is "2.3" do
it "returns the seconds to wait till the connection is open" do
net = Net::HTTP.new("localhost")
net.open_timeout.should eql(60)
net.open_timeout = 10
net.open_timeout.should eql(10)
end
end
end
describe "Net::HTTP#open_timeout=" do
it "sets the seconds to wait till the connection is open" do
net = Net::HTTP.new("localhost")
net.open_timeout = 10
net.open_timeout.should eql(10)
end
it "returns the newly set value" do
net = Net::HTTP.new("localhost")
(net.open_timeout = 10).should eql(10)
end
end

View file

@ -0,0 +1,25 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#options" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends an options request to the passed path and returns the response" do
response = @http.options("/request")
response.body.should == "Request type: OPTIONS"
end
it "returns a Net::HTTPResponse" do
@http.options("/request").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,9 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#port" do
it "returns the current port number" do
net = Net::HTTP.new("localhost", 3333)
net.port.should eql(3333)
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_post', __FILE__)
describe "Net::HTTP#post2" do
it_behaves_like :net_ftp_request_post, :post2
end

View file

@ -0,0 +1,22 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP.post_form when passed URI" do
before :each do
NetHTTPSpecs.start_server
@port = NetHTTPSpecs.port
end
after :each do
NetHTTPSpecs.stop_server
end
it "POSTs the passed form data to the given uri" do
uri = URI.parse("http://localhost:#{@port}/request/body")
data = { test: :data }
res = Net::HTTP.post_form(uri, data)
res.body.should == "test=data"
end
end

View file

@ -0,0 +1,38 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#post" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends an post request to the passed path and returns the response" do
response = @http.post("/request", "test=test")
response.body.should == "Request type: POST"
end
it "returns a Net::HTTPResponse" do
@http.post("/request", "test=test").should be_kind_of(Net::HTTPResponse)
end
describe "when passed a block" do
it "yields fragments of the response body to the passed block" do
str = ""
@http.post("/request", "test=test") do |res|
str << res
end
str.should == "Request type: POST"
end
it "returns a Net::HTTPResponse" do
@http.post("/request", "test=test") {}.should be_kind_of(Net::HTTPResponse)
end
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#propfind" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends an propfind request to the passed path and returns the response" do
response = @http.propfind("/request", "test=test")
response.body.should == "Request type: PROPFIND"
end
it "returns a Net::HTTPResponse" do
@http.propfind("/request", "test=test").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#proppatch" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends an proppatch request to the passed path and returns the response" do
response = @http.proppatch("/request", "test=test")
response.body.should == "Request type: PROPPATCH"
end
it "returns a Net::HTTPResponse" do
@http.proppatch("/request", "test=test").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,31 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.proxy_address" do
describe "when self is no proxy class" do
it "returns nil" do
Net::HTTP.proxy_address.should be_nil
end
end
describe "when self is a proxy class" do
it "returns the address for self's proxy connection" do
Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_address.should == "localhost"
end
end
end
describe "Net::HTTP#proxy_address" do
describe "when self is no proxy class instance" do
it "returns nil" do
Net::HTTP.new("localhost", 3333).proxy_address.should be_nil
end
end
describe "when self is a proxy class instance" do
it "returns the password for self's proxy connection" do
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
http_with_proxy.new("localhost", 3333).proxy_address.should == "localhost"
end
end
end

View file

@ -0,0 +1,9 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.proxy_class?" do
it "returns true if sels is a class created with Net::HTTP.Proxy" do
Net::HTTP.proxy_class?.should be_false
Net::HTTP.Proxy("localhost").proxy_class?.should be_true
end
end

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.proxy_pass" do
describe "when self is no proxy class" do
it "returns nil" do
Net::HTTP.proxy_pass.should be_nil
end
end
describe "when self is a proxy class" do
it "returns nil if no password was set for self's proxy connection" do
Net::HTTP.Proxy("localhost").proxy_pass.should be_nil
end
it "returns the password for self's proxy connection" do
Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_pass.should == "rocks"
end
end
end
describe "Net::HTTP#proxy_pass" do
describe "when self is no proxy class instance" do
it "returns nil" do
Net::HTTP.new("localhost", 3333).proxy_pass.should be_nil
end
end
describe "when self is a proxy class instance" do
it "returns nil if no password was set for self's proxy connection" do
Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_pass.should be_nil
end
it "returns the password for self's proxy connection" do
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
http_with_proxy.new("localhost", 3333).proxy_pass.should == "rocks"
end
end
end

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.proxy_port" do
describe "when self is no proxy class" do
it "returns nil" do
Net::HTTP.proxy_port.should be_nil
end
end
describe "when self is a proxy class" do
it "returns 80 if no port was set for self's proxy connection" do
Net::HTTP.Proxy("localhost").proxy_port.should eql(80)
end
it "returns the port for self's proxy connection" do
Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_port.should eql(1234)
end
end
end
describe "Net::HTTP#proxy_port" do
describe "when self is no proxy class instance" do
it "returns nil" do
Net::HTTP.new("localhost", 3333).proxy_port.should be_nil
end
end
describe "when self is a proxy class instance" do
it "returns 80 if no port was set for self's proxy connection" do
Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_port.should eql(80)
end
it "returns the port for self's proxy connection" do
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
http_with_proxy.new("localhost", 3333).proxy_port.should eql(1234)
end
end
end

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.proxy_user" do
describe "when self is no proxy class" do
it "returns nil" do
Net::HTTP.proxy_user.should be_nil
end
end
describe "when self is a proxy class" do
it "returns nil if no username was set for self's proxy connection" do
Net::HTTP.Proxy("localhost").proxy_user.should be_nil
end
it "returns the username for self's proxy connection" do
Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_user.should == "rspec"
end
end
end
describe "Net::HTTP#proxy_user" do
describe "when self is no proxy class instance" do
it "returns nil" do
Net::HTTP.new("localhost", 3333).proxy_user.should be_nil
end
end
describe "when self is a proxy class instance" do
it "returns nil if no username was set for self's proxy connection" do
Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_user.should be_nil
end
it "returns the username for self's proxy connection" do
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
http_with_proxy.new("localhost", 3333).proxy_user.should == "rspec"
end
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_put', __FILE__)
describe "Net::HTTP#put2" do
it_behaves_like :net_ftp_request_put, :put2
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#put" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends an put request to the passed path and returns the response" do
response = @http.put("/request", "test=test")
response.body.should == "Request type: PUT"
end
it "returns a Net::HTTPResponse" do
@http.put("/request", "test=test").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#read_timeout" do
it "returns the seconds to wait until reading one block" do
net = Net::HTTP.new("localhost")
net.read_timeout.should eql(60)
net.read_timeout = 10
net.read_timeout.should eql(10)
end
end
describe "Net::HTTP#read_timeout=" do
it "sets the seconds to wait till the connection is open" do
net = Net::HTTP.new("localhost")
net.read_timeout = 10
net.read_timeout.should eql(10)
end
it "returns the newly set value" do
net = Net::HTTP.new("localhost")
(net.read_timeout = 10).should eql(10)
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_get', __FILE__)
describe "Net::HTTP#request_get" do
it_behaves_like :net_ftp_request_get, :get2
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_head', __FILE__)
describe "Net::HTTP#request_head" do
it_behaves_like :net_ftp_request_head, :request_head
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_post', __FILE__)
describe "Net::HTTP#request_post" do
it_behaves_like :net_ftp_request_post, :request_post
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/request_put', __FILE__)
describe "Net::HTTP#request_put" do
it_behaves_like :net_ftp_request_put, :request_put
end

View file

@ -0,0 +1,109 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#request" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
describe "when passed request_object" do
it "makes a HTTP Request based on the passed request_object" do
response = @http.request(Net::HTTP::Get.new("/request"), "test=test")
response.body.should == "Request type: GET"
response = @http.request(Net::HTTP::Head.new("/request"), "test=test")
response.body.should be_nil
response = @http.request(Net::HTTP::Post.new("/request"), "test=test")
response.body.should == "Request type: POST"
response = @http.request(Net::HTTP::Put.new("/request"), "test=test")
response.body.should == "Request type: PUT"
response = @http.request(Net::HTTP::Proppatch.new("/request"), "test=test")
response.body.should == "Request type: PROPPATCH"
response = @http.request(Net::HTTP::Lock.new("/request"), "test=test")
response.body.should == "Request type: LOCK"
response = @http.request(Net::HTTP::Unlock.new("/request"), "test=test")
response.body.should == "Request type: UNLOCK"
# TODO: Does not work?
#response = @http.request(Net::HTTP::Options.new("/request"), "test=test")
#response.body.should be_nil
response = @http.request(Net::HTTP::Propfind.new("/request"), "test=test")
response.body.should == "Request type: PROPFIND"
response = @http.request(Net::HTTP::Delete.new("/request"), "test=test")
response.body.should == "Request type: DELETE"
response = @http.request(Net::HTTP::Move.new("/request"), "test=test")
response.body.should == "Request type: MOVE"
response = @http.request(Net::HTTP::Copy.new("/request"), "test=test")
response.body.should == "Request type: COPY"
response = @http.request(Net::HTTP::Mkcol.new("/request"), "test=test")
response.body.should == "Request type: MKCOL"
response = @http.request(Net::HTTP::Trace.new("/request"), "test=test")
response.body.should == "Request type: TRACE"
end
end
describe "when passed request_object and request_body" do
it "sends the passed request_body when making the HTTP Request" do
response = @http.request(Net::HTTP::Get.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Head.new("/request/body"), "test=test")
response.body.should be_nil
response = @http.request(Net::HTTP::Post.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Put.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Proppatch.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Lock.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Unlock.new("/request/body"), "test=test")
response.body.should == "test=test"
# TODO: Does not work?
#response = @http.request(Net::HTTP::Options.new("/request/body"), "test=test")
#response.body.should be_nil
response = @http.request(Net::HTTP::Propfind.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Delete.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Move.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Copy.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Mkcol.new("/request/body"), "test=test")
response.body.should == "test=test"
response = @http.request(Net::HTTP::Trace.new("/request/body"), "test=test")
response.body.should == "test=test"
end
end
end

View file

@ -0,0 +1,254 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP::Get" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Get.should < Net::HTTPRequest
end
it "represents the 'GET'-Request-Method" do
Net::HTTP::Get::METHOD.should == "GET"
end
it "has no Request Body" do
Net::HTTP::Get::REQUEST_HAS_BODY.should be_false
end
it "has a Respone Body" do
Net::HTTP::Get::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Head" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Head.should < Net::HTTPRequest
end
it "represents the 'HEAD'-Request-Method" do
Net::HTTP::Head::METHOD.should == "HEAD"
end
it "has no Request Body" do
Net::HTTP::Head::REQUEST_HAS_BODY.should be_false
end
it "has no Respone Body" do
Net::HTTP::Head::RESPONSE_HAS_BODY.should be_false
end
end
describe "Net::HTTP::Post" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Post.should < Net::HTTPRequest
end
it "represents the 'POST'-Request-Method" do
Net::HTTP::Post::METHOD.should == "POST"
end
it "has a Request Body" do
Net::HTTP::Post::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Post::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Put" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Put.should < Net::HTTPRequest
end
it "represents the 'PUT'-Request-Method" do
Net::HTTP::Put::METHOD.should == "PUT"
end
it "has a Request Body" do
Net::HTTP::Put::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Put::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Delete" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Delete.should < Net::HTTPRequest
end
it "represents the 'DELETE'-Request-Method" do
Net::HTTP::Delete::METHOD.should == "DELETE"
end
it "has no Request Body" do
Net::HTTP::Delete::REQUEST_HAS_BODY.should be_false
end
it "has a Respone Body" do
Net::HTTP::Delete::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Options" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Options.should < Net::HTTPRequest
end
it "represents the 'OPTIONS'-Request-Method" do
Net::HTTP::Options::METHOD.should == "OPTIONS"
end
it "has no Request Body" do
Net::HTTP::Options::REQUEST_HAS_BODY.should be_false
end
it "has no Respone Body" do
Net::HTTP::Options::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Trace" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Trace.should < Net::HTTPRequest
end
it "represents the 'TRACE'-Request-Method" do
Net::HTTP::Trace::METHOD.should == "TRACE"
end
it "has no Request Body" do
Net::HTTP::Trace::REQUEST_HAS_BODY.should be_false
end
it "has a Respone Body" do
Net::HTTP::Trace::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Propfind" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Propfind.should < Net::HTTPRequest
end
it "represents the 'PROPFIND'-Request-Method" do
Net::HTTP::Propfind::METHOD.should == "PROPFIND"
end
it "has a Request Body" do
Net::HTTP::Propfind::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Propfind::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Proppatch" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Proppatch.should < Net::HTTPRequest
end
it "represents the 'PROPPATCH'-Request-Method" do
Net::HTTP::Proppatch::METHOD.should == "PROPPATCH"
end
it "has a Request Body" do
Net::HTTP::Proppatch::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Proppatch::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Mkcol" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Mkcol.should < Net::HTTPRequest
end
it "represents the 'MKCOL'-Request-Method" do
Net::HTTP::Mkcol::METHOD.should == "MKCOL"
end
it "has a Request Body" do
Net::HTTP::Mkcol::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Mkcol::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Copy" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Copy.should < Net::HTTPRequest
end
it "represents the 'COPY'-Request-Method" do
Net::HTTP::Copy::METHOD.should == "COPY"
end
it "has no Request Body" do
Net::HTTP::Copy::REQUEST_HAS_BODY.should be_false
end
it "has a Respone Body" do
Net::HTTP::Copy::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Move" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Move.should < Net::HTTPRequest
end
it "represents the 'MOVE'-Request-Method" do
Net::HTTP::Move::METHOD.should == "MOVE"
end
it "has no Request Body" do
Net::HTTP::Move::REQUEST_HAS_BODY.should be_false
end
it "has a Respone Body" do
Net::HTTP::Move::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Lock" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Lock.should < Net::HTTPRequest
end
it "represents the 'LOCK'-Request-Method" do
Net::HTTP::Lock::METHOD.should == "LOCK"
end
it "has a Request Body" do
Net::HTTP::Lock::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Lock::RESPONSE_HAS_BODY.should be_true
end
end
describe "Net::HTTP::Unlock" do
it "is a subclass of Net::HTTPRequest" do
Net::HTTP::Unlock.should < Net::HTTPRequest
end
it "represents the 'UNLOCK'-Request-Method" do
Net::HTTP::Unlock::METHOD.should == "UNLOCK"
end
it "has a Request Body" do
Net::HTTP::Unlock::REQUEST_HAS_BODY.should be_true
end
it "has a Respone Body" do
Net::HTTP::Unlock::RESPONSE_HAS_BODY.should be_true
end
end

View file

@ -0,0 +1,61 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#send_request" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
# HEAD is special so handled separately
@methods = %w[
GET POST PUT DELETE
OPTIONS
PROPFIND PROPPATCH LOCK UNLOCK
]
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
# TODO: Does only work with GET and POST requests
describe "when passed type, path" do
it "sends a HTTP Request of the passed type to the passed path" do
response = @http.send_request("HEAD", "/request")
response.body.should be_nil
@methods.each do |method|
response = @http.send_request(method, "/request")
response.body.should == "Request type: #{method}"
end
end
end
describe "when passed type, path, body" do
it "sends a HTTP Request with the passed body" do
response = @http.send_request("HEAD", "/request/body", "test=test")
response.body.should be_nil
@methods.each do |method|
response = @http.send_request(method, "/request/body", "test=test")
response.body.should == "test=test"
end
end
end
describe "when passed type, path, body, headers" do
it "sends a HTTP Request with the passed headers" do
referer = 'https://www.ruby-lang.org/'.freeze
response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => referer)
response.body.should be_nil
@methods.each do |method|
response = @http.send_request(method, "/request/header", "test=test", "referer" => referer)
response.body.should include('"referer"=>["' + referer + '"]')
end
end
end
end

View file

@ -0,0 +1,33 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require "stringio"
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#set_debug_output when passed io" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sets the passed io as output stream for debugging" do
io = StringIO.new
@http.set_debug_output(io)
@http.start
io.string.should_not be_empty
size = io.string.size
@http.get("/")
io.string.size.should > size
end
it "outputs a warning when the connection has already been started" do
@http.start
lambda { @http.set_debug_output(StringIO.new) }.should complain("Net::HTTP#set_debug_output called after HTTP started\n")
end
end

View file

@ -0,0 +1,41 @@
describe :net_ftp_request_get, shared: true do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
describe "when passed no block" do
it "sends a GET request to the passed path and returns the response" do
response = @http.send(@method, "/request")
response.body.should == "Request type: GET"
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request")
response.should be_kind_of(Net::HTTPResponse)
end
end
describe "when passed a block" do
it "sends a GET request to the passed path and returns the response" do
response = @http.send(@method, "/request") {}
response.body.should == "Request type: GET"
end
it "yields the response to the passed block" do
@http.send(@method, "/request") do |response|
response.body.should == "Request type: GET"
end
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request") {}
response.should be_kind_of(Net::HTTPResponse)
end
end
end

View file

@ -0,0 +1,41 @@
describe :net_ftp_request_head, shared: true do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
describe "when passed no block" do
it "sends a head request to the passed path and returns the response" do
response = @http.send(@method, "/request")
response.body.should be_nil
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request")
response.should be_kind_of(Net::HTTPResponse)
end
end
describe "when passed a block" do
it "sends a head request to the passed path and returns the response" do
response = @http.send(@method, "/request") {}
response.body.should be_nil
end
it "yields the response to the passed block" do
@http.send(@method, "/request") do |response|
response.body.should be_nil
end
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request") {}
response.should be_kind_of(Net::HTTPResponse)
end
end
end

View file

@ -0,0 +1,41 @@
describe :net_ftp_request_post, shared: true do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
describe "when passed no block" do
it "sends a post request to the passed path and returns the response" do
response = @http.send(@method, "/request", "test=test")
response.body.should == "Request type: POST"
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request", "test=test")
response.should be_kind_of(Net::HTTPResponse)
end
end
describe "when passed a block" do
it "sends a post request to the passed path and returns the response" do
response = @http.send(@method, "/request", "test=test") {}
response.body.should == "Request type: POST"
end
it "yields the response to the passed block" do
@http.send(@method, "/request", "test=test") do |response|
response.body.should == "Request type: POST"
end
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request", "test=test") {}
response.should be_kind_of(Net::HTTPResponse)
end
end
end

View file

@ -0,0 +1,41 @@
describe :net_ftp_request_put, shared: true do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
describe "when passed no block" do
it "sends a put request to the passed path and returns the response" do
response = @http.send(@method, "/request", "test=test")
response.body.should == "Request type: PUT"
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request", "test=test")
response.should be_kind_of(Net::HTTPResponse)
end
end
describe "when passed a block" do
it "sends a put request to the passed path and returns the response" do
response = @http.send(@method, "/request", "test=test") {}
response.body.should == "Request type: PUT"
end
it "yields the response to the passed block" do
@http.send(@method, "/request", "test=test") do |response|
response.body.should == "Request type: PUT"
end
end
it "returns a Net::HTTPResponse object" do
response = @http.send(@method, "/request", "test=test") {}
response.should be_kind_of(Net::HTTPResponse)
end
end
end

View file

@ -0,0 +1,26 @@
describe :net_http_started_p, shared: true do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "returns true when self has been started" do
@http.start
@http.send(@method).should be_true
end
it "returns false when self has not been started yet" do
@http.send(@method).should be_false
end
it "returns false when self has been stopped again" do
@http.start
@http.finish
@http.send(@method).should be_false
end
end

View file

@ -0,0 +1,6 @@
describe :net_http_version_1_1_p, shared: true do
it "returns the state of net/http 1.1 features" do
Net::HTTP.version_1_2
Net::HTTP.send(@method).should be_false
end
end

View file

@ -0,0 +1,6 @@
describe :net_http_version_1_2_p, shared: true do
it "returns the state of net/http 1.2 features" do
Net::HTTP.version_1_2
Net::HTTP.send(@method).should be_true
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP.socket_type" do
it "returns BufferedIO" do
Net::HTTP.socket_type.should == Net::BufferedIO
end
end

View file

@ -0,0 +1,111 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP.start" do
before :each do
NetHTTPSpecs.start_server
@port = NetHTTPSpecs.port
end
after :each do
NetHTTPSpecs.stop_server
end
describe "when not passed a block" do
before :each do
@http = Net::HTTP.start("localhost", @port)
end
after :each do
@http.finish if @http.started?
end
it "returns a new Net::HTTP object for the passed address and port" do
@http.should be_kind_of(Net::HTTP)
@http.address.should == "localhost"
@http.port.should == @port
end
it "opens the tcp connection" do
@http.started?.should be_true
end
end
describe "when passed a block" do
it "returns the blocks return value" do
Net::HTTP.start("localhost", @port) { :test }.should == :test
end
it "yields the new Net::HTTP object to the block" do
yielded = false
Net::HTTP.start("localhost", @port) do |net|
yielded = true
net.should be_kind_of(Net::HTTP)
end
yielded.should be_true
end
it "opens the tcp connection before yielding" do
Net::HTTP.start("localhost", @port) { |http| http.started?.should be_true }
end
it "closes the tcp connection after yielding" do
net = nil
Net::HTTP.start("localhost", @port) { |x| net = x }
net.started?.should be_false
end
end
end
describe "Net::HTTP#start" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "returns self" do
@http.start.should equal(@http)
end
it "opens the tcp connection" do
@http.start
@http.started?.should be_true
end
describe "when self has already been started" do
it "raises an IOError" do
@http.start
lambda { @http.start }.should raise_error(IOError)
end
end
describe "when passed a block" do
it "returns the blocks return value" do
@http.start { :test }.should == :test
end
it "yields the new Net::HTTP object to the block" do
yielded = false
@http.start do |http|
yielded = true
http.should equal(@http)
end
yielded.should be_true
end
it "opens the tcp connection before yielding" do
@http.start { |http| http.started?.should be_true }
end
it "closes the tcp connection after yielding" do
@http.start { }
@http.started?.should be_false
end
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
require File.expand_path('../shared/started', __FILE__)
describe "Net::HTTP#started?" do
it_behaves_like :net_http_started_p, :started?
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#trace" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends a TRACE request to the passed path and returns the response" do
response = @http.trace("/request")
response.body.should == "Request type: TRACE"
end
it "returns a Net::HTTPResponse" do
@http.trace("/request").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,24 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/http_server', __FILE__)
describe "Net::HTTP#unlock" do
before :each do
NetHTTPSpecs.start_server
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
end
after :each do
@http.finish if @http.started?
NetHTTPSpecs.stop_server
end
it "sends an UNLOCK request to the passed path and returns the response" do
response = @http.unlock("/request", "test=test")
response.body.should == "Request type: UNLOCK"
end
it "returns a Net::HTTPResponse" do
@http.unlock("/request", "test=test").should be_kind_of(Net::HTTPResponse)
end
end

View file

@ -0,0 +1,9 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTP#use_ssl?" do
it "returns false" do
http = Net::HTTP.new("localhost")
http.use_ssl?.should be_false
end
end

View file

@ -0,0 +1,7 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../shared/version_1_1', __FILE__)
describe "Net::HTTP.version_1_1?" do
it_behaves_like :net_http_version_1_1_p, :version_1_1?
end

View file

@ -0,0 +1,20 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../shared/version_1_2', __FILE__)
describe "Net::HTTP.version_1_2" do
it "turns on net/http 1.2 features" do
Net::HTTP.version_1_2
Net::HTTP.version_1_2?.should be_true
Net::HTTP.version_1_1?.should be_false
end
it "returns true" do
Net::HTTP.version_1_2.should be_true
end
end
describe "Net::HTTP.version_1_2?" do
it_behaves_like :net_http_version_1_2_p, :version_1_2?
end

View file

@ -0,0 +1,5 @@
module NetHTTPExceptionsSpecs
class Simple < StandardError
include Net::HTTPExceptions
end
end

View file

@ -0,0 +1,17 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPExceptions#initialize when passed message, response" do
before :each do
@exception = NetHTTPExceptionsSpecs::Simple.new("error message", "a http response")
end
it "calls super with the passed message" do
@exception.message.should == "error message"
end
it "sets self's response to the passed response" do
@exception.response.should == "a http response"
end
end

View file

@ -0,0 +1,10 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPExceptions#response" do
it "returns self's response" do
exception = NetHTTPExceptionsSpecs::Simple.new("error message", "a http response")
exception.response.should == "a http response"
end
end

View file

@ -0,0 +1,22 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#body_exist?" do
it "returns true when the response is expected to have a body" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.body_exist?.should be_true
request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
request.body_exist?.should be_false
end
describe "when $VERBOSE is true" do
it "emits a warning" do
request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
lambda {
$VERBOSE = true
request.body_exist?
}.should complain(/body_exist\? is obsolete/)
end
end
end

View file

@ -0,0 +1,30 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require "stringio"
describe "Net::HTTPGenericRequest#body" do
it "returns self's request body" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.body.should be_nil
request.body = "Some Content"
request.body.should == "Some Content"
end
end
describe "Net::HTTPGenericRequest#body=" do
before :each do
@request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
end
it "sets self's body content to the passed String" do
@request.body = "Some Content"
@request.body.should == "Some Content"
end
it "sets self's body stream to nil" do
@request.body_stream = StringIO.new("")
@request.body = "Some Content"
@request.body_stream.should be_nil
end
end

View file

@ -0,0 +1,32 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require "stringio"
describe "Net::HTTPGenericRequest#body_stream" do
it "returns self's body stream Object" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.body_stream.should be_nil
stream = StringIO.new("test")
request.body_stream = stream
request.body_stream.should equal(stream)
end
end
describe "Net::HTTPGenericRequest#body_stream=" do
before :each do
@request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
@stream = StringIO.new("test")
end
it "sets self's body stream to the passed Object" do
@request.body_stream = @stream
@request.body_stream.should equal(@stream)
end
it "sets self's body to nil" do
@request.body = "Some Content"
@request.body_stream = @stream
@request.body.should be_nil
end
end

View file

@ -0,0 +1,131 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require "stringio"
describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do
before :each do
@socket = StringIO.new("")
@buffered_socket = Net::BufferedIO.new(@socket)
end
it "executes the request over the socket to the path using the HTTP version" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.exec(@buffered_socket, "1.1", "/some/path")
str = @socket.string
str.should =~ %r[POST /some/path HTTP/1.1\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str[-4..-1].should == "\r\n\r\n"
request = Net::HTTPGenericRequest.new("GET", true, true, "/some/path",
"Content-Type" => "text/html")
request.exec(@buffered_socket, "1.0", "/some/other/path")
str = @socket.string
str.should =~ %r[GET /some/other/path HTTP/1.0\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str.should =~ %r[Content-Type: text/html\r\n]
str[-4..-1].should == "\r\n\r\n"
end
describe "when a request body is set" do
it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.body = "Some Content"
request.exec(@buffered_socket, "1.1", "/some/other/path")
str = @socket.string
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
str.should =~ %r[Content-Length: 12\r\n]
str[-16..-1].should == "\r\n\r\nSome Content"
end
it "correctly sets the 'Content-Length' header and includes the body" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
"Content-Type" => "text/html")
request.body = "Some Content"
request.exec(@buffered_socket, "1.1", "/some/other/path")
str = @socket.string
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str.should =~ %r[Content-Type: text/html\r\n]
str.should =~ %r[Content-Length: 12\r\n]
str[-16..-1].should == "\r\n\r\nSome Content"
end
end
describe "when a body stream is set" do
it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
"Content-Length" => "10")
request.body_stream = StringIO.new("a" * 20)
request.exec(@buffered_socket, "1.1", "/some/other/path")
str = @socket.string
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
str.should =~ %r[Content-Length: 10\r\n]
str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
end
it "sends the whole stream, regardless of the 'Content-Length' header" do
request = Net::HTTPGenericRequest.new("POST", true, true,"/some/path",
"Content-Type" => "text/html",
"Content-Length" => "10")
request.body_stream = StringIO.new("a" * 20)
request.exec(@buffered_socket, "1.1", "/some/other/path")
str = @socket.string
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str.should =~ %r[Content-Type: text/html\r\n]
str.should =~ %r[Content-Length: 10\r\n]
str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
end
it "sends the request in chunks when 'Transfer-Encoding' is set to 'chunked'" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
"Content-Type" => "text/html",
"Transfer-Encoding" => "chunked")
datasize = 1024 * 10
request.body_stream = StringIO.new("a" * datasize)
request.exec(@buffered_socket, "1.1", "/some/other/path")
str = @socket.string
str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
str.should =~ %r[Accept: \*/\*\r\n]
str.should =~ %r[Content-Type: text/html\r\n]
str.should =~ %r[Transfer-Encoding: chunked\r\n]
str =~ %r[\r\n\r\n]
str = $'
while datasize > 0
chunk_size_line, str = str.split(/\r\n/, 2)
chunk_size = chunk_size_line[/\A[0-9A-Fa-f]+/].to_i(16)
str.slice!(0, chunk_size).should == 'a' * chunk_size
datasize -= chunk_size
str.slice!(0, 2).should == "\r\n"
end
datasize.should == 0
str.should == %"0\r\n\r\n"
end
it "raises an ArgumentError when the 'Content-Length' is not set or 'Transfer-Encoding' is not set to 'chunked'" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
"Content-Type" => "text/html")
request.body_stream = StringIO.new("Some Content")
lambda { request.exec(@buffered_socket, "1.1", "/some/other/path") }.should raise_error(ArgumentError)
end
end
end

View file

@ -0,0 +1,25 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#inspect" do
it "returns a String representation of self" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.inspect.should == "#<Net::HTTPGenericRequest POST>"
request = Net::HTTPGenericRequest.new("GET", false, true, "/some/path")
request.inspect.should == "#<Net::HTTPGenericRequest GET>"
request = Net::HTTPGenericRequest.new("BLA", true, true, "/some/path")
request.inspect.should == "#<Net::HTTPGenericRequest BLA>"
# Subclasses
request = Net::HTTP::Get.new("/some/path")
request.inspect.should == "#<Net::HTTP::Get GET>"
request = Net::HTTP::Post.new("/some/path")
request.inspect.should == "#<Net::HTTP::Post POST>"
request = Net::HTTP::Trace.new("/some/path")
request.inspect.should == "#<Net::HTTP::Trace TRACE>"
end
end

View file

@ -0,0 +1,15 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#method" do
it "returns self's request method" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.method.should == "POST"
request = Net::HTTPGenericRequest.new("GET", false, true, "/some/path")
request.method.should == "GET"
request = Net::HTTPGenericRequest.new("BLA", true, true, "/some/path")
request.method.should == "BLA"
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#path" do
it "returns self's request path" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.path.should == "/some/path"
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/other/path")
request.path.should == "/some/other/path"
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#request_body_permitted?" do
it "returns true when the request is expected to have a body" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.request_body_permitted?.should be_true
request = Net::HTTPGenericRequest.new("POST", false, true, "/some/path")
request.request_body_permitted?.should be_false
end
end

View file

@ -0,0 +1,12 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#response_body_permitted?" do
it "returns true when the response is expected to have a body" do
request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
request.response_body_permitted?.should be_true
request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
request.response_body_permitted?.should be_false
end
end

View file

@ -0,0 +1,21 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
describe "Net::HTTPGenericRequest#set_body_internal when passed string" do
before :each do
@request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
end
it "sets self's body to the passed string" do
@request.set_body_internal("Some Content")
@request.body.should == "Some Content"
end
it "raises an ArgumentError when the body or body_stream of self have already been set" do
@request.body = "Some Content"
lambda { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError)
@request.body_stream = "Some Content"
lambda { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError)
end
end

View file

@ -0,0 +1,31 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#add_field when passed key, value" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "adds the passed value to the header entry with the passed key" do
@headers.add_field("My-Header", "a")
@headers.get_fields("My-Header").should == ["a"]
@headers.add_field("My-Header", "b")
@headers.get_fields("My-Header").should == ["a", "b"]
@headers.add_field("My-Header", "c")
@headers.get_fields("My-Header").should == ["a", "b", "c"]
end
it "is case-insensitive" do
@headers.add_field("My-Header", "a")
@headers.get_fields("My-Header").should == ["a"]
@headers.add_field("my-header", "b")
@headers.get_fields("My-Header").should == ["a", "b"]
@headers.add_field("MY-HEADER", "c")
@headers.get_fields("My-Header").should == ["a", "b", "c"]
end
end

View file

@ -0,0 +1,14 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#basic_auth when passed account, password" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "sets the 'Authorization' Header entry for basic authorization" do
@headers.basic_auth("rubyspec", "rocks")
@headers["Authorization"].should == "Basic cnVieXNwZWM6cm9ja3M="
end
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/each_capitalized', __FILE__)
describe "Net::HTTPHeader#canonical_each" do
it_behaves_like :net_httpheader_each_capitalized, :canonical_each
end

View file

@ -0,0 +1,22 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#chunked?" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "returns true if the 'Transfer-Encoding' header entry is set to chunked" do
@headers.chunked?.should be_false
@headers["Transfer-Encoding"] = "bla"
@headers.chunked?.should be_false
@headers["Transfer-Encoding"] = "blachunkedbla"
@headers.chunked?.should be_false
@headers["Transfer-Encoding"] = "chunked"
@headers.chunked?.should be_true
end
end

View file

@ -0,0 +1,54 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#content_length" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "returns nil if no 'Content-Length' header entry is set" do
@headers.content_length.should be_nil
end
it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Length' header entry has an invalid format" do
@headers["Content-Length"] = "invalid"
lambda { @headers.content_length }.should raise_error(Net::HTTPHeaderSyntaxError)
end
it "returns the value of the 'Content-Length' header entry as an Integer" do
@headers["Content-Length"] = "123"
@headers.content_length.should eql(123)
@headers["Content-Length"] = "123valid"
@headers.content_length.should eql(123)
@headers["Content-Length"] = "valid123"
@headers.content_length.should eql(123)
end
end
describe "Net::HTTPHeader#content_length=" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "removes the 'Content-Length' entry if passed false or nil" do
@headers["Content-Length"] = "123"
@headers.content_length = nil
@headers["Content-Lenght"].should be_nil
end
it "sets the 'Content-Length' entry to the passed value" do
@headers.content_length = "123"
@headers["Content-Length"].should == "123"
@headers.content_length = "123valid"
@headers["Content-Length"].should == "123"
end
it "sets the 'Content-Length' entry to 0 if the passed value is not valid" do
@headers.content_length = "invalid123"
@headers["Content-Length"].should == "0"
end
end

View file

@ -0,0 +1,32 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#content_range" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "returns a Range object that represents the 'Content-Range' header entry" do
@headers["Content-Range"] = "bytes 0-499/1234"
@headers.content_range.should == (0..499)
@headers["Content-Range"] = "bytes 500-1233/1234"
@headers.content_range.should == (500..1233)
end
it "returns nil when there is no 'Content-Range' header entry" do
@headers.content_range.should be_nil
end
it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do
@headers["Content-Range"] = "invalid"
lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
@headers["Content-Range"] = "bytes 123-abc"
lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
@headers["Content-Range"] = "bytes abc-123"
lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
end
end

View file

@ -0,0 +1,26 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/set_content_type', __FILE__)
describe "Net::HTTPHeader#content_type" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "returns the content type string, as per 'Content-Type' header entry" do
@headers["Content-Type"] = "text/html"
@headers.content_type.should == "text/html"
@headers["Content-Type"] = "text/html;charset=utf-8"
@headers.content_type.should == "text/html"
end
it "returns nil if the 'Content-Type' header entry does not exist" do
@headers.content_type.should be_nil
end
end
describe "Net::HTTPHeader#content_type=" do
it_behaves_like :net_httpheader_set_content_type, :content_type=
end

View file

@ -0,0 +1,30 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#delete when passed key" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "removes the header entry with the passed key" do
@headers["My-Header"] = "test"
@headers.delete("My-Header")
@headers["My-Header"].should be_nil
@headers.size.should eql(0)
end
it "returns the removed values" do
@headers["My-Header"] = "test"
@headers.delete("My-Header").should == ["test"]
end
it "is case-insensitive" do
@headers["My-Header"] = "test"
@headers.delete("my-header")
@headers["My-Header"].should be_nil
@headers.size.should eql(0)
end
end

View file

@ -0,0 +1,35 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#each_capitalized_name" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
@headers["My-Header"] = "test"
@headers.add_field("My-Other-Header", "a")
@headers.add_field("My-Other-Header", "b")
end
describe "when passed a block" do
it "yields each header key to the passed block (keys capitalized)" do
res = []
@headers.each_capitalized_name do |key|
res << key
end
res.sort.should == ["My-Header", "My-Other-Header"]
end
end
describe "when passed no block" do
it "returns an Enumerator" do
enumerator = @headers.each_capitalized_name
enumerator.should be_an_instance_of(Enumerator)
res = []
enumerator.each do |key|
res << key
end
res.sort.should == ["My-Header", "My-Other-Header"]
end
end
end

View file

@ -0,0 +1,9 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/each_capitalized', __FILE__)
describe "Net::HTTPHeader#each_capitalized" do
it_behaves_like :net_httpheader_each_capitalized, :each_capitalized
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/each_header', __FILE__)
describe "Net::HTTPHeader#each_header" do
it_behaves_like :net_httpheader_each_header, :each_header
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/each_name', __FILE__)
describe "Net::HTTPHeader#each_key" do
it_behaves_like :net_httpheader_each_name, :each_key
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/each_name', __FILE__)
describe "Net::HTTPHeader#each_name" do
it_behaves_like :net_httpheader_each_name, :each_name
end

View file

@ -0,0 +1,8 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/each_header', __FILE__)
describe "Net::HTTPHeader#each" do
it_behaves_like :net_httpheader_each_header, :each
end

View file

@ -0,0 +1,35 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#each_value" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
@headers["My-Header"] = "test"
@headers.add_field("My-Other-Header", "a")
@headers.add_field("My-Other-Header", "b")
end
describe "when passed a block" do
it "yields each header entry's joined values" do
res = []
@headers.each_value do |value|
res << value
end
res.sort.should == ["a, b", "test"]
end
end
describe "when passed no block" do
it "returns an Enumerator" do
enumerator = @headers.each_value
enumerator.should be_an_instance_of(Enumerator)
res = []
enumerator.each do |key|
res << key
end
res.sort.should == ["a, b", "test"]
end
end
end

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
require File.expand_path('../fixtures/classes', __FILE__)
describe "Net::HTTPHeader#[] when passed key" do
before :each do
@headers = NetHTTPHeaderSpecs::Example.new
end
it "returns the value of the header entry with the passed key" do
@headers["My-Header"] = "test"
@headers["My-Header"].should == "test"
@headers["My-Other-Header"] = "another test"
@headers["My-Other-Header"].should == "another test"
end
it "is case-insensitive" do
@headers["My-Header"] = "test"
@headers['My-Header'].should == "test"
@headers['my-Header'].should == "test"
@headers['My-header'].should == "test"
@headers['my-header'].should == "test"
@headers['MY-HEADER'].should == "test"
end
it "returns multi-element values joined together" do
@headers["My-Header"] = "test"
@headers.add_field("My-Header", "another test")
@headers.add_field("My-Header", "and one more")
@headers["My-Header"].should == "test, another test, and one more"
end
it "returns nil for non-existing entries" do
@headers["My-Header"].should be_nil
@headers["My-Other-Header"].should be_nil
end
end

Some files were not shown because too many files have changed in this diff Show more