Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored the code that figures out the request uri into its own met…

…hod that can be called on its own.
  • Loading branch information...
commit 60eab99469d6c036458807eaf7764b658fd341a2 1 parent acc404b
@myronmarston authored
Showing with 12 additions and 1 deletion.
  1. +5 −1 lib/fake_web/ext/net_http.rb
  2. +7 −0 test/test_fake_web.rb
View
6 lib/fake_web/ext/net_http.rb
@@ -35,7 +35,7 @@ def socket_type_with_fakeweb
alias_method :socket_type, :socket_type_with_fakeweb
end
- def request_with_fakeweb(request, body = nil, &block)
+ def request_uri(request)
protocol = use_ssl? ? "https" : "http"
path = request.path
@@ -49,6 +49,10 @@ def request_with_fakeweb(request, body = nil, &block)
end
uri = "#{protocol}://#{userinfo}#{self.address}:#{self.port}#{path}"
+ end
+
+ def request_with_fakeweb(request, body = nil, &block)
+ uri = request_uri(request)
method = request.method.downcase.to_sym
if FakeWeb.registered_uri?(method, uri)
View
7 test/test_fake_web.rb
@@ -323,6 +323,13 @@ def test_register_unimplemented_response
end
end
+ def test_request_uri
+ uri = URI.parse('http://www.example.com/index.html')
+ http = Net::HTTP.new(uri.host, uri.port)
+ request = Net::HTTP::Get.new(uri.path)
+ assert_equal 'http://www.example.com:80/index.html', http.request_uri(request)
+ end
+
def test_real_http_request
FakeWeb.allow_net_connect = true
setup_expectations_for_real_apple_hot_news_request
Please sign in to comment.
Something went wrong with that request. Please try again.