webstub 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/webstub/stub.rb +32 -1
- data/lib/webstub/uri.rb +20 -0
- data/lib/webstub/version.rb +1 -1
- data/spec/stub_spec.rb +24 -0
- data/spec/uri_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f498c840e10f87af4e242bf40649b85c6e5f554
|
4
|
+
data.tar.gz: 6f73bdb65fd0884065a5aa35a75b5196ebb3a326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89d90b6d50d6ead629cd3817d5ed730f61f33263bdab2db6bc5adc563cd7642bd464bc20c64d6affcf22f4f1a0489b2b2434e8ca1591a60fad1ed203906ed0a4
|
7
|
+
data.tar.gz: 6c7c9d832871faa3ad313c4606d18c12cdc8f8893465e189b97f0a4ea381af7ed356ef97efc45d9c3cf927f9aeaefa942c8300f92ce1e394e5fc42bab36ada34
|
data/README.md
CHANGED
data/lib/webstub/stub.rb
CHANGED
@@ -145,7 +145,38 @@ module WebStub
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def canonicalize_url(url)
|
148
|
-
url
|
148
|
+
scheme, authority, hostname, port, path, query, fragment = URI.split(url)
|
149
|
+
|
150
|
+
parts = scheme.downcase
|
151
|
+
parts << "://"
|
152
|
+
|
153
|
+
if authority
|
154
|
+
parts << authority
|
155
|
+
parts << "@"
|
156
|
+
end
|
157
|
+
|
158
|
+
parts << hostname.downcase
|
159
|
+
|
160
|
+
if port
|
161
|
+
well_known_ports = { "http" => 80, "https" => 443 }
|
162
|
+
if well_known_ports[scheme] != port
|
163
|
+
parts << ":#{port}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
if path != "/"
|
168
|
+
parts << path
|
169
|
+
end
|
170
|
+
|
171
|
+
if query
|
172
|
+
parts << "?#{query}"
|
173
|
+
end
|
174
|
+
|
175
|
+
if fragment
|
176
|
+
parts << "##{fragment}"
|
177
|
+
end
|
178
|
+
|
179
|
+
parts
|
149
180
|
end
|
150
181
|
end
|
151
182
|
end
|
data/lib/webstub/uri.rb
CHANGED
@@ -12,5 +12,25 @@ module WebStub
|
|
12
12
|
def self.decode_www_form_component(str)
|
13
13
|
str.gsub("+", " ").stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
|
14
14
|
end
|
15
|
+
|
16
|
+
def self.split(str)
|
17
|
+
url = NSURL.URLWithString(str)
|
18
|
+
|
19
|
+
scheme = url.scheme
|
20
|
+
user = url.user
|
21
|
+
password = url.password
|
22
|
+
hostname = url.host
|
23
|
+
port = url.port
|
24
|
+
path = url.path
|
25
|
+
query = url.query
|
26
|
+
fragment = url.fragment
|
27
|
+
|
28
|
+
user_info = nil
|
29
|
+
if user || password
|
30
|
+
user_info = "#{user}:#{password}"
|
31
|
+
end
|
32
|
+
|
33
|
+
[scheme, user_info, hostname, port, path, query, fragment]
|
34
|
+
end
|
15
35
|
end
|
16
36
|
end
|
data/lib/webstub/version.rb
CHANGED
data/spec/stub_spec.rb
CHANGED
@@ -50,6 +50,30 @@ describe WebStub::Stub do
|
|
50
50
|
@stub.matches?(:post, "http://www.yahoo.com/").should.be.false
|
51
51
|
end
|
52
52
|
|
53
|
+
describe "canonicalizing URLs" do
|
54
|
+
it "lowercases the scheme" do
|
55
|
+
@stub.matches?(:get, "HTTP://www.yahoo.com/").should.be.true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "lowercases the hostname" do
|
59
|
+
@stub.matches?(:get, "http://WWW.YAHOo.COM/").should.be.true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "ignores default HTTP port" do
|
63
|
+
@stub.matches?(:get, "http://www.yahoo.com:80/").should.be.true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "ignores default HTTPS port" do
|
67
|
+
stub = WebStub::Stub.new(:get, "https://www.yahoo.com/")
|
68
|
+
|
69
|
+
stub.matches?(:get, "https://www.yahoo.com:443/").should.be.true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "ignores a path with \"/\"" do
|
73
|
+
@stub.matches?(:get, "http://www.yahoo.com:80/").should.be.true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
53
77
|
describe "body" do
|
54
78
|
describe "with a dictionary" do
|
55
79
|
before do
|
data/spec/uri_spec.rb
CHANGED
@@ -13,4 +13,19 @@ describe WebStub::URI do
|
|
13
13
|
WebStub::URI.decode_www_form("a=42&b=hello").should == WebStub::URI.decode_www_form("b=hello&a=42")
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
describe ".split" do
|
18
|
+
it "splits a URL into its constituent parts" do
|
19
|
+
parts = WebStub::URI.split("http://user:password@hostname:9000/path/to/file?query=true#fragment")
|
20
|
+
|
21
|
+
parts.should ==
|
22
|
+
["http", "user:password", "hostname", 9000, "/path/to/file", "query=true", "fragment"]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns nil for elements not present" do
|
26
|
+
parts = WebStub::URI.split("http://www.yahoo.com")
|
27
|
+
|
28
|
+
parts.should == ["http", nil, "www.yahoo.com", nil, "", nil, nil]
|
29
|
+
end
|
30
|
+
end
|
16
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|