diff options
author | Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp> | 2018-03-24 20:49:54 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-03-24 12:49:54 +0100 |
commit | 54b273bf993888cd079113dd588cb7a90228b93b (patch) | |
tree | d6437a702618c9108ffad35a540a222a053b2c7d /spec | |
parent | 4e71b104e6d5f02069120c7a56b26888c6f0fef5 (diff) |
Close http connection in perform method of Request class (#6889)
HTTP connections must be explicitly closed in many cases, and letting perform method close connections makes its callers less redundant and prevent them from forgetting to close connections.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/request_spec.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb index 5da357c55..4d6b20dd5 100644 --- a/spec/lib/request_spec.rb +++ b/spec/lib/request_spec.rb @@ -39,12 +39,10 @@ describe Request do describe '#perform' do context 'with valid host' do - before do - stub_request(:get, 'http://example.com') - subject.perform - end + before { stub_request(:get, 'http://example.com') } it 'executes a HTTP request' do + expect { |block| subject.perform &block }.to yield_control expect(a_request(:get, 'http://example.com')).to have_been_made.once end @@ -52,12 +50,20 @@ describe Request do allow(Addrinfo).to receive(:foreach).with('example.com', nil, nil, :SOCK_STREAM) .and_yield(Addrinfo.new(["AF_INET", 0, "example.com", "0.0.0.0"], :PF_INET, :SOCK_STREAM)) .and_yield(Addrinfo.new(["AF_INET6", 0, "example.com", "2001:4860:4860::8844"], :PF_INET6, :SOCK_STREAM)) + + expect { |block| subject.perform &block }.to yield_control expect(a_request(:get, 'http://example.com')).to have_been_made.once end it 'sets headers' do + expect { |block| subject.perform &block }.to yield_control expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made end + + it 'closes underlaying connection' do + expect_any_instance_of(HTTP::Client).to receive(:close) + expect { |block| subject.perform &block }.to yield_control + end end context 'with private host' do |