Skip to content

Commit

Permalink
Fixed the broken pass_request test case.
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <[email protected]>
  • Loading branch information
Jack12816 committed Mar 7, 2018
1 parent c22df35 commit 2b7d49b
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions spec/lib/billy/proxy_request_stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,31 @@
end

it 'should use a callable with pass_request' do
# Required due to the instance_exec implementation
subject.extend(RSpec::Matchers)

subject.and_return(proc do |*args|
response = pass_request(*args)
response[:body] = 'modified'
response[:code] = 205
response
end)

expect(subject.call('GET', @http_url, {}, {}, 'original')).to eql [
205,
'modified'
]
# Add the missing em-synchrony call which is done by
# ProxyConnection#handle_request instead.
EM.synchrony do
# Required due to the instance_exec implementation
subject.extend(RSpec::Matchers)

subject.and_return(proc do |*args|
response = pass_request(*args)
response[:body] = 'modified'
response[:code] = 205
response
end)

# The test server can't be used at this scenario due to the limitations
# of the Ruby GIL. We cannot use fibers (via eventmachine) and ask
# ourself on a different thread to serve a HTTP request. This results
# in +fiber called across threads (FiberError)+ errors. Unfortunately
# we have to ask an external resource.
url = 'http://google.com'

expect(subject.call('GET', url, {}, {}, 'original')).to eql [
205,
'modified'
]
end
end
end

Expand Down

0 comments on commit 2b7d49b

Please sign in to comment.