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

Use #parsed_response and eq matcher instead of includes matcher

This commit is contained in:
Michael Stock 2014-12-08 21:01:13 -08:00
parent 0b0cac7381
commit 40e383af13
4 changed files with 36 additions and 36 deletions

View file

@ -16,7 +16,7 @@ Then /it should return an? (\w+)$/ do |class_string|
end end
Then /the return value should match '(.*)'/ do |expected_text| Then /the return value should match '(.*)'/ do |expected_text|
expect(@response_from_httparty).to include(expected_text) expect(@response_from_httparty.parsed_response).to eq(expected_text)
end end
Then /it should return a Hash equaling:/ do |hash_table| Then /it should return a Hash equaling:/ do |hash_table|

View file

@ -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 include({"hash" => {"foo" => "bar"}}) expect(response.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(response.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(response.parsed_response).to eq({"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 include('Content for you') expect(@request.perform.parsed_response).to eq('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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"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 include({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
expect(@request.http_method).to eq(Net::HTTP::Delete) expect(@request.http_method).to eq(Net::HTTP::Delete)
end end

View file

@ -17,7 +17,7 @@ RSpec.describe HTTParty::Request do
end end
it "should work when no trusted CA list is specified, when the verify option is set to false" do it "should work when no trusted CA list is specified, when the verify option is set to false" do
expect(ssl_verify_test(nil, nil, "selfsigned.crt", verify: false)).to include({'success' => true}) expect(ssl_verify_test(nil, nil, "selfsigned.crt", verify: false).parsed_response).to eq({'success' => true})
end end
it "should fail when no trusted CA list is specified, with a bogus hostname, by default" do it "should fail when no trusted CA list is specified, with a bogus hostname, by default" do
@ -27,15 +27,15 @@ RSpec.describe HTTParty::Request do
end end
it "should work when no trusted CA list is specified, even with a bogus hostname, when the verify option is set to true" do it "should work when no trusted CA list is specified, even with a bogus hostname, when the verify option is set to true" do
expect(ssl_verify_test(nil, nil, "bogushost.crt", verify: false)).to include({'success' => true}) expect(ssl_verify_test(nil, nil, "bogushost.crt", verify: false).parsed_response).to eq({'success' => true})
end end
it "should work when using ssl_ca_file with a self-signed CA" do it "should work when using ssl_ca_file with a self-signed CA" do
expect(ssl_verify_test(:ssl_ca_file, "selfsigned.crt", "selfsigned.crt")).to include({'success' => true}) expect(ssl_verify_test(:ssl_ca_file, "selfsigned.crt", "selfsigned.crt").parsed_response).to eq({'success' => true})
end end
it "should work when using ssl_ca_file with a certificate authority" do it "should work when using ssl_ca_file with a certificate authority" do
expect(ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt")).to include({'success' => true}) expect(ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt").parsed_response).to eq({'success' => true})
end end
it "should work when using ssl_ca_path with a certificate authority" do it "should work when using ssl_ca_path with a certificate authority" do

View file

@ -394,7 +394,7 @@ RSpec.describe HTTParty do
}.with(URI.parse(uri), kind_of(Hash)) }.with(URI.parse(uri), kind_of(Hash))
FakeWeb.register_uri(:get, uri, body: 'stuff') FakeWeb.register_uri(:get, uri, body: 'stuff')
@klass.connection_adapter connection_adapter, connection_adapter_options @klass.connection_adapter connection_adapter, connection_adapter_options
expect(@klass.get(uri)).to include('stuff') expect(@klass.get(uri).parsed_response).to eq('stuff')
end end
end end
@ -687,7 +687,7 @@ RSpec.describe HTTParty do
describe "#get" do describe "#get" do
it "should be able to get html" do it "should be able to get html" do
stub_http_response_with('google.html') stub_http_response_with('google.html')
expect(HTTParty.get('http://www.google.com')).to include(file_fixture('google.html')) expect(HTTParty.get('http://www.google.com').parsed_response).to eq(file_fixture('google.html'))
end end
it "should be able to get chunked html" do it "should be able to get chunked html" do
@ -758,7 +758,7 @@ RSpec.describe HTTParty do
it "should not get undefined method add_node for nil class for the following xml" do it "should not get undefined method add_node for nil class for the following xml" do
stub_http_response_with('undefined_method_add_node_for_nil.xml') stub_http_response_with('undefined_method_add_node_for_nil.xml')
result = HTTParty.get('http://foobar.com') result = HTTParty.get('http://foobar.com')
expect(result).to include({"Entities"=>{"href"=>"https://s3-sandbox.parature.com/api/v1/5578/5633/Account", "results"=>"0", "total"=>"0", "page_size"=>"25", "page"=>"1"}}) expect(result.parsed_response).to eq({"Entities"=>{"href"=>"https://s3-sandbox.parature.com/api/v1/5578/5633/Account", "results"=>"0", "total"=>"0", "page_size"=>"25", "page"=>"1"}})
end end
it "should parse empty response fine" do it "should parse empty response fine" do