webmock 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/README.md +169 -76
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/webmock.rb +12 -9
- data/lib/webmock/adapters/rspec.rb +20 -22
- data/lib/webmock/adapters/rspec/matchers.rb +4 -4
- data/lib/webmock/adapters/rspec/webmock_matcher.rb +2 -2
- data/lib/webmock/adapters/test_unit.rb +20 -21
- data/lib/webmock/http_lib_adapters/net_http.rb +51 -15
- data/lib/webmock/request_profile.rb +5 -44
- data/lib/webmock/request_registry.rb +10 -11
- data/lib/webmock/request_signature.rb +44 -0
- data/lib/webmock/request_stub.rb +3 -3
- data/lib/webmock/response.rb +1 -1
- data/lib/webmock/rspec.rb +1 -0
- data/lib/webmock/test_unit.rb +1 -0
- data/lib/webmock/util/hash_counter.rb +16 -8
- data/lib/webmock/util/headers.rb +23 -0
- data/lib/webmock/util/uri.rb +81 -0
- data/lib/webmock/webmock.rb +16 -19
- data/spec/net_http_spec.rb +10 -9
- data/spec/other_net_http_libs_spec.rb +3 -1
- data/spec/request_profile_spec.rb +6 -116
- data/spec/request_registry_spec.rb +12 -17
- data/spec/request_signature_spec.rb +155 -0
- data/spec/request_stub_spec.rb +2 -2
- data/spec/response_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -1
- data/spec/util/hash_counter_spec.rb +4 -4
- data/spec/util/headers_spec.rb +11 -0
- data/spec/util/uri_spec.rb +213 -0
- data/spec/vendor/addressable/lib/addressable/uri.rb +8 -0
- data/spec/vendor/addressable/lib/uri.rb +0 -0
- data/spec/webmock_spec.rb +58 -10
- data/test/test_helper.rb +5 -1
- data/test/test_webmock.rb +11 -6
- data/webmock.gemspec +21 -6
- metadata +28 -6
- data/lib/webmock/url.rb +0 -46
- data/lib/webmock/utility.rb +0 -65
- data/spec/utility_spec.rb +0 -70
data/test/test_webmock.rb
CHANGED
@@ -4,13 +4,18 @@ require 'ostruct'
|
|
4
4
|
|
5
5
|
class TestWebMock < Test::Unit::TestCase
|
6
6
|
|
7
|
-
def http_request(method,
|
8
|
-
|
7
|
+
def http_request(method, uri, options = {})
|
8
|
+
begin
|
9
|
+
uri = URI.parse(uri)
|
10
|
+
rescue
|
11
|
+
uri = Addressable::URI.heuristic_parse(uri)
|
12
|
+
end
|
9
13
|
response = nil
|
10
14
|
clazz = Net::HTTP.const_get("#{method.to_s.capitalize}")
|
11
|
-
req = clazz.new(
|
12
|
-
|
13
|
-
http
|
15
|
+
req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", options[:headers])
|
16
|
+
req.basic_auth uri.user, uri.password if uri.user
|
17
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
http.use_ssl = true if uri.scheme == "https"
|
14
19
|
response = http.start {|http|
|
15
20
|
http.request(req, options[:body])
|
16
21
|
}
|
@@ -18,7 +23,7 @@ class TestWebMock < Test::Unit::TestCase
|
|
18
23
|
:body => response.body,
|
19
24
|
:headers => response,
|
20
25
|
:status => response.code })
|
21
|
-
end
|
26
|
+
end
|
22
27
|
|
23
28
|
|
24
29
|
def setup
|
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 = "0.7.
|
8
|
+
s.version = "0.7.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{2009-11-
|
12
|
+
s.date = %q{2009-11-24}
|
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 = [
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".gitignore",
|
21
|
+
"CHANGELOG",
|
21
22
|
"LICENSE",
|
22
23
|
"README.md",
|
23
24
|
"Rakefile",
|
@@ -34,23 +35,30 @@ Gem::Specification.new do |s|
|
|
34
35
|
"lib/webmock/request_execution_verifier.rb",
|
35
36
|
"lib/webmock/request_profile.rb",
|
36
37
|
"lib/webmock/request_registry.rb",
|
38
|
+
"lib/webmock/request_signature.rb",
|
37
39
|
"lib/webmock/request_stub.rb",
|
38
40
|
"lib/webmock/response.rb",
|
39
|
-
"lib/webmock/
|
41
|
+
"lib/webmock/rspec.rb",
|
42
|
+
"lib/webmock/test_unit.rb",
|
40
43
|
"lib/webmock/util/hash_counter.rb",
|
41
|
-
"lib/webmock/
|
44
|
+
"lib/webmock/util/headers.rb",
|
45
|
+
"lib/webmock/util/uri.rb",
|
42
46
|
"lib/webmock/webmock.rb",
|
43
47
|
"spec/net_http_spec.rb",
|
44
48
|
"spec/other_net_http_libs_spec.rb",
|
45
49
|
"spec/request_execution_verifier_spec.rb",
|
46
50
|
"spec/request_profile_spec.rb",
|
47
51
|
"spec/request_registry_spec.rb",
|
52
|
+
"spec/request_signature_spec.rb",
|
48
53
|
"spec/request_stub_spec.rb",
|
49
54
|
"spec/response_spec.rb",
|
50
55
|
"spec/spec.opts",
|
51
56
|
"spec/spec_helper.rb",
|
52
57
|
"spec/util/hash_counter_spec.rb",
|
53
|
-
"spec/
|
58
|
+
"spec/util/headers_spec.rb",
|
59
|
+
"spec/util/uri_spec.rb",
|
60
|
+
"spec/vendor/addressable/lib/addressable/uri.rb",
|
61
|
+
"spec/vendor/addressable/lib/uri.rb",
|
54
62
|
"spec/vendor/right_http_connection-1.2.4/History.txt",
|
55
63
|
"spec/vendor/right_http_connection-1.2.4/Manifest.txt",
|
56
64
|
"spec/vendor/right_http_connection-1.2.4/README.txt",
|
@@ -88,11 +96,15 @@ Gem::Specification.new do |s|
|
|
88
96
|
"spec/request_execution_verifier_spec.rb",
|
89
97
|
"spec/request_profile_spec.rb",
|
90
98
|
"spec/request_registry_spec.rb",
|
99
|
+
"spec/request_signature_spec.rb",
|
91
100
|
"spec/request_stub_spec.rb",
|
92
101
|
"spec/response_spec.rb",
|
93
102
|
"spec/spec_helper.rb",
|
94
103
|
"spec/util/hash_counter_spec.rb",
|
95
|
-
"spec/
|
104
|
+
"spec/util/headers_spec.rb",
|
105
|
+
"spec/util/uri_spec.rb",
|
106
|
+
"spec/vendor/addressable/lib/addressable/uri.rb",
|
107
|
+
"spec/vendor/addressable/lib/uri.rb",
|
96
108
|
"spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb",
|
97
109
|
"spec/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb",
|
98
110
|
"spec/vendor/right_http_connection-1.2.4/setup.rb",
|
@@ -113,11 +125,14 @@ Gem::Specification.new do |s|
|
|
113
125
|
s.specification_version = 3
|
114
126
|
|
115
127
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
128
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
|
116
129
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
117
130
|
else
|
131
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
118
132
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
119
133
|
end
|
120
134
|
else
|
135
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
121
136
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
122
137
|
end
|
123
138
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
@@ -9,9 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: addressable
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.1
|
24
|
+
version:
|
15
25
|
- !ruby/object:Gem::Dependency
|
16
26
|
name: rspec
|
17
27
|
type: :development
|
@@ -33,6 +43,7 @@ extra_rdoc_files:
|
|
33
43
|
- README.md
|
34
44
|
files:
|
35
45
|
- .gitignore
|
46
|
+
- CHANGELOG
|
36
47
|
- LICENSE
|
37
48
|
- README.md
|
38
49
|
- Rakefile
|
@@ -49,23 +60,30 @@ files:
|
|
49
60
|
- lib/webmock/request_execution_verifier.rb
|
50
61
|
- lib/webmock/request_profile.rb
|
51
62
|
- lib/webmock/request_registry.rb
|
63
|
+
- lib/webmock/request_signature.rb
|
52
64
|
- lib/webmock/request_stub.rb
|
53
65
|
- lib/webmock/response.rb
|
54
|
-
- lib/webmock/
|
66
|
+
- lib/webmock/rspec.rb
|
67
|
+
- lib/webmock/test_unit.rb
|
55
68
|
- lib/webmock/util/hash_counter.rb
|
56
|
-
- lib/webmock/
|
69
|
+
- lib/webmock/util/headers.rb
|
70
|
+
- lib/webmock/util/uri.rb
|
57
71
|
- lib/webmock/webmock.rb
|
58
72
|
- spec/net_http_spec.rb
|
59
73
|
- spec/other_net_http_libs_spec.rb
|
60
74
|
- spec/request_execution_verifier_spec.rb
|
61
75
|
- spec/request_profile_spec.rb
|
62
76
|
- spec/request_registry_spec.rb
|
77
|
+
- spec/request_signature_spec.rb
|
63
78
|
- spec/request_stub_spec.rb
|
64
79
|
- spec/response_spec.rb
|
65
80
|
- spec/spec.opts
|
66
81
|
- spec/spec_helper.rb
|
67
82
|
- spec/util/hash_counter_spec.rb
|
68
|
-
- spec/
|
83
|
+
- spec/util/headers_spec.rb
|
84
|
+
- spec/util/uri_spec.rb
|
85
|
+
- spec/vendor/addressable/lib/addressable/uri.rb
|
86
|
+
- spec/vendor/addressable/lib/uri.rb
|
69
87
|
- spec/vendor/right_http_connection-1.2.4/History.txt
|
70
88
|
- spec/vendor/right_http_connection-1.2.4/Manifest.txt
|
71
89
|
- spec/vendor/right_http_connection-1.2.4/README.txt
|
@@ -125,11 +143,15 @@ test_files:
|
|
125
143
|
- spec/request_execution_verifier_spec.rb
|
126
144
|
- spec/request_profile_spec.rb
|
127
145
|
- spec/request_registry_spec.rb
|
146
|
+
- spec/request_signature_spec.rb
|
128
147
|
- spec/request_stub_spec.rb
|
129
148
|
- spec/response_spec.rb
|
130
149
|
- spec/spec_helper.rb
|
131
150
|
- spec/util/hash_counter_spec.rb
|
132
|
-
- spec/
|
151
|
+
- spec/util/headers_spec.rb
|
152
|
+
- spec/util/uri_spec.rb
|
153
|
+
- spec/vendor/addressable/lib/addressable/uri.rb
|
154
|
+
- spec/vendor/addressable/lib/uri.rb
|
133
155
|
- spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb
|
134
156
|
- spec/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb
|
135
157
|
- spec/vendor/right_http_connection-1.2.4/setup.rb
|
data/lib/webmock/url.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module WebMock
|
2
|
-
|
3
|
-
class URL
|
4
|
-
|
5
|
-
def self.normalize_uri(uri)
|
6
|
-
return uri if uri.is_a?(Regexp)
|
7
|
-
normalized_uri =
|
8
|
-
case uri
|
9
|
-
when URI then uri
|
10
|
-
when String
|
11
|
-
uri = 'http://' + uri unless uri.match('^https?://')
|
12
|
-
URI.parse(uri)
|
13
|
-
end
|
14
|
-
normalized_uri.query = sort_query_params(normalized_uri.query)
|
15
|
-
normalized_uri.normalize
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.variations_of_uri_as_strings(uri_object)
|
19
|
-
normalized_uri = normalize_uri(uri_object.dup)
|
20
|
-
normalized_uri_string = normalized_uri.to_s
|
21
|
-
|
22
|
-
variations = [normalized_uri_string]
|
23
|
-
|
24
|
-
# if the port is implied in the original, add a copy with an explicit port
|
25
|
-
if normalized_uri.default_port == normalized_uri.port
|
26
|
-
variations << normalized_uri_string.sub(
|
27
|
-
/#{Regexp.escape(normalized_uri.request_uri)}$/,
|
28
|
-
":#{normalized_uri.port}#{normalized_uri.request_uri}")
|
29
|
-
end
|
30
|
-
|
31
|
-
variations
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def self.sort_query_params(query)
|
37
|
-
if query.nil? || query.empty?
|
38
|
-
nil
|
39
|
-
else
|
40
|
-
query.split('&').sort.join('&')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/lib/webmock/utility.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
#This file is taken from FakeWeb (fakeweb.rubyforge.org/) and adopted
|
2
|
-
|
3
|
-
module WebMock
|
4
|
-
module Utility #:nodoc:
|
5
|
-
|
6
|
-
def self.decode_userinfo_from_header(header)
|
7
|
-
header.sub(/^Basic /, "").unpack("m").first
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.encode_unsafe_chars_in_userinfo(userinfo)
|
11
|
-
unsafe_in_userinfo = /[^#{URI::REGEXP::PATTERN::UNRESERVED};&=+$,]|^(#{URI::REGEXP::PATTERN::ESCAPED})/
|
12
|
-
userinfo.split(":").map { |part| URI.escape(part, unsafe_in_userinfo) }.join(":")
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.strip_default_port_from_uri(uri)
|
16
|
-
case uri
|
17
|
-
when %r{^http://} then uri.sub(%r{:80(/|$)}, '\1')
|
18
|
-
when %r{^https://} then uri.sub(%r{:443(/|$)}, '\1')
|
19
|
-
else uri
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.puts_warning_for_net_http_around_advice_libs_if_needed
|
24
|
-
libs = {"Samuel" => defined?(Samuel)}
|
25
|
-
warnings = libs.select { |_, loaded| loaded }.map do |name, _|
|
26
|
-
<<-TEXT.gsub(/ {10}/, '')
|
27
|
-
\e[1mWarning: WebMock was loaded after #{name}\e[0m
|
28
|
-
* #{name}'s code is being ignored when a request is handled by WebMock,
|
29
|
-
because both libraries work by patching Net::HTTP.
|
30
|
-
* To fix this, just reorder your requires so that WebMock is before #{name}.
|
31
|
-
TEXT
|
32
|
-
end
|
33
|
-
$stderr.puts "\n" + warnings.join("\n") + "\n" if warnings.any?
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.record_loaded_net_http_replacement_libs
|
37
|
-
libs = {"RightHttpConnection" => defined?(RightHttpConnection)}
|
38
|
-
@loaded_net_http_replacement_libs = libs.map { |name, loaded| name if loaded }.compact
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.puts_warning_for_net_http_replacement_libs_if_needed
|
42
|
-
libs = {"RightHttpConnection" => defined?(RightHttpConnection)}
|
43
|
-
warnings = libs.select { |_, loaded| loaded }.
|
44
|
-
reject { |name, _| @loaded_net_http_replacement_libs.include?(name) }.
|
45
|
-
map do |name, _|
|
46
|
-
<<-TEXT.gsub(/ {10}/, '')
|
47
|
-
\e[1mWarning: #{name} was loaded after WebMock\e[0m
|
48
|
-
* WebMock's code is being ignored, because #{name} replaces parts of
|
49
|
-
Net::HTTP without deferring to other libraries. This will break Net::HTTP requests.
|
50
|
-
* To fix this, just reorder your requires so that #{name} is before WebMock.
|
51
|
-
TEXT
|
52
|
-
end
|
53
|
-
$stderr.puts "\n" + warnings.join("\n") + "\n" if warnings.any?
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.normalize_headers(headers)
|
57
|
-
return nil unless headers
|
58
|
-
array = headers.map { |name, value|
|
59
|
-
[name.to_s.split(/_|-/).map { |segment| segment.capitalize }.join("-"), value.to_s]
|
60
|
-
}
|
61
|
-
Hash[*array.flatten]
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
data/spec/utility_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Utility do
|
4
|
-
|
5
|
-
it "should decode_userinfo_from_header handles basic auth" do
|
6
|
-
authorization_header = "Basic dXNlcm5hbWU6c2VjcmV0"
|
7
|
-
userinfo = Utility.decode_userinfo_from_header(authorization_header)
|
8
|
-
userinfo.should == "username:secret"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should encode unsafe chars in userinfo does not encode userinfo safe punctuation" do
|
12
|
-
userinfo = "user;&=+$,:secret"
|
13
|
-
userinfo.should == Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should encode unsafe chars in userinfo does not encode rfc 3986 unreserved characters" do
|
17
|
-
userinfo = "-.!~*'()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:secret"
|
18
|
-
userinfo.should == Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should encode unsafe chars in userinfo does encode other characters" do
|
22
|
-
userinfo, safe_userinfo = 'us#rn@me:sec//ret?"', 'us%23rn%40me:sec%2F%2Fret%3F%22'
|
23
|
-
safe_userinfo.should == Utility.encode_unsafe_chars_in_userinfo(userinfo)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should strip_default_port_from_uri strips 80 from http with path" do
|
27
|
-
uri = "http://example.com:80/foo/bar"
|
28
|
-
stripped_uri = Utility.strip_default_port_from_uri(uri)
|
29
|
-
stripped_uri.should == "http://example.com/foo/bar"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should strip_default_port_from_uri strips 80 from http without path" do
|
33
|
-
uri = "http://example.com:80"
|
34
|
-
stripped_uri = Utility.strip_default_port_from_uri(uri)
|
35
|
-
stripped_uri.should == "http://example.com"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should strip_default_port_from_uri strips 443 from https without path" do
|
39
|
-
uri = "https://example.com:443"
|
40
|
-
stripped_uri = Utility.strip_default_port_from_uri(uri)
|
41
|
-
stripped_uri.should == "https://example.com"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should strip_default_port_from_uri strips 443 from https" do
|
45
|
-
uri = "https://example.com:443/foo/bar"
|
46
|
-
stripped_uri = Utility.strip_default_port_from_uri(uri)
|
47
|
-
stripped_uri.should == "https://example.com/foo/bar"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should strip_default_port_from_uri does not strip 8080 from http" do
|
51
|
-
uri = "http://example.com:8080/foo/bar"
|
52
|
-
uri.should == Utility.strip_default_port_from_uri(uri)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should strip_default_port_from_uri does not strip 443 from http" do
|
56
|
-
uri = "http://example.com:443/foo/bar"
|
57
|
-
uri.should == Utility.strip_default_port_from_uri(uri)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should strip_default_port_from_uri does not strip 80 from query string" do
|
61
|
-
uri = "http://example.com/?a=:80&b=c"
|
62
|
-
uri.should == Utility.strip_default_port_from_uri(uri)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should strip_default_port_from_uri does not modify strings that do not start with http or https" do
|
66
|
-
uri = "httpz://example.com:80/"
|
67
|
-
uri.should == Utility.strip_default_port_from_uri(uri)
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|