1 require File.dirname(__FILE__) + '/../../../spec_helper'
3 require File.dirname(__FILE__) + '/fixtures/http_server'
5 describe "Net::HTTP.start" do
7 NetHTTPSpecs.start_server
11 NetHTTPSpecs.stop_server
14 it "returns a new Net::HTTP object for the passed address and port" do
15 net = Net::HTTP.start("localhost", 3333)
16 net.should be_kind_of(Net::HTTP)
17 net.address.should == "localhost"
18 net.port.should == 3333
21 it "opens the tcp connection" do
22 Net::HTTP.start("localhost", 3333).started?.should be_true
26 describe "Net::HTTP.start when passed a block" do
28 NetHTTPSpecs.start_server
32 NetHTTPSpecs.stop_server
35 it "returns the blocks return value" do
36 Net::HTTP.start("localhost", 3333) { :test }.should == :test
39 it "yields the new Net::HTTP object to the block" do
41 Net::HTTP.start("localhost", 3333) do |net|
43 net.should be_kind_of(Net::HTTP)
45 yielded.should be_true
48 it "opens the tcp connection before yielding" do
49 Net::HTTP.start("localhost", 3333) { |http| http.started?.should be_true }
52 it "closes the tcp connection after yielding" do
54 Net::HTTP.start("localhost", 3333) { |x| net = x }
55 net.started?.should be_false
59 describe "Net::HTTP#start" do
61 NetHTTPSpecs.start_server
65 NetHTTPSpecs.stop_server
69 @http = Net::HTTP.new("localhost", 3333)
73 @http.start.should equal(@http)
76 it "opens the tcp connection" do
78 @http.started?.should be_true
82 describe "Net::HTTP#start when self has already been started" do
84 NetHTTPSpecs.start_server
88 NetHTTPSpecs.stop_server
92 @http = Net::HTTP.new("localhost", 3333)
95 it "raises an IOError" do
97 lambda { @http.start }.should raise_error(IOError)
101 describe "Net::HTTP#start when passed a block" do
103 NetHTTPSpecs.start_server
107 NetHTTPSpecs.stop_server
111 @http = Net::HTTP.new("localhost", 3333)
114 it "returns the blocks return value" do
115 @http.start { :test }.should == :test
118 it "yields the new Net::HTTP object to the block" do
120 @http.start do |http|
122 http.should equal(@http)
124 yielded.should be_true
127 it "opens the tcp connection before yielding" do
128 @http.start { |http| http.started?.should be_true }
131 it "closes the tcp connection after yielding" do
133 @http.started?.should be_false