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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83ff338cdc8626be04a4ca16d8a72f4fa015e5ae
4
- data.tar.gz: 32edcc1fb2dc10c867ce83ad0c8bfbd4860959dd
3
+ metadata.gz: 9f498c840e10f87af4e242bf40649b85c6e5f554
4
+ data.tar.gz: 6f73bdb65fd0884065a5aa35a75b5196ebb3a326
5
5
  SHA512:
6
- metadata.gz: f94be75dca1cacf1f27d03282ab04f98f791bc8f7e3ec6e4080a759914169a3b73ed4d9a83c4ad01ae5a71d6fec3152ae371c3c9f246c60034f9da5a8720a7fd
7
- data.tar.gz: 28b5ea6be60a257bfb17a3e517dde84b2fb9a231eb4e245dd200fd5be0d5e17f9d99d2bc2dd0e91bcb36a34b122b5c54d103f98f0fa7c5dab65ed2b315ca8ba9
6
+ metadata.gz: 89d90b6d50d6ead629cd3817d5ed730f61f33263bdab2db6bc5adc563cd7642bd464bc20c64d6affcf22f4f1a0489b2b2434e8ca1591a60fad1ed203906ed0a4
7
+ data.tar.gz: 6c7c9d832871faa3ad313c4606d18c12cdc8f8893465e189b97f0a4ea381af7ed356ef97efc45d9c3cf927f9aeaefa942c8300f92ce1e394e5fc42bab36ada34
data/README.md CHANGED
@@ -152,5 +152,4 @@ end
152
152
  TODO
153
153
  ---------
154
154
  * Handle query params similarly to form data
155
- * URI canonicalization
156
155
 
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
@@ -1,3 +1,3 @@
1
1
  module WebStub
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
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.0
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-06-27 00:00:00.000000000 Z
11
+ date: 2013-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake