Skip to content

Commit

Permalink
Improve client stubs in specs
Browse files Browse the repository at this point in the history
Make them closer to reality.
Related to: #546
  • Loading branch information
ixti committed Oct 21, 2019
1 parent a2c49ea commit 0b51aa7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions spec/lib/http/client_spec.rb
Expand Up @@ -10,7 +10,8 @@

StubbedClient = Class.new(HTTP::Client) do
def perform(request, options)
stubs.fetch(request.uri) { super(request, options) }
stubbed = stubs[request.uri]
stubbed ? stubbed.call(request) : super(request, options)
end

def stubs
Expand All @@ -27,22 +28,26 @@ def stub(stubs)
end

def redirect_response(location, status = 302)
HTTP::Response.new(
:status => status,
:version => "1.1",
:headers => {"Location" => location},
:body => "",
:request => HTTP::Request.new(:verb => :get, :uri => "http://example.com")
)
lambda do |request|
HTTP::Response.new(
:status => status,
:version => "1.1",
:headers => {"Location" => location},
:body => "",
:request => request
)
end
end

def simple_response(body, status = 200)
HTTP::Response.new(
:status => status,
:version => "1.1",
:body => body,
:request => HTTP::Request.new(:verb => :get, :uri => "http://example.com")
)
lambda do |request|
HTTP::Response.new(
:status => status,
:version => "1.1",
:body => body,
:request => request
)
end
end

describe "following redirects" do
Expand Down

0 comments on commit 0b51aa7

Please sign in to comment.