1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

add specs for maintain_method_across_redirects assignment on head requests

This commit is contained in:
Mark Lehman 2015-08-24 15:46:47 -07:00
parent 58fc195b6f
commit 6b0201d3ab

View file

@ -590,19 +590,28 @@ RSpec.describe HTTParty do
describe "head requests should follow redirects requesting HEAD only" do describe "head requests should follow redirects requesting HEAD only" do
before do before do
@request = HTTParty::Request.new(Net::HTTP::Head, 'http://api.foo.com/v1') allow(HTTParty::Request).to receive(:new).
@redirect = stub_response 'first redirect', 302 and_return(double("mock response", perform: nil))
@redirect['location'] = 'http://foo.com/bar'
allow(HTTParty::Request).to receive_messages(new: @request)
end end
it "should set maintain_method_across_redirects option if unspecified" do it "should remain HEAD request across redirects, unless specified otherwise" do
# This is what I'm trying to do: expect(@klass).to receive(:ensure_method_maintained_across_redirects).with({})
# expect(@klass.head('/foo').body).to be_nil @klass.head('/foo')
end
# This is what I get instead: end
# HTTParty::RedirectionTooDeep: HTTP redirects too deep
# from /Users/Lehman/Desktop/Code/httparty/lib/httparty/request.rb:344:in `validate' describe "#ensure_method_maintained_across_redirects" do
it "should set maintain_method_across_redirects option if unspecified" do
options = {}
@klass.send(:ensure_method_maintained_across_redirects, options)
expect(options[:maintain_method_across_redirects]).to be_truthy
end
it "should not set maintain_method_across_redirects option if value is present" do
options = { maintain_method_across_redirects: false }
@klass.send(:ensure_method_maintained_across_redirects, options)
expect(options[:maintain_method_across_redirects]).to be_falsey
end end
end end