Skip to content

Commit

Permalink
Use #to_return with stub_request consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
JonMidhir committed Jun 8, 2017
1 parent 7516697 commit d195bfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
},
{ status: ['200', 'OK'] }
]
stub_request(:get, 'http://api.foo.com/v1').and_return(response_sequence)
stub_request(:get, 'http://api.foo.com/v1').to_return(response_sequence)
end

it 'should not send credentials more than once' do
Expand All @@ -187,7 +187,7 @@
},
{ status: ['404', 'Not found'] }
]
stub_request(:get, 'http://api.foo.com/v1').and_return(response_sequence)
stub_request(:get, 'http://api.foo.com/v1').to_return(response_sequence)

@request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
response = @request.perform { |v| }
Expand All @@ -198,7 +198,7 @@
end

it 'should not be used when configured and the response is 200' do
stub_request(:get, 'http://api.foo.com/v1').and_return(status: 200)
stub_request(:get, 'http://api.foo.com/v1').to_return(status: 200)
@request.options[:digest_auth] = {username: 'foobar', password: 'secret'}
response = @request.perform { |v| }
expect(response.code).to eq(200)
Expand Down Expand Up @@ -572,12 +572,12 @@
it "calls block given to perform with each redirect" do
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
stub_request(:get, 'http://test.com/redirect')
.and_return(
.to_return(
status: [300, 'REDIRECT'],
headers: { location: 'http://api.foo.com/v2' }
)
stub_request(:get, 'http://api.foo.com/v2')
.and_return(body: '<hash><foo>bar</foo></hash>')
.to_return(body: '<hash><foo>bar</foo></hash>')
body = ""
response = @request.perform { |chunk| body += chunk }
expect(body.length).to eq(27)
Expand All @@ -599,17 +599,17 @@
it "handles multiple redirects and relative location headers on different hosts" do
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
stub_request(:get, 'http://test.com/redirect')
.and_return(
.to_return(
status: [300, 'REDIRECT'],
headers: { location: "http://api.foo.com/v2" }
)
stub_request(:get, 'http://api.foo.com/v2')
.and_return(
.to_return(
status: [300, 'REDIRECT'],
headers: { location: '/v3' }
)
stub_request(:get, 'http://api.foo.com/v3')
.and_return(body: '<hash><foo>bar</foo></hash>')
.to_return(body: '<hash><foo>bar</foo></hash>')
response = @request.perform
expect(response.request.base_uri.to_s).to eq("http://api.foo.com")
expect(response.request.path.to_s).to eq("/v3")
Expand All @@ -621,7 +621,7 @@
it "raises an error if redirect has duplicate location header" do
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://test.com/redirect', format: :xml)
stub_request(:get, 'http://test.com/redirect')
.and_return(
.to_return(
status: [300, 'REDIRECT'],
headers: {
location: ['http://api.foo.com/v2', 'http://api.foo.com/v2']
Expand All @@ -637,12 +637,12 @@

it "redirects including port" do
stub_request(:get, 'http://withport.com:3000/v1')
.and_return(
.to_return(
status: [301, 'Moved Permanently'],
headers: { location: 'http://withport.com:3000/v2' }
)
stub_request(:get, 'http://withport.com:3000/v2')
.and_return(status: 200)
.to_return(status: 200)
request = HTTParty::Request.new(Net::HTTP::Get, 'http://withport.com:3000/v1')
response = request.perform
expect(response.request.base_uri.to_s).to eq("http://withport.com:3000")
Expand Down
8 changes: 4 additions & 4 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def self.parse(body)
it "should be able parse response with custom parser" do
@klass.parser parser
stub_request(:get, 'http://twitter.com/statuses/public_timeline.xml')
.and_return(body: 'tweets')
.to_return(body: 'tweets')
custom_parsed_response = @klass.get('http://twitter.com/statuses/public_timeline.xml')
expect(custom_parsed_response[:sexy]).to eq(true)
end
Expand Down Expand Up @@ -389,7 +389,7 @@ def self.parse uri

it "should process a request with a uri instance parsed from the uri_adapter" do
uri = 'http://foo.com/bar'
stub_request(:get, uri).and_return(body: 'stuff')
stub_request(:get, uri).to_return(body: 'stuff')
@klass.uri_adapter uri_adapter
expect(@klass.get(uri).parsed_response).to eq('stuff')
end
Expand Down Expand Up @@ -422,7 +422,7 @@ def self.parse uri
expect(o[:connection_adapter_options]).to eq(connection_adapter_options)
HTTParty::ConnectionAdapter.call(u, o)
}.with(URI.parse(uri), kind_of(Hash))
stub_request(:get, uri).and_return(body: 'stuff')
stub_request(:get, uri).to_return(body: 'stuff')
@klass.connection_adapter connection_adapter, connection_adapter_options
expect(@klass.get(uri).parsed_response).to eq('stuff')
end
Expand Down Expand Up @@ -862,7 +862,7 @@ def self.inherited(subclass)

it "should accept webcal URIs" do
uri = 'http://google.com/'
stub_request(:get, uri).and_return(body: 'stuff')
stub_request(:get, uri).to_return(body: 'stuff')
uri = 'webcal://google.com/'
expect do
HTTParty.get(uri)
Expand Down

0 comments on commit d195bfd

Please sign in to comment.