mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
HTTParty#debug_output for debugging requests
This commit is contained in:
parent
23c2e13b55
commit
8347ac7880
3 changed files with 42 additions and 0 deletions
|
@ -82,6 +82,17 @@ module HTTParty
|
|||
default_options[:default_params].merge!(h)
|
||||
end
|
||||
|
||||
# Set an output stream for debugging, defaults to $stderr.
|
||||
# The output stream is passed on to Net::HTTP#set_debug_output.
|
||||
#
|
||||
# class Foo
|
||||
# include HTTParty
|
||||
# debug_output $stderr
|
||||
# end
|
||||
def debug_output(stream = $stderr)
|
||||
default_options[:debug_output] = stream
|
||||
end
|
||||
|
||||
# Allows setting a base uri to be used for each request.
|
||||
#
|
||||
# class Foo
|
||||
|
|
|
@ -111,6 +111,25 @@ describe HTTParty::Request do
|
|||
http.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
end
|
||||
|
||||
context "debugging" do
|
||||
before do
|
||||
@http = Net::HTTP.new('google.com')
|
||||
Net::HTTP.stub(:new => @http)
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://google.com')
|
||||
end
|
||||
|
||||
it "calls #set_debug_output when the option is provided" do
|
||||
@request.options[:debug_output] = $stderr
|
||||
@http.should_receive(:set_debug_output).with($stderr)
|
||||
@request.send(:http)
|
||||
end
|
||||
|
||||
it "does not set_debug_output when the option is not provided" do
|
||||
@http.should_not_receive(:set_debug_output)
|
||||
@request.send(:http)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should use basic auth when configured" do
|
||||
|
|
|
@ -203,6 +203,18 @@ describe HTTParty do
|
|||
end
|
||||
end
|
||||
|
||||
describe "debug_output" do
|
||||
it "stores the given stream as a default_option" do
|
||||
@klass.debug_output $stdout
|
||||
@klass.default_options[:debug_output].should == $stdout
|
||||
end
|
||||
|
||||
it "stores the $stderr stream by default" do
|
||||
@klass.debug_output
|
||||
@klass.default_options[:debug_output].should == $stderr
|
||||
end
|
||||
end
|
||||
|
||||
describe "basic http authentication" do
|
||||
it "should work" do
|
||||
@klass.basic_auth 'foobar', 'secret'
|
||||
|
|
Loading…
Add table
Reference in a new issue