diff --git a/features/steps/httparty_steps.rb b/features/steps/httparty_steps.rb index 05dda65..88a5956 100644 --- a/features/steps/httparty_steps.rb +++ b/features/steps/httparty_steps.rb @@ -3,11 +3,11 @@ When /^I set my HTTParty timeout option to (\d+)$/ do |timeout| end When /^I set my HTTParty open_timeout option to (\d+)$/ do |timeout| - @request_options[:open_timeout] = timeout.to_i + @request_options[:open_timeout] = timeout.to_i end When /^I set my HTTParty read_timeout option to (\d+)$/ do |timeout| - @request_options[:read_timeout] = timeout.to_i + @request_options[:read_timeout] = timeout.to_i end When /I call HTTParty#get with '(.*)'$/ do |url| diff --git a/lib/httparty.rb b/lib/httparty.rb index 94f076a..b96789b 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -194,8 +194,8 @@ module HTTParty # read_timeout 10 # end def read_timeout(t) - raise ArgumentError, 'read_timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float)) - default_options[:read_timeout] = t + raise ArgumentError, 'read_timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float)) + default_options[:read_timeout] = t end # Set an output stream for debugging, defaults to $stderr. diff --git a/lib/httparty/connection_adapter.rb b/lib/httparty/connection_adapter.rb index e908eb8..e13bb09 100644 --- a/lib/httparty/connection_adapter.rb +++ b/lib/httparty/connection_adapter.rb @@ -84,11 +84,11 @@ module HTTParty end if options[:read_timeout] && (options[:read_timeout].is_a?(Integer) || options[:read_timeout].is_a?(Float)) - http.read_timeout = options[:read_timeout] + http.read_timeout = options[:read_timeout] end - if options[:open_timeout] && (options[:open_timeout].is_a?(Integer) || options[:open_timeout].is_a?(Float)) - http.open_timeout = options[:open_timeout] + if options[:open_timeout] && (options[:open_timeout].is_a?(Integer) || options[:open_timeout].is_a?(Float)) + http.open_timeout = options[:open_timeout] end if options[:debug_output] diff --git a/spec/httparty/connection_adapter_spec.rb b/spec/httparty/connection_adapter_spec.rb index 04b3a77..12b147a 100644 --- a/spec/httparty/connection_adapter_spec.rb +++ b/spec/httparty/connection_adapter_spec.rb @@ -154,59 +154,59 @@ describe HTTParty::ConnectionAdapter do end context "when timeout is not set and read_timeout is set to 6 seconds" do - let(:options) { {:read_timeout => 6} } + let(:options) { {:read_timeout => 6} } - its(:read_timeout) { should == 6 } + its(:read_timeout) { should == 6 } - it "should not set the open_timeout" do - http = mock("http", :null_object => true) - http.should_not_receive(:open_timeout=) - Net::HTTP.stub(:new => http) - adapter.connection - end + it "should not set the open_timeout" do + http = mock("http", :null_object => true) + http.should_not_receive(:open_timeout=) + Net::HTTP.stub(:new => http) + adapter.connection + end end context "when timeout is set and read_timeout is set to 6 seconds" do - let(:options) { {:timeout => 5, :read_timeout => 6} } + let(:options) { {:timeout => 5, :read_timeout => 6} } - its(:open_timeout) { should == 5 } - its(:read_timeout) { should == 6 } + its(:open_timeout) { should == 5 } + its(:read_timeout) { should == 6 } - it "should override the timeout option" do - http = mock("http", :null_object => true) - http.should_receive(:open_timeout=) - http.should_receive(:read_timeout=).twice - Net::HTTP.stub(:new => http) - adapter.connection - end + it "should override the timeout option" do + http = mock("http", :null_object => true) + http.should_receive(:open_timeout=) + http.should_receive(:read_timeout=).twice + Net::HTTP.stub(:new => http) + adapter.connection + end end context "when timeout is not set and open_timeout is set to 7 seconds" do - let(:options) { {:open_timeout => 7} } + let(:options) { {:open_timeout => 7} } - its(:open_timeout) { should == 7 } + its(:open_timeout) { should == 7 } - it "should not set the read_timeout" do - http = mock("http", :null_object => true) - http.should_not_receive(:read_timeout=) - Net::HTTP.stub(:new => http) - adapter.connection - end + it "should not set the read_timeout" do + http = mock("http", :null_object => true) + http.should_not_receive(:read_timeout=) + Net::HTTP.stub(:new => http) + adapter.connection + end end context "when timeout is set and open_timeout is set to 7 seconds" do - let(:options) { {:timeout => 5, :open_timeout => 7} } + let(:options) { {:timeout => 5, :open_timeout => 7} } - its(:open_timeout) { should == 7 } - its(:read_timeout) { should == 5 } + its(:open_timeout) { should == 7 } + its(:read_timeout) { should == 5 } - it "should override the timeout option" do - http = mock("http", :null_object => true) - http.should_receive(:open_timeout=).twice - http.should_receive(:read_timeout=) - Net::HTTP.stub(:new => http) - adapter.connection - end + it "should override the timeout option" do + http = mock("http", :null_object => true) + http.should_receive(:open_timeout=).twice + http.should_receive(:read_timeout=) + Net::HTTP.stub(:new => http) + adapter.connection + end end context "when debug_output" do