webmock-net-http-pipeline 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 397983d8f69cd968e08f3ce2656502d535efe32e
4
+ data.tar.gz: 73e9b87762c31b999c59532fddd8dfa4bf004852
5
+ SHA512:
6
+ metadata.gz: ddad97f62dd128f21c63ea22908eb3a48c6ceb4454a1bf1ee60ddc5b8e8e88920b1e1312be739923473648acbd84d7de072001b4bf70966576795b3a5e29e858
7
+ data.tar.gz: a3b9890f8752df0d882cbfe04485d5f24659cc1c36a0f3a5d7718ae085b7621f2e51a6aa1b69597ec79ba025e84416642b27d9e568539b30c2176128aeb194bf
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Global Personals Ltd.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # WebMock + Net::HTTP::Pipeline
2
+
3
+ Use WebMock to test your use of pipelined HTTP requests.
4
+
5
+ [WebMock][webmock] is a great tool for stubbing HTTP requests in tests.
6
+ [net-http-pipeline][nhp] is an HTTP/1.1 pipelining implementation build on top
7
+ of Net::HTTP, used for making batches of HTTP calls more efficient. The only
8
+ problem is that the two don't play well together: net-http-pipeline bypasses
9
+ the hooks that WebMock sets in place to provide its behaviour.
10
+
11
+ This library mimics the -pipeline behaviour within WebMock's version of
12
+ `Net::HTTP#request` to allow you to test your pipelined HTTP calls.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application"s Gemfile:
17
+
18
+ ```ruby
19
+ gem "webmock-net-http-pipeline"
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```bash
31
+ $ gem install webmock-net-http-pipeline
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Simply `require` this gem after requiring `webmock`, and start mocking and
37
+ testing your pipelined requests.
38
+
39
+
40
+ ```ruby
41
+ require "webmock"
42
+ require "webmock/net/http/pipeline"
43
+
44
+ include WebMock::API
45
+
46
+ host = "www.example.com"
47
+ stub_request(:any, host)
48
+
49
+ http = Net::HTTP.start(host, 80).tap { |http| http.pipelining = true }
50
+ requests = (1..3).map { Net::HTTP::Get.new("/") }
51
+ responses = http.pipeline(requests)
52
+
53
+ p responses #=> [#<Net::HTTPOK 200 readbody=true>, ...]
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it: http://github.com/globaldev/webmock-net-http-pipeline/fork
59
+ 2. Create your feature branch: `git checkout -b my-new-feature`
60
+ 3. Commit your changes: `git commit -am "Add some feature"`
61
+ 4. Push to the branch: `git push origin my-new-feature`
62
+ 5. Create new Pull Request
63
+
64
+ [webmock]: https://github.com/bblimke/webmock
65
+ [nhp]: https://github.com/drbrain/net-http-pipeline
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ require "webmock/net/http/pipeline/version"
2
+ require "webmock"
3
+
4
+ module WebMock
5
+ module NetHTTPPipeline
6
+
7
+ def pipeline(requests)
8
+ responses = []
9
+ requests.reject! do |req|
10
+ response = request(req)
11
+ yield response if block_given?
12
+ responses << response
13
+ end
14
+ responses
15
+ end
16
+
17
+ # Not actually used, but keeps the interface consistent with -pipeline
18
+ attr_accessor :pipelining
19
+
20
+ end
21
+ end
22
+
23
+ WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP).class_eval do
24
+ include WebMock::NetHTTPPipeline
25
+ end
@@ -0,0 +1,5 @@
1
+ module WebMock
2
+ module NetHTTPPipeline
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,71 @@
1
+ require "minitest/autorun"
2
+ require "webmock/net/http/pipeline"
3
+
4
+ class TestPipeliningBehaviour < MiniTest::Unit::TestCase
5
+
6
+ class MockedResponse < Struct.new(:request); end
7
+ class MockedClient
8
+ include WebMock::NetHTTPPipeline
9
+ def request(req)
10
+ MockedResponse.new(req)
11
+ end
12
+ end
13
+
14
+ def setup
15
+ @client = MockedClient.new
16
+ end
17
+
18
+ def test_pipelines_zero_requests
19
+ assert_empty @client.pipeline([])
20
+ end
21
+
22
+ def test_pipelines_one_request
23
+ requests = [:one]
24
+ responses = @client.pipeline(requests.dup)
25
+ assert_equal 1, responses.length
26
+ assert_same requests.first, responses.first.request
27
+ end
28
+
29
+ def test_pipelines_multiple_requests
30
+ requests = [:one, :two, :three]
31
+ responses = @client.pipeline(requests.dup)
32
+ responses.each { |res| assert_includes requests, res.request }
33
+ end
34
+
35
+ def test_returns_responses_in_order
36
+ requests = [:one, :two, :three]
37
+ responses = @client.pipeline(requests.dup)
38
+ assert requests == responses.map { |r| r.request }
39
+ end
40
+
41
+ def test_removes_successfully_pipelined_requests
42
+ requests = [:one, :two, :three]
43
+ assert_equal 3, @client.pipeline(requests).size
44
+ assert_empty requests
45
+ end
46
+
47
+ def test_yields_each_response_if_block_given
48
+ requests, responses = [:one, :two, :three], []
49
+ @client.pipeline(requests.dup) { |res| responses << res.request }
50
+ assert requests == responses
51
+ end
52
+ end
53
+
54
+ class TestWebMockInclusion < MiniTest::Unit::TestCase
55
+ def setup
56
+ klass = WebMock::HttpLibAdapters::NetHttpAdapter
57
+ @client = klass.instance_variable_get(:@webMockNetHTTP).new(nil)
58
+ end
59
+
60
+ def test_net_http_adapter_responds_to_pipeline
61
+ assert_respond_to @client, :pipeline
62
+ end
63
+
64
+ def test_net_http_adapter_responds_to_pipelining
65
+ assert_respond_to @client, :pipelining
66
+ end
67
+
68
+ def test_net_http_adapter_responds_to_pipelining=
69
+ assert_respond_to @client, :pipelining=
70
+ end
71
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webmock/net/http/pipeline/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webmock-net-http-pipeline"
8
+ spec.version = WebMock::NetHTTPPipeline::VERSION
9
+ spec.authors = ["Tim Blair", "Mat Sadler"]
10
+ spec.email = ["tim@bla.ir", "mat@sourcetagsandcodes.com"]
11
+ spec.summary = %q{Use WebMock to test your use of pipelined HTTP requests.}
12
+ spec.description = %q{Mimics net-http-pipeline's behaviour within WebMock's Net::HTTP implementation, allowing you to mock and test your pipelined HTTP calls.}
13
+ spec.homepage = "http://github.com/globaldev/webmock-net-http-pipeline"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "webmock", "~> 1.7"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webmock-net-http-pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Blair
8
+ - Mat Sadler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: webmock
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Mimics net-http-pipeline's behaviour within WebMock's Net::HTTP implementation,
71
+ allowing you to mock and test your pipelined HTTP calls.
72
+ email:
73
+ - tim@bla.ir
74
+ - mat@sourcetagsandcodes.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/webmock/net/http/pipeline.rb
85
+ - lib/webmock/net/http/pipeline/version.rb
86
+ - test/test_webmock_net_http_pipeline.rb
87
+ - webmock-net-http-pipeline.gemspec
88
+ homepage: http://github.com/globaldev/webmock-net-http-pipeline
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.1.11
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Use WebMock to test your use of pipelined HTTP requests.
112
+ test_files:
113
+ - test/test_webmock_net_http_pipeline.rb