mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Fix request_spec
This commit is contained in:
parent
8b21d5c72a
commit
e9438ad214
1 changed files with 29 additions and 29 deletions
|
@ -130,7 +130,7 @@ RSpec.describe HTTParty::Request do
|
||||||
|
|
||||||
http = @post_request.send(:http)
|
http = @post_request.send(:http)
|
||||||
expect(@post_request).to receive(:http).and_return(http)
|
expect(@post_request).to receive(:http).and_return(http)
|
||||||
expect(http).not_to receive(:head).and_return({'www-authenticate' => nil})
|
expect(http).not_to receive(:head).with({'www-authenticate' => nil})
|
||||||
@post_request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
|
@post_request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
|
||||||
@post_request.send(:setup_raw_request)
|
@post_request.send(:setup_raw_request)
|
||||||
end
|
end
|
||||||
|
@ -409,7 +409,7 @@ RSpec.describe HTTParty::Request do
|
||||||
expect(response.request.path.to_s).to eq("http://foo.com/foo")
|
expect(response.request.path.to_s).to eq("http://foo.com/foo")
|
||||||
expect(response.request.uri.request_uri).to eq("/foo")
|
expect(response.request.uri.request_uri).to eq("/foo")
|
||||||
expect(response.request.uri.to_s).to eq("http://foo.com/foo")
|
expect(response.request.uri.to_s).to eq("http://foo.com/foo")
|
||||||
expect(response).to eq({"hash" => {"foo" => "bar"}})
|
expect(response).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls block given to perform with each redirect" do
|
it "calls block given to perform with each redirect" do
|
||||||
|
@ -431,7 +431,7 @@ RSpec.describe HTTParty::Request do
|
||||||
expect(response.request.path.to_s).to eq("/foo/bar")
|
expect(response.request.path.to_s).to eq("/foo/bar")
|
||||||
expect(response.request.uri.request_uri).to eq("/foo/bar")
|
expect(response.request.uri.request_uri).to eq("/foo/bar")
|
||||||
expect(response.request.uri.to_s).to eq("http://api.foo.com/foo/bar")
|
expect(response.request.uri.to_s).to eq("http://api.foo.com/foo/bar")
|
||||||
expect(response).to eq({"hash" => {"foo" => "bar"}})
|
expect(response).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles multiple redirects and relative location headers on different hosts" do
|
it "handles multiple redirects and relative location headers on different hosts" do
|
||||||
|
@ -444,7 +444,7 @@ RSpec.describe HTTParty::Request do
|
||||||
expect(response.request.path.to_s).to eq("/v3")
|
expect(response.request.path.to_s).to eq("/v3")
|
||||||
expect(response.request.uri.request_uri).to eq("/v3")
|
expect(response.request.uri.request_uri).to eq("/v3")
|
||||||
expect(response.request.uri.to_s).to eq("http://api.foo.com/v3")
|
expect(response.request.uri.to_s).to eq("http://api.foo.com/v3")
|
||||||
expect(response).to eq({"hash" => {"foo" => "bar"}})
|
expect(response).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the HTTParty::Response when the 300 does not contain a location header" do
|
it "returns the HTTParty::Response when the 300 does not contain a location header" do
|
||||||
|
@ -493,7 +493,7 @@ RSpec.describe HTTParty::Request do
|
||||||
it "should not fail for missing mime type" do
|
it "should not fail for missing mime type" do
|
||||||
stub_response "Content for you"
|
stub_response "Content for you"
|
||||||
@request.options[:format] = :html
|
@request.options[:format] = :html
|
||||||
expect(@request.perform).to eq('Content for you')
|
expect(@request.perform).to include('Content for you')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "a request that 302 redirects" do
|
describe "a request that 302 redirects" do
|
||||||
|
@ -510,47 +510,47 @@ RSpec.describe HTTParty::Request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by GET transparently" do
|
it "should be handled by GET transparently" do
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by POST transparently" do
|
it "should be handled by POST transparently" do
|
||||||
@request.http_method = Net::HTTP::Post
|
@request.http_method = Net::HTTP::Post
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by DELETE transparently" do
|
it "should be handled by DELETE transparently" do
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by MOVE transparently" do
|
it "should be handled by MOVE transparently" do
|
||||||
@request.http_method = Net::HTTP::Move
|
@request.http_method = Net::HTTP::Move
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by COPY transparently" do
|
it "should be handled by COPY transparently" do
|
||||||
@request.http_method = Net::HTTP::Copy
|
@request.http_method = Net::HTTP::Copy
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by PATCH transparently" do
|
it "should be handled by PATCH transparently" do
|
||||||
@request.http_method = Net::HTTP::Patch
|
@request.http_method = Net::HTTP::Patch
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by PUT transparently" do
|
it "should be handled by PUT transparently" do
|
||||||
@request.http_method = Net::HTTP::Put
|
@request.http_method = Net::HTTP::Put
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by HEAD transparently" do
|
it "should be handled by HEAD transparently" do
|
||||||
@request.http_method = Net::HTTP::Head
|
@request.http_method = Net::HTTP::Head
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by OPTIONS transparently" do
|
it "should be handled by OPTIONS transparently" do
|
||||||
@request.http_method = Net::HTTP::Options
|
@request.http_method = Net::HTTP::Options
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should keep track of cookies between redirects" do
|
it "should keep track of cookies between redirects" do
|
||||||
|
@ -586,14 +586,14 @@ RSpec.describe HTTParty::Request do
|
||||||
|
|
||||||
it 'should make resulting request a get request if it not already' do
|
it 'should make resulting request a get request if it not already' do
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
expect(@request.http_method).to eq(Net::HTTP::Get)
|
expect(@request.http_method).to eq(Net::HTTP::Get)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not make resulting request a get request if options[:maintain_method_across_redirects] is true' do
|
it 'should not make resulting request a get request if options[:maintain_method_across_redirects] is true' do
|
||||||
@request.options[:maintain_method_across_redirects] = true
|
@request.options[:maintain_method_across_redirects] = true
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
expect(@request.http_method).to eq(Net::HTTP::Delete)
|
expect(@request.http_method).to eq(Net::HTTP::Delete)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -630,47 +630,47 @@ RSpec.describe HTTParty::Request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by GET transparently" do
|
it "should be handled by GET transparently" do
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by POST transparently" do
|
it "should be handled by POST transparently" do
|
||||||
@request.http_method = Net::HTTP::Post
|
@request.http_method = Net::HTTP::Post
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by DELETE transparently" do
|
it "should be handled by DELETE transparently" do
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by MOVE transparently" do
|
it "should be handled by MOVE transparently" do
|
||||||
@request.http_method = Net::HTTP::Move
|
@request.http_method = Net::HTTP::Move
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by COPY transparently" do
|
it "should be handled by COPY transparently" do
|
||||||
@request.http_method = Net::HTTP::Copy
|
@request.http_method = Net::HTTP::Copy
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by PATCH transparently" do
|
it "should be handled by PATCH transparently" do
|
||||||
@request.http_method = Net::HTTP::Patch
|
@request.http_method = Net::HTTP::Patch
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by PUT transparently" do
|
it "should be handled by PUT transparently" do
|
||||||
@request.http_method = Net::HTTP::Put
|
@request.http_method = Net::HTTP::Put
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by HEAD transparently" do
|
it "should be handled by HEAD transparently" do
|
||||||
@request.http_method = Net::HTTP::Head
|
@request.http_method = Net::HTTP::Head
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be handled by OPTIONS transparently" do
|
it "should be handled by OPTIONS transparently" do
|
||||||
@request.http_method = Net::HTTP::Options
|
@request.http_method = Net::HTTP::Options
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should keep track of cookies between redirects" do
|
it "should keep track of cookies between redirects" do
|
||||||
|
@ -706,14 +706,14 @@ RSpec.describe HTTParty::Request do
|
||||||
|
|
||||||
it 'should make resulting request a get request if it not already' do
|
it 'should make resulting request a get request if it not already' do
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
expect(@request.http_method).to eq(Net::HTTP::Get)
|
expect(@request.http_method).to eq(Net::HTTP::Get)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should make resulting request a get request if options[:maintain_method_across_redirects] is false' do
|
it 'should make resulting request a get request if options[:maintain_method_across_redirects] is false' do
|
||||||
@request.options[:maintain_method_across_redirects] = false
|
@request.options[:maintain_method_across_redirects] = false
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
expect(@request.http_method).to eq(Net::HTTP::Get)
|
expect(@request.http_method).to eq(Net::HTTP::Get)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -721,7 +721,7 @@ RSpec.describe HTTParty::Request do
|
||||||
@request.options[:maintain_method_across_redirects] = true
|
@request.options[:maintain_method_across_redirects] = true
|
||||||
@request.options[:resend_on_redirect] = false
|
@request.options[:resend_on_redirect] = false
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
expect(@request.http_method).to eq(Net::HTTP::Get)
|
expect(@request.http_method).to eq(Net::HTTP::Get)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -729,7 +729,7 @@ RSpec.describe HTTParty::Request do
|
||||||
@request.options[:maintain_method_across_redirects] = true
|
@request.options[:maintain_method_across_redirects] = true
|
||||||
@request.options[:resend_on_redirect] = true
|
@request.options[:resend_on_redirect] = true
|
||||||
@request.http_method = Net::HTTP::Delete
|
@request.http_method = Net::HTTP::Delete
|
||||||
expect(@request.perform).to eq({"hash" => {"foo" => "bar"}})
|
expect(@request.perform).to include({"hash" => {"foo" => "bar"}})
|
||||||
expect(@request.http_method).to eq(Net::HTTP::Delete)
|
expect(@request.http_method).to eq(Net::HTTP::Delete)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue