webmock 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/README.md +33 -8
- data/VERSION +1 -1
- data/lib/webmock/http_lib_adapters/em_http_request.rb +21 -14
- data/spec/em_http_request_spec_helper.rb +5 -1
- data/webmock.gemspec +3 -4
- metadata +3 -4
- data/spec/benchmark.rb +0 -61
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -22,20 +22,23 @@ Supported HTTP libraries
|
|
22
22
|
* Patron
|
23
23
|
* EM-HTTP-Request
|
24
24
|
|
25
|
-
Installation
|
26
|
-
------------
|
25
|
+
##Installation
|
27
26
|
|
28
27
|
gem install webmock --source http://gemcutter.org
|
29
28
|
|
30
|
-
|
29
|
+
### Test::Unit
|
31
30
|
|
32
|
-
|
31
|
+
Add the following code to `test/test_helper.rb`
|
32
|
+
|
33
|
+
require 'webmock/test_unit'
|
33
34
|
|
34
35
|
class Test::Unit::TestCase
|
35
|
-
include WebMock
|
36
|
+
config.include WebMock
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
+
### RSpec
|
40
|
+
|
41
|
+
Add the following code to `spec/spec_helper`:
|
39
42
|
|
40
43
|
require 'webmock/rspec'
|
41
44
|
|
@@ -43,11 +46,33 @@ or if you use RSpec add these lines to `spec/spec_helper`:
|
|
43
46
|
config.include WebMock
|
44
47
|
end
|
45
48
|
|
46
|
-
|
49
|
+
### RSpec 2
|
47
50
|
|
48
|
-
|
51
|
+
Add the following code to `spec/spec_helper`:
|
49
52
|
|
53
|
+
require 'webmock/rspec'
|
54
|
+
|
55
|
+
RSpec.configure do |config|
|
56
|
+
config.include WebMock
|
57
|
+
end
|
58
|
+
|
59
|
+
### Cucumber
|
60
|
+
|
61
|
+
Add the following code to `features/support/env.rb`
|
62
|
+
|
63
|
+
require 'webmock/rspec'
|
64
|
+
module WebMockWorld
|
65
|
+
include WebMock
|
66
|
+
include WebMock::Matchers
|
67
|
+
end
|
68
|
+
|
69
|
+
World(WebMockWorld)
|
70
|
+
|
71
|
+
You can also use WebMock outside a test framework:
|
72
|
+
|
73
|
+
require 'webmock'
|
50
74
|
include WebMock
|
75
|
+
include WebMock::Matchers
|
51
76
|
|
52
77
|
## Examples
|
53
78
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.2
|
@@ -18,13 +18,11 @@ if defined?(EventMachine::HttpRequest)
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
# def stream(&blk)
|
22
|
-
# blk.call(@response)
|
23
|
-
# end
|
24
|
-
|
25
21
|
def unbind
|
26
22
|
end
|
27
23
|
|
24
|
+
def close_connection
|
25
|
+
end
|
28
26
|
end
|
29
27
|
|
30
28
|
def send_request_with_webmock(&block)
|
@@ -72,22 +70,31 @@ if defined?(EventMachine::HttpRequest)
|
|
72
70
|
end
|
73
71
|
|
74
72
|
def build_request_signature
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
if @req
|
74
|
+
options = @req.options
|
75
|
+
method = @req.method
|
76
|
+
uri = @req.uri
|
77
|
+
else
|
78
|
+
options = @options
|
79
|
+
method = @method
|
80
|
+
uri = @uri
|
81
|
+
end
|
82
|
+
|
83
|
+
if options[:authorization] || options['authorization']
|
84
|
+
auth = (options[:authorization] || options['authorization'])
|
78
85
|
userinfo = auth.join(':')
|
79
86
|
userinfo = WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)
|
80
|
-
|
81
|
-
|
87
|
+
options.reject! {|k,v| k.to_s == 'authorization' } #we added it to url userinfo
|
88
|
+
uri.userinfo = userinfo
|
82
89
|
end
|
83
90
|
|
84
|
-
|
91
|
+
uri.query_values = (uri.query_values || {}).merge(options[:query]) if options[:query]
|
85
92
|
|
86
93
|
WebMock::RequestSignature.new(
|
87
|
-
|
88
|
-
|
89
|
-
:body => (
|
90
|
-
:headers => (
|
94
|
+
method.downcase.to_sym,
|
95
|
+
uri.to_s,
|
96
|
+
:body => (options[:body] || options['body']),
|
97
|
+
:headers => (options[:head] || options['head'])
|
91
98
|
)
|
92
99
|
end
|
93
100
|
|
@@ -18,7 +18,11 @@ module EMHttpRequestSpecHelper
|
|
18
18
|
'authorization' => [uri.user, uri.password],
|
19
19
|
:head => options[:headers]}, &block)
|
20
20
|
http.errback {
|
21
|
-
error = http.errors
|
21
|
+
error = if http.respond_to?(:errors)
|
22
|
+
http.errors
|
23
|
+
else
|
24
|
+
http.error
|
25
|
+
end
|
22
26
|
failed
|
23
27
|
}
|
24
28
|
http.callback {
|
data/webmock.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{webmock}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bartosz Blimke"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-23}
|
13
13
|
s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
|
14
14
|
s.email = %q{bartosz.blimke@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -92,8 +92,7 @@ Gem::Specification.new do |s|
|
|
92
92
|
s.rubygems_version = %q{1.3.6}
|
93
93
|
s.summary = %q{Library for stubbing HTTP requests in Ruby.}
|
94
94
|
s.test_files = [
|
95
|
-
"spec/
|
96
|
-
"spec/em_http_request_spec.rb",
|
95
|
+
"spec/em_http_request_spec.rb",
|
97
96
|
"spec/em_http_request_spec_helper.rb",
|
98
97
|
"spec/httpclient_spec.rb",
|
99
98
|
"spec/httpclient_spec_helper.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 1.3.
|
8
|
+
- 2
|
9
|
+
version: 1.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bartosz Blimke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-23 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -211,7 +211,6 @@ signing_key:
|
|
211
211
|
specification_version: 3
|
212
212
|
summary: Library for stubbing HTTP requests in Ruby.
|
213
213
|
test_files:
|
214
|
-
- spec/benchmark.rb
|
215
214
|
- spec/em_http_request_spec.rb
|
216
215
|
- spec/em_http_request_spec_helper.rb
|
217
216
|
- spec/httpclient_spec.rb
|
data/spec/benchmark.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# require 'rubygems'
|
2
|
-
require 'benchmark'
|
3
|
-
require 'net/http'
|
4
|
-
# require 'fakeweb'
|
5
|
-
require 'spec/spec_helper'
|
6
|
-
|
7
|
-
def http_request
|
8
|
-
res = Net::HTTP.get_response(URI.parse('http://example.com'))
|
9
|
-
raise "Body should be 'Hello'" unless res.body == 'Hello'
|
10
|
-
end
|
11
|
-
|
12
|
-
def fakeweb
|
13
|
-
FakeWeb.register_uri(:get, 'http://example.com', :body => 'Hello')
|
14
|
-
yield
|
15
|
-
ensure
|
16
|
-
FakeWeb.clean_registry
|
17
|
-
end
|
18
|
-
|
19
|
-
def webmock
|
20
|
-
WebMock.stub_request(:get, 'http://example.com').to_return(:body => 'Hello')
|
21
|
-
yield
|
22
|
-
ensure
|
23
|
-
WebMock.reset_webmock
|
24
|
-
end
|
25
|
-
|
26
|
-
def perform_benchmark(name)
|
27
|
-
puts "\n\nBenchmarking #{name}:"
|
28
|
-
Benchmark.benchmark do |b|
|
29
|
-
%w(webmock).each do |type|
|
30
|
-
b.report(type) do
|
31
|
-
# this is a bit convoluted, but we want to ensure that each benchmark runs without the other library loaded,
|
32
|
-
# so we fork off a sub-process before requiring the libraries.
|
33
|
-
Process.fork do
|
34
|
-
require type
|
35
|
-
yield type
|
36
|
-
end
|
37
|
-
Process.wait
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
n = 5000
|
44
|
-
perform_benchmark("Single setup/teardown") do |type|
|
45
|
-
send(type) { n.times { http_request } }
|
46
|
-
end
|
47
|
-
|
48
|
-
perform_benchmark("Setup/teardown for each http request") do |type|
|
49
|
-
n.times { send(type) { http_request } }
|
50
|
-
end
|
51
|
-
|
52
|
-
# Output on my machine:
|
53
|
-
#
|
54
|
-
# Benchmarking Single setup/teardown:
|
55
|
-
# webmock 0.000000 0.000000 18.830000 ( 19.350281)
|
56
|
-
# fakeweb 0.000000 0.000000 1.930000 ( 2.049569)
|
57
|
-
#
|
58
|
-
#
|
59
|
-
# Benchmarking Setup/teardown for each http request:
|
60
|
-
# webmock 0.000000 0.000000 21.350000 ( 21.795557)
|
61
|
-
# fakeweb 0.000000 0.000000 2.490000 ( 2.707574)
|