chrisk-fakeweb 1.1.2.6 → 1.1.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,3 @@
1
- # FakeWeb - Ruby Helper for Faking Web Requests
2
- # Copyright 2006 Blaine Cook <romeda@gmail.com>.
3
- #
4
- # FakeWeb is free software; you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation; either version 2 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # FakeWeb is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with FakeWeb; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
1
  require 'net/http'
19
2
  require 'net/https'
20
3
  require 'stringio'
@@ -37,7 +20,6 @@ module Net #:nodoc: all
37
20
  end
38
21
  end
39
22
 
40
-
41
23
  class HTTP
42
24
  def self.socket_type
43
25
  FakeWeb::SocketDelegator
@@ -47,22 +29,23 @@ module Net #:nodoc: all
47
29
  alias :original_net_http_connect :connect
48
30
 
49
31
  def request(request, body = nil, &block)
50
- protocol = use_ssl ? "https" : "http"
32
+ protocol = use_ssl? ? "https" : "http"
51
33
 
52
34
  path = request.path
53
35
  path = URI.parse(request.path).request_uri if request.path =~ /^http/
54
36
 
55
37
  uri = "#{protocol}://#{self.address}:#{self.port}#{path}"
38
+ method = request.method.downcase.to_sym
56
39
 
57
- if FakeWeb.registered_uri?(uri)
40
+ if FakeWeb.registered_uri?(method, uri)
58
41
  @socket = Net::HTTP.socket_type.new
59
- FakeWeb.response_for(uri, &block)
42
+ FakeWeb.response_for(method, uri, &block)
60
43
  elsif FakeWeb.allow_net_connect?
61
44
  original_net_http_connect
62
45
  original_net_http_request(request, body, &block)
63
46
  else
64
47
  raise FakeWeb::NetConnectNotAllowedError,
65
- "Real HTTP connections are disabled. Unregistered URI: #{uri}"
48
+ "Real HTTP connections are disabled. Unregistered request: #{request.method} #{uri}"
66
49
  end
67
50
  end
68
51
 
@@ -70,4 +53,4 @@ module Net #:nodoc: all
70
53
  end
71
54
  end
72
55
 
73
- end
56
+ end
@@ -0,0 +1,78 @@
1
+ module FakeWeb
2
+ class Registry #:nodoc:
3
+ include Singleton
4
+
5
+ attr_accessor :uri_map
6
+
7
+ def initialize
8
+ clean_registry
9
+ end
10
+
11
+ def clean_registry
12
+ self.uri_map = Hash.new do |hash, key|
13
+ hash[key] = Hash.new(&hash.default_proc)
14
+ end
15
+ end
16
+
17
+ def register_uri(method, uri, options)
18
+ uri_map[normalize_uri(uri)][method] = [*[options]].flatten.collect do |option|
19
+ FakeWeb::Responder.new(method, uri, option, option[:times])
20
+ end
21
+ end
22
+
23
+ def registered_uri?(method, uri)
24
+ normalized_uri = normalize_uri(uri)
25
+ uri_map[normalized_uri].has_key?(method) || uri_map[normalized_uri].has_key?(:any)
26
+ end
27
+
28
+ def registered_uri(method, uri)
29
+ uri = normalize_uri(uri)
30
+ registered = registered_uri?(method, uri)
31
+ if registered && uri_map[uri].has_key?(method)
32
+ uri_map[uri][method]
33
+ elsif registered
34
+ uri_map[uri][:any]
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ def response_for(method, uri, &block)
41
+ responses = registered_uri(method, uri)
42
+ return nil if responses.nil?
43
+
44
+ next_response = responses.last
45
+ responses.each do |response|
46
+ if response.times and response.times > 0
47
+ response.times -= 1
48
+ next_response = response
49
+ break
50
+ end
51
+ end
52
+
53
+ next_response.response(&block)
54
+ end
55
+
56
+ private
57
+
58
+ def normalize_uri(uri)
59
+ case uri
60
+ when URI then uri
61
+ else
62
+ uri = 'http://' + uri unless uri.match('^https?://')
63
+ parsed_uri = URI.parse(uri)
64
+ parsed_uri.query = sort_query_params(parsed_uri.query)
65
+ parsed_uri
66
+ end
67
+ end
68
+
69
+ def sort_query_params(query)
70
+ if query.nil? || query.empty?
71
+ nil
72
+ else
73
+ query.split('&').sort.join('&')
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,99 @@
1
+ module FakeWeb
2
+ class Responder #:nodoc:
3
+
4
+ attr_accessor :method, :uri, :options, :times
5
+
6
+ def initialize(method, uri, options, times)
7
+ self.method = method
8
+ self.uri = uri
9
+ self.options = options
10
+ self.times = times ? times : 1
11
+ end
12
+
13
+ def response(&block)
14
+ if has_baked_response?
15
+ response = baked_response
16
+ else
17
+ code, msg = meta_information
18
+ response = Net::HTTPResponse.send(:response_class, code.to_s).new(uri, code.to_s, msg)
19
+ response.instance_variable_set(:@body, content)
20
+ end
21
+
22
+ response.instance_variable_set(:@read, true)
23
+ response.extend FakeWeb::Response
24
+
25
+ optionally_raise(response)
26
+
27
+ yield response if block_given?
28
+
29
+ response
30
+ end
31
+
32
+ private
33
+
34
+ def content
35
+ [ :file, :string ].each do |map_option|
36
+ next unless options.has_key?(map_option)
37
+ return self.send("#{map_option}_response", options[map_option])
38
+ end
39
+
40
+ return ''
41
+ end
42
+
43
+ def file_response(path)
44
+ IO.read(path)
45
+ end
46
+
47
+ def string_response(string)
48
+ string
49
+ end
50
+
51
+ def baked_response
52
+ resp = case options[:response]
53
+ when Net::HTTPResponse then options[:response]
54
+ when String
55
+ socket = Net::BufferedIO.new(options[:response])
56
+ r = Net::HTTPResponse.read_new(socket)
57
+
58
+ # Store the oiriginal transfer-encoding
59
+ saved_transfer_encoding = r.instance_eval {
60
+ @header['transfer-encoding'] if @header.key?('transfer-encoding')
61
+ }
62
+
63
+ # read the body of response.
64
+ r.instance_eval { @header['transfer-encoding'] = nil }
65
+ r.reading_body(socket, true) {}
66
+
67
+ # Delete the transfer-encoding key from r.@header if there wasn't one,
68
+ # else restore the saved_transfer_encoding.
69
+ if saved_transfer_encoding.nil?
70
+ r.instance_eval { @header.delete('transfer-encoding') }
71
+ else
72
+ r.instance_eval { @header['transfer-encoding'] = saved_transfer_encoding }
73
+ end
74
+ r
75
+ else raise StandardError, "Handler unimplemented for response #{options[:response]}"
76
+ end
77
+ end
78
+
79
+ def has_baked_response?
80
+ options.has_key?(:response)
81
+ end
82
+
83
+ def optionally_raise(response)
84
+ return unless options.has_key?(:exception)
85
+ ex_alloc = options[:exception].allocate
86
+ ex_instance = case ex_alloc
87
+ when Net::HTTPError, OpenURI::HTTPError
88
+ options[:exception].new('Exception from FakeWeb', response)
89
+ else options[:exception].new
90
+ end
91
+ raise ex_instance
92
+ end
93
+
94
+ def meta_information
95
+ options.has_key?(:status) ? options[:status] : [200, 'OK']
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,10 @@
1
+ module FakeWeb
2
+ module Response #:nodoc:
3
+
4
+ def read_body(*args, &block)
5
+ yield @body if block_given?
6
+ @body
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ module FakeWeb
2
+ class SocketDelegator #:nodoc:
3
+
4
+ def initialize(delegate=nil)
5
+ @delegate = nil
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ if @delegate
10
+ @delegate.send(method, *args, &block)
11
+ else
12
+ self.send("my_#{method}", *args, &block)
13
+ end
14
+ end
15
+
16
+ def my_closed?
17
+ @closed ||= true
18
+ end
19
+
20
+ def my_readuntil(*args)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 200 OK
2
+ Cache-Control: private, max-age=0
3
+ Date: Sun, 01 Feb 2009 02:16:24 GMT
4
+ Expires: -1
5
+ Content-Type: text/html; charset=ISO-8859-1
6
+ Set-Cookie: PREF=ID=a6d9b5f5a4056dfe:TM=1233454584:LM=1233454584:S=U9pSwSu4eQwOPenX; expires=Tue, 01-Feb-2011 02:16:24 GMT; path=/; domain=.google.com
7
+ Server: gws
8
+ Transfer-Encoding: chunked
9
+
10
+ <html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><script>var _gjwl=location;function _gjuc(){var a=_gjwl.hash;if(a.indexOf("&q=")>0||a.indexOf("#q=")>=0){a=a.substring(1);if(a.indexOf("#")==-1){for(var c=0;c<a.length;){var d=c;if(a.charAt(d)=="&")++d;var b=a.indexOf("&",d);if(b==-1)b=a.length;var e=a.substring(d,b);if(e.indexOf("fp=")==0){a=a.substring(0,c)+a.substring(b,a.length);b=c}else if(e=="cad=h")return 0;c=b}_gjwl.href="search?"+a+"&cad=h";return 1}}return 0};
11
+ window._gjuc && location.hash && _gjuc();</script><style>body,td,a,p,.h{font-family:arial,sans-serif}.h{color:#36c;font-size:20px}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}#gbar{height:22px;padding-left:2px}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}#gbi,#gbs{background:#fff;left:0;position:absolute;top:24px;visibility:hidden;z-index:1000}#gbi{border:1px solid;border-color:#c9d7f1 #36c #36c #a2bae7;z-index:1001}#guser{padding-bottom:7px !important}#gbar,#guser{font-size:13px;padding-top:1px !important}@media all{.gb1,.gb3{height:22px;margin-right:.73em;vertical-align:top}#gbar{float:left}}.gb2{display:block;padding:.2em .5em}a.gb1,a.gb2,a.gb3{color:#00c !important}.gb2,.gb3{text-decoration:none}a.gb2:hover{background:#36c;color:#fff !important}</style><script>window.google={kEI:"-AWFSZ6qFYuUswO9j5HIDQ",kEXPI:"17259,19547",kHL:"en"};
12
+ google.y={};google.x=function(e,g){google.y[e.id]=[e,g];return false};window.gbar={};(function(){var b=window.gbar,f,h;b.qs=function(a){var c=window.encodeURIComponent&&(document.forms[0].q||"").value;if(c)a.href=a.href.replace(/([?&])q=[^&]*|$/,function(i,g){return(g||"&")+"q="+encodeURIComponent(c)})};function j(a,c){a.visibility=h?"hidden":"visible";a.left=c+"px"}b.tg=function(a){a=a||window.event;var c=0,i,g=window.navExtra,d=document.getElementById("gbi"),e=a.target||a.srcElement;a.cancelBubble=true;if(!f){f=document.createElement(Array.every||window.createPopup?"iframe":"div");f.frameBorder="0";f.src="#";d.parentNode.appendChild(f).id="gbs";if(g)for(i in g)d.insertBefore(g[i],d.firstChild).className="gb2";document.onclick=b.close}if(e.className!="gb3")e=e.parentNode;do c+=e.offsetLeft;while(e=e.offsetParent);j(d.style,c);f.style.width=d.offsetWidth+"px";f.style.height=d.offsetHeight+"px";j(f.style,c);h=!h};b.close=function(a){h&&b.tg(a)}})();</script></head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus();if(document.images)new Image().src='/images/nav_logo3.png'" topmargin=3 marginheight=3><div id=gbar><nobr><b class=gb1>Web</b> <a href="http://images.google.com/imghp?hl=en&tab=wi" onclick=gbar.qs(this) class=gb1>Images</a> <a href="http://maps.google.com/maps?hl=en&tab=wl" onclick=gbar.qs(this) class=gb1>Maps</a> <a href="http://news.google.com/nwshp?hl=en&tab=wn" onclick=gbar.qs(this) class=gb1>News</a> <a href="http://www.google.com/prdhp?hl=en&tab=wf" onclick=gbar.qs(this) class=gb1>Shopping</a> <a href="http://mail.google.com/mail/?hl=en&tab=wm" class=gb1>Gmail</a> <a href="http://www.google.com/intl/en/options/" onclick="this.blur();gbar.tg(event);return !1" class=gb3><u>more</u> <small>&#9660;</small></a><div id=gbi> <a href="http://video.google.com/?hl=en&tab=wv" onclick=gbar.qs(this) class=gb2>Video</a> <a href="http://groups.google.com/grphp?hl=en&tab=wg" onclick=gbar.qs(this) class=gb2>Groups</a> <a href="http://books.google.com/bkshp?hl=en&tab=wp" onclick=gbar.qs(this) class=gb2>Books</a> <a href="http://scholar.google.com/schhp?hl=en&tab=ws" onclick=gbar.qs(this) class=gb2>Scholar</a> <a href="http://finance.google.com/finance?hl=en&tab=we" onclick=gbar.qs(this) class=gb2>Finance</a> <a href="http://blogsearch.google.com/?hl=en&tab=wb" onclick=gbar.qs(this) class=gb2>Blogs</a> <div class=gb2><div class=gbd></div></div> <a href="http://www.youtube.com/?hl=en&tab=w1" onclick=gbar.qs(this) class=gb2>YouTube</a> <a href="http://www.google.com/calendar/render?hl=en&tab=wc" class=gb2>Calendar</a> <a href="http://picasaweb.google.com/home?hl=en&tab=wq" onclick=gbar.qs(this) class=gb2>Photos</a> <a href="http://docs.google.com/?hl=en&tab=wo" class=gb2>Documents</a> <a href="http://www.google.com/reader/view/?hl=en&tab=wy" class=gb2>Reader</a> <a href="http://sites.google.com/?hl=en&tab=w3" class=gb2>Sites</a> <div class=gb2><div class=gbd></div></div> <a href="http://www.google.com/intl/en/options/" class=gb2>even more &raquo;</a></div> </nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div><div align=right id=guser style="font-size:84%;padding:0 0 4px" width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg">iGoogle</a> | <a href="https://www.google.com/accounts/Login?continue=http://www.google.com/&hl=en">Sign in</a></nobr></div><center><br clear=all id=lgpd><img alt="Google" height=110 src="/intl/en_ALL/images/logo.gif" width=276><br><br><form action="/search" name=f><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=en><input type=hidden name=ie value="ISO-8859-1"><input autocomplete="off" maxlength=2048 name=q size=55 title="Google Search" value=""><br><input name=btnG type=submit value="Google Search"><input name=btnI type=submit value="I'm Feeling Lucky"></td><td nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a href=/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><font size=-1>Share what you know. <a href="/aclk?sa=L&ai=CYhslHwSFSZH6LIHusAPEsc2eBfv77nqP3YC9CsHZnNkTEAEgwVRQypDftPn_____AWDJBqoECU_QbUVlfOdxZw&num=1&sig=AGiWqtwRgqw8y_kza6RGKxBrCstaXkDJ7A&q=http://knol.google.com">Write a Knol</a>.</font><br><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="/services/">Business Solutions</a> - <a href="/intl/en/about.html">About Google</a></font><p><font size=-2>&copy;2009 - <a href="/intl/en/privacy.html">Privacy</a></font></p></center></body><script>if(google.y)google.y.first=[];window.setTimeout(function(){var xjs=document.createElement('script');xjs.src='/extern_js/f/CgJlbhICdXMgACswCjgVLCswDjgELCswGDgDLA/L3N5xu59nDE.js';document.getElementsByTagName('head')[0].appendChild(xjs)},0);google.y.first.push(function(){google.ac.i(document.f,document.f.q,'','')})</script><script>function _gjp() {!(location.hash && _gjuc()) && setTimeout(_gjp, 500);}window._gjuc && _gjp();</script></html>
@@ -0,0 +1,17 @@
1
+ HTTP/1.1 200 OK
2
+ Cache-Control: private, max-age=0
3
+ Date: Sun, 01 Feb 2009 01:54:36 GMT
4
+ Expires: -1
5
+ Content-Type: text/html; charset=ISO-8859-1
6
+ Set-Cookie: PREF=ID=4320bcaa30d097de:TM=1233453276:LM=1233453276:S=Eio39bg_nIabTxzL; expires=Tue, 01-Feb-2011 01:54:36 GMT; path=/; domain=.google.com
7
+ Server: gws
8
+ Transfer-Encoding: chunked
9
+
10
+ fef
11
+ <html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><script>var _gjwl=location;function _gjuc(){var a=_gjwl.hash;if(a.indexOf("&q=")>0||a.indexOf("#q=")>=0){a=a.substring(1);if(a.indexOf("#")==-1){for(var c=0;c<a.length;){var d=c;if(a.charAt(d)=="&")++d;var b=a.indexOf("&",d);if(b==-1)b=a.length;var e=a.substring(d,b);if(e.indexOf("fp=")==0){a=a.substring(0,c)+a.substring(b,a.length);b=c}else if(e=="cad=h")return 0;c=b}_gjwl.href="search?"+a+"&cad=h";return 1}}return 0};
12
+ window._gjuc && location.hash && _gjuc();</script><style>body,td,a,p,.h{font-family:arial,sans-serif}.h{color:#36c;font-size:20px}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}#gbar{height:22px;padding-left:2px}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}#gbi,#gbs{background:#fff;left:0;position:absolute;top:24px;visibility:hidden;z-index:1000}#gbi{border:1px solid;border-color:#c9d7f1 #36c #36c #a2bae7;z-index:1001}#guser{padding-bottom:7px !important}#gbar,#guser{font-size:13px;padding-top:1px !important}@media all{.gb1,.gb3{height:22px;margin-right:.73em;vertical-align:top}#gbar{float:left}}.gb2{display:block;padding:.2em .5em}a.gb1,a.gb2,a.gb3{color:#00c !important}.gb2,.gb3{text-decoration:none}a.gb2:hover{background:#36c;color:#fff !important}</style><script>window.google={kEI:"3ACFSYC6EKTcswOL4_nBDQ",kEXPI:"17259,19463",kHL:"en"};
13
+ google.y={};google.x=function(e,g){google.y[e.id]=[e,g];return false};window.gbar={};(function(){var b=window.gbar,f,h;b.qs=function(a){var c=window.encodeURIComponent&&(document.forms[0].q||"").value;if(c)a.href=a.href.replace(/([?&])q=[^&]*|$/,function(i,g){return(g||"&")+"q="+encodeURIComponent(c)})};function j(a,c){a.visibility=h?"hidden":"visible";a.left=c+"px"}b.tg=function(a){a=a||window.event;var c=0,i,g=window.navExtra,d=document.getElementById("gbi"),e=a.target||a.srcElement;a.cancelBubble=true;if(!f){f=document.createElement(Array.every||window.createPopup?"iframe":"div");f.frameBorder="0";f.src="#";d.parentNode.appendChild(f).id="gbs";if(g)for(i in g)d.insertBefore(g[i],d.firstChild).className="gb2";document.onclick=b.close}if(e.className!="gb3")e=e.parentNode;do c+=e.offsetLeft;while(e=e.offsetParent);j(d.style,c);f.style.width=d.offsetWidth+"px";f.style.height=d.offsetHeight+"px";j(f.style,c);h=!h};b.close=function(a){h&&b.tg(a)}})();</script></head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus();if(document.images)new Image().src='/images/nav_logo3.png'" topmargin=3 marginheight=3><div id=gbar><nobr><b class=gb1>Web</b> <a href="http://images.google.com/imghp?hl=en&tab=wi" onclick=gbar.qs(this) class=gb1>Images</a> <a href="http://maps.google.com/maps?hl=en&tab=wl" onclick=gbar.qs(this) class=gb1>Maps</a> <a href="http://news.google.com/nwshp?hl=en&tab=wn" onclick=gbar.qs(this) class=gb1>News</a> <a href="http://www.google.com/prdhp?hl=en&tab=wf" onclick=gbar.qs(this) class=gb1>Shopping</a> <a href="http://mail.google.com/mail/?hl=en&tab=wm" class=gb1>Gmail</a> <a href="http://www.google.com/intl/en/options/" onclick="this.blur();gbar.tg(event);return !1" class=gb3><u>more</u> <small>&#9660;</small></a><div id=gbi> <a href="http://video.google.com/?hl=en&tab=wv" onclick=gbar.qs(this) class=gb2>Video</a> <a href="http://groups.google.com/grphp?hl=en&tab=wg" onclick=gbar.qs(this) class=gb2>Groups</a> <a href="http://books.google.com/bkshp?hl=en&tab=wp" onclick=gbar.qs(this) class=gb2>Books</a> <a href="http://scholar.google.com/schhp?hl=en&tab=ws" onclick=gbar.qs(this) class=gb2>Scholar</a> <a href="http://finance.google.com/finance?hl=en&tab=we" onclick=gbar.qs(this) class=gb2>Finance</a> <a href="http://blogsearch.google.com/?hl=en&tab=wb" onclick=gbar.qs(this) class=gb2>Blogs</a> <div class=gb2><div class=gbd></div></div> <a href="http://www.youtube.com/?hl=en&tab=w1" onclick=gbar.qs(this) class=gb2>YouTube</a> <a href="http://www.google.com/calendar/render?hl=en&tab=wc" class=gb2>Calendar</a> <a href="http
14
+ a27
15
+ ://picasaweb.google.com/home?hl=en&tab=wq" onclick=gbar.qs(this) class=gb2>Photos</a> <a href="http://docs.google.com/?hl=en&tab=wo" class=gb2>Documents</a> <a href="http://www.google.com/reader/view/?hl=en&tab=wy" class=gb2>Reader</a> <a href="http://sites.google.com/?hl=en&tab=w3" class=gb2>Sites</a> <div class=gb2><div class=gbd></div></div> <a href="http://www.google.com/intl/en/options/" class=gb2>even more &raquo;</a></div> </nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div><div align=right id=guser style="font-size:84%;padding:0 0 4px" width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg">iGoogle</a> | <a href="https://www.google.com/accounts/Login?continue=http://www.google.com/&hl=en">Sign in</a></nobr></div><center><br clear=all id=lgpd><img alt="Google" height=110 src="/intl/en_ALL/images/logo.gif" width=276><br><br><form action="/search" name=f><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=en><input type=hidden name=ie value="ISO-8859-1"><input autocomplete="off" maxlength=2048 name=q size=55 title="Google Search" value=""><br><input name=btnG type=submit value="Google Search"><input name=btnI type=submit value="I'm Feeling Lucky"></td><td nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a href=/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><font size=-1>Share what you know. <a href="/aclk?sa=L&ai=CFL7HzwCFSZCnCJSwsQPm842HB_v77nqP3YC9CsHZnNkTEAEgwVRQypDftPn_____AWDJBqoECU_Q1sTewQNSbw&num=1&sig=AGiWqtyz-UiOD3EpsSp4k3n8A7zooeg48g&q=http://knol.google.com">Write a Knol</a>.</font><br><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="/services/">Business Solutions</a> - <a href="/intl/en/about.html">About Google</a></font><p><font size=-2>&copy;2009 - <a href="/intl/en/privacy.html">Privacy</a></font></p></center></body><script>if(google.y)google.y.first=[];window.setTimeout(function(){var xjs=document.createElement('script');xjs.src='/extern_js/f/CgJlbhICdXMgACswCjgVLCswDjgELCswGDgDLA/L3N5xu59nDE.js';document.getElementsByTagName('head')[0].appendChild(xjs)},0);google.y.first.push(function(){google.ac.i(document.f,document.f.q,'','')})</script><script>function _gjp() {!(location.hash && _gjuc()) && setTimeout(_gjp, 500);}window._gjuc && _gjp();</script></html>
16
+ 0
17
+
@@ -0,0 +1,11 @@
1
+ HTTP/1.0 200 OK
2
+ Cache-Control: private, max-age=0
3
+ Date: Sun, 01 Feb 2009 01:55:33 GMT
4
+ Expires: -1
5
+ Content-Type: text/html; charset=ISO-8859-1
6
+ Set-Cookie: PREF=ID=3c140c3eb4c4f516:TM=1233453333:LM=1233453333:S=OH7sElk2hOWkb9ot; expires=Tue, 01-Feb-2011 01:55:33 GMT; path=/; domain=.google.com
7
+ Server: gws
8
+
9
+ <html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><script>var _gjwl=location;function _gjuc(){var a=_gjwl.hash;if(a.indexOf("&q=")>0||a.indexOf("#q=")>=0){a=a.substring(1);if(a.indexOf("#")==-1){for(var c=0;c<a.length;){var d=c;if(a.charAt(d)=="&")++d;var b=a.indexOf("&",d);if(b==-1)b=a.length;var e=a.substring(d,b);if(e.indexOf("fp=")==0){a=a.substring(0,c)+a.substring(b,a.length);b=c}else if(e=="cad=h")return 0;c=b}_gjwl.href="search?"+a+"&cad=h";return 1}}return 0};
10
+ window._gjuc && location.hash && _gjuc();</script><style>body,td,a,p,.h{font-family:arial,sans-serif}.h{color:#36c;font-size:20px}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}#gbar{height:22px;padding-left:2px}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}#gbi,#gbs{background:#fff;left:0;position:absolute;top:24px;visibility:hidden;z-index:1000}#gbi{border:1px solid;border-color:#c9d7f1 #36c #36c #a2bae7;z-index:1001}#guser{padding-bottom:7px !important}#gbar,#guser{font-size:13px;padding-top:1px !important}@media all{.gb1,.gb3{height:22px;margin-right:.73em;vertical-align:top}#gbar{float:left}}.gb2{display:block;padding:.2em .5em}a.gb1,a.gb2,a.gb3{color:#00c !important}.gb2,.gb3{text-decoration:none}a.gb2:hover{background:#36c;color:#fff !important}</style><script>window.google={kEI:"FQGFSY2rG5eSswOKpsHeDQ",kEXPI:"17259",kHL:"en"};
11
+ google.y={};google.x=function(e,g){google.y[e.id]=[e,g];return false};window.gbar={};(function(){var b=window.gbar,f,h;b.qs=function(a){var c=window.encodeURIComponent&&(document.forms[0].q||"").value;if(c)a.href=a.href.replace(/([?&])q=[^&]*|$/,function(i,g){return(g||"&")+"q="+encodeURIComponent(c)})};function j(a,c){a.visibility=h?"hidden":"visible";a.left=c+"px"}b.tg=function(a){a=a||window.event;var c=0,i,g=window.navExtra,d=document.getElementById("gbi"),e=a.target||a.srcElement;a.cancelBubble=true;if(!f){f=document.createElement(Array.every||window.createPopup?"iframe":"div");f.frameBorder="0";f.src="#";d.parentNode.appendChild(f).id="gbs";if(g)for(i in g)d.insertBefore(g[i],d.firstChild).className="gb2";document.onclick=b.close}if(e.className!="gb3")e=e.parentNode;do c+=e.offsetLeft;while(e=e.offsetParent);j(d.style,c);f.style.width=d.offsetWidth+"px";f.style.height=d.offsetHeight+"px";j(f.style,c);h=!h};b.close=function(a){h&&b.tg(a)}})();</script></head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus();if(document.images)new Image().src='/images/nav_logo3.png'" topmargin=3 marginheight=3><div id=gbar><nobr><b class=gb1>Web</b> <a href="http://images.google.com/imghp?hl=en&tab=wi" onclick=gbar.qs(this) class=gb1>Images</a> <a href="http://maps.google.com/maps?hl=en&tab=wl" onclick=gbar.qs(this) class=gb1>Maps</a> <a href="http://news.google.com/nwshp?hl=en&tab=wn" onclick=gbar.qs(this) class=gb1>News</a> <a href="http://www.google.com/prdhp?hl=en&tab=wf" onclick=gbar.qs(this) class=gb1>Shopping</a> <a href="http://mail.google.com/mail/?hl=en&tab=wm" class=gb1>Gmail</a> <a href="http://www.google.com/intl/en/options/" onclick="this.blur();gbar.tg(event);return !1" class=gb3><u>more</u> <small>&#9660;</small></a><div id=gbi> <a href="http://video.google.com/?hl=en&tab=wv" onclick=gbar.qs(this) class=gb2>Video</a> <a href="http://groups.google.com/grphp?hl=en&tab=wg" onclick=gbar.qs(this) class=gb2>Groups</a> <a href="http://books.google.com/bkshp?hl=en&tab=wp" onclick=gbar.qs(this) class=gb2>Books</a> <a href="http://scholar.google.com/schhp?hl=en&tab=ws" onclick=gbar.qs(this) class=gb2>Scholar</a> <a href="http://finance.google.com/finance?hl=en&tab=we" onclick=gbar.qs(this) class=gb2>Finance</a> <a href="http://blogsearch.google.com/?hl=en&tab=wb" onclick=gbar.qs(this) class=gb2>Blogs</a> <div class=gb2><div class=gbd></div></div> <a href="http://www.youtube.com/?hl=en&tab=w1" onclick=gbar.qs(this) class=gb2>YouTube</a> <a href="http://www.google.com/calendar/render?hl=en&tab=wc" class=gb2>Calendar</a> <a href="http://picasaweb.google.com/home?hl=en&tab=wq" onclick=gbar.qs(this) class=gb2>Photos</a> <a href="http://docs.google.com/?hl=en&tab=wo" class=gb2>Documents</a> <a href="http://www.google.com/reader/view/?hl=en&tab=wy" class=gb2>Reader</a> <a href="http://sites.google.com/?hl=en&tab=w3" class=gb2>Sites</a> <div class=gb2><div class=gbd></div></div> <a href="http://www.google.com/intl/en/options/" class=gb2>even more &raquo;</a></div> </nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div><div align=right id=guser style="font-size:84%;padding:0 0 4px" width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg">iGoogle</a> | <a href="https://www.google.com/accounts/Login?continue=http://www.google.com/&hl=en">Sign in</a></nobr></div><center><br clear=all id=lgpd><img alt="Google" height=110 src="/intl/en_ALL/images/logo.gif" width=276><br><br><form action="/search" name=f><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=en><input type=hidden name=ie value="ISO-8859-1"><input autocomplete="off" maxlength=2048 name=q size=55 title="Google Search" value=""><br><input name=btnG type=submit value="Google Search"><input name=btnI type=submit value="I'm Feeling Lucky"></td><td nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a href=/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><font size=-1>Share what you know. <a href="/aclk?sa=L&ai=ClyBp_v-EScTWD4W2tQOxoqSkB_v77nqP3YC9CsHZnNkTEAEgwVRQypDftPn_____AWDJBqoECU_QphTjHaZ5QA&num=1&sig=AGiWqtwtBqZ-zra3DJd_1chQKhKGf7lMVg&q=http://knol.google.com">Write a Knol</a>.</font><br><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="/services/">Business Solutions</a> - <a href="/intl/en/about.html">About Google</a></font><p><font size=-2>&copy;2009 - <a href="/intl/en/privacy.html">Privacy</a></font></p></center></body><script>if(google.y)google.y.first=[];window.setTimeout(function(){var xjs=document.createElement('script');xjs.src='/extern_js/f/CgJlbhICdXMgACswCjgNLCswDjgELCswGDgDLA/oTKXc0xdkmY.js';document.getElementsByTagName('head')[0].appendChild(xjs)},0);google.y.first.push(function(){google.ac.i(document.f,document.f.q,'','')})</script><script>function _gjp() {!(location.hash && _gjuc()) && setTimeout(_gjp, 500);}window._gjuc && _gjp();</script></html>
@@ -0,0 +1,3 @@
1
+ line 1
2
+ line 2
3
+ line 3
@@ -1,33 +1,44 @@
1
- # FakeWeb - Ruby Helper for Faking Web Requests
2
- # Copyright 2006 Blaine Cook <romeda@gmail.com>.
3
- #
4
- # FakeWeb is free software; you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation; either version 2 of the License, or
7
- # (at your option) any later version.
8
- #
9
- # FakeWeb is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU General Public License
15
- # along with FakeWeb; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
1
  require File.join(File.dirname(__FILE__), "test_helper")
19
2
 
20
3
  class TestFakeWeb < Test::Unit::TestCase
21
4
 
22
5
  def setup
6
+ FakeWeb.allow_net_connect = true
23
7
  FakeWeb.clean_registry
24
- FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
25
8
  end
26
9
 
27
10
  def test_register_uri
11
+ FakeWeb.register_uri('http://mock/test_example.txt', :string => "example")
28
12
  assert FakeWeb.registered_uri?('http://mock/test_example.txt')
29
13
  end
30
14
 
15
+ def test_register_uri_with_wrong_number_of_arguments
16
+ assert_raises ArgumentError do
17
+ FakeWeb.register_uri("http://example.com")
18
+ end
19
+ assert_raises ArgumentError do
20
+ FakeWeb.register_uri(:get, "http://example.com", "/example", :string => "example")
21
+ end
22
+ end
23
+
24
+ def test_registered_uri_with_wrong_number_of_arguments
25
+ assert_raises ArgumentError do
26
+ FakeWeb.registered_uri?
27
+ end
28
+ assert_raises ArgumentError do
29
+ FakeWeb.registered_uri?(:get, "http://example.com", "/example")
30
+ end
31
+ end
32
+
33
+ def test_response_for_with_wrong_number_of_arguments
34
+ assert_raises ArgumentError do
35
+ FakeWeb.response_for
36
+ end
37
+ assert_raises ArgumentError do
38
+ FakeWeb.response_for(:get, "http://example.com", "/example")
39
+ end
40
+ end
41
+
31
42
  def test_register_uri_without_domain_name
32
43
  assert_raises URI::InvalidURIError do
33
44
  FakeWeb.register_uri('test_example2.txt', File.dirname(__FILE__) + '/fixtures/test_example.txt')
@@ -64,10 +75,46 @@ class TestFakeWeb < Test::Unit::TestCase
64
75
  assert FakeWeb.registered_uri?('https://example.com:443/')
65
76
  end
66
77
 
67
- def test_content_for_registered_uri
78
+ def test_register_uri_for_any_method_explicitly
79
+ FakeWeb.register_uri(:any, "http://example.com/rpc_endpoint", :string => "OK")
80
+ assert FakeWeb.registered_uri?(:get, "http://example.com/rpc_endpoint")
81
+ assert FakeWeb.registered_uri?(:post, "http://example.com/rpc_endpoint")
82
+ assert FakeWeb.registered_uri?(:put, "http://example.com/rpc_endpoint")
83
+ assert FakeWeb.registered_uri?(:delete, "http://example.com/rpc_endpoint")
84
+ assert FakeWeb.registered_uri?(:any, "http://example.com/rpc_endpoint")
85
+ assert FakeWeb.registered_uri?("http://example.com/rpc_endpoint")
86
+ end
87
+
88
+ def test_register_uri_for_get_method_only
89
+ FakeWeb.register_uri(:get, "http://example.com/users", :string => "User list")
90
+ assert FakeWeb.registered_uri?(:get, "http://example.com/users")
91
+ assert !FakeWeb.registered_uri?(:post, "http://example.com/users")
92
+ assert !FakeWeb.registered_uri?(:put, "http://example.com/users")
93
+ assert !FakeWeb.registered_uri?(:delete, "http://example.com/users")
94
+ assert !FakeWeb.registered_uri?(:any, "http://example.com/users")
95
+ assert !FakeWeb.registered_uri?("http://example.com/users")
96
+ end
97
+
98
+ def test_response_for_with_registered_uri
99
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
68
100
  assert_equal 'test example content', FakeWeb.response_for('http://mock/test_example.txt').body
69
101
  end
70
102
 
103
+ def test_response_for_with_unknown_uri
104
+ assert_equal nil, FakeWeb.response_for(:get, 'http://example.com/')
105
+ end
106
+
107
+ def test_response_for_with_put_method
108
+ FakeWeb.register_uri(:put, "http://example.com", :string => "response")
109
+ assert_equal 'response', FakeWeb.response_for(:put, "http://example.com").body
110
+ end
111
+
112
+ def test_response_for_with_any_method_explicitly
113
+ FakeWeb.register_uri(:any, "http://example.com", :string => "response")
114
+ assert_equal 'response', FakeWeb.response_for(:get, "http://example.com").body
115
+ assert_equal 'response', FakeWeb.response_for(:any, "http://example.com").body
116
+ end
117
+
71
118
  def test_content_for_registered_uri_with_port_and_request_with_port
72
119
  FakeWeb.register_uri('http://example.com:3000/', :string => 'test example content')
73
120
  Net::HTTP.start('example.com', 3000) do |http|
@@ -126,8 +173,41 @@ class TestFakeWeb < Test::Unit::TestCase
126
173
  end
127
174
  end
128
175
 
176
+ def test_content_for_registered_uri_with_get_method_only
177
+ FakeWeb.allow_net_connect = false
178
+ FakeWeb.register_uri(:get, "http://example.com/", :string => "test example content")
179
+ Net::HTTP.start('example.com') do |http|
180
+ assert_equal 'test example content', http.get('/').body
181
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.post('/', nil) }
182
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.put('/', nil) }
183
+ assert_raises(FakeWeb::NetConnectNotAllowedError) { http.delete('/', nil) }
184
+ end
185
+ end
186
+
187
+ def test_content_for_registered_uri_with_any_method_explicitly
188
+ FakeWeb.allow_net_connect = false
189
+ FakeWeb.register_uri(:any, "http://example.com/", :string => "test example content")
190
+ Net::HTTP.start('example.com') do |http|
191
+ assert_equal 'test example content', http.get('/').body
192
+ assert_equal 'test example content', http.post('/', nil).body
193
+ assert_equal 'test example content', http.put('/', nil).body
194
+ assert_equal 'test example content', http.delete('/').body
195
+ end
196
+ end
197
+
198
+ def test_content_for_registered_uri_with_any_method_implicitly
199
+ FakeWeb.allow_net_connect = false
200
+ FakeWeb.register_uri("http://example.com/", :string => "test example content")
201
+ Net::HTTP.start('example.com') do |http|
202
+ assert_equal 'test example content', http.get('/').body
203
+ assert_equal 'test example content', http.post('/', nil).body
204
+ assert_equal 'test example content', http.put('/', nil).body
205
+ assert_equal 'test example content', http.delete('/').body
206
+ end
207
+ end
129
208
 
130
209
  def test_mock_request_with_block
210
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
131
211
  Net::HTTP.start('mock') do |http|
132
212
  response = http.get('/test_example.txt')
133
213
  assert_equal 'test example content', response.body
@@ -135,6 +215,7 @@ class TestFakeWeb < Test::Unit::TestCase
135
215
  end
136
216
 
137
217
  def test_mock_request_with_undocumented_full_uri_argument_style
218
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
138
219
  Net::HTTP.start('mock') do |query|
139
220
  response = query.get('http://mock/test_example.txt')
140
221
  assert_equal 'test example content', response.body
@@ -150,6 +231,7 @@ class TestFakeWeb < Test::Unit::TestCase
150
231
  end
151
232
 
152
233
  def test_mock_post
234
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
153
235
  response = nil
154
236
  Net::HTTP.start('mock') do |query|
155
237
  response = query.post('/test_example.txt', '')
@@ -178,7 +260,7 @@ class TestFakeWeb < Test::Unit::TestCase
178
260
  end
179
261
 
180
262
  def test_mock_get_with_request_from_file_as_registered_uri
181
- FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/test_request')
263
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_without_transfer_encoding')
182
264
  response = nil
183
265
  Net::HTTP.start('www.google.com') do |query|
184
266
  response = query.get('/')
@@ -188,7 +270,7 @@ class TestFakeWeb < Test::Unit::TestCase
188
270
  end
189
271
 
190
272
  def test_mock_post_with_request_from_file_as_registered_uri
191
- FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/test_request')
273
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_without_transfer_encoding')
192
274
  response = nil
193
275
  Net::HTTP.start('www.google.com') do |query|
194
276
  response = query.post('/', '')
@@ -298,6 +380,7 @@ class TestFakeWeb < Test::Unit::TestCase
298
380
  end
299
381
 
300
382
  def test_mock_instance_syntax
383
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
301
384
  response = nil
302
385
  uri = URI.parse('http://mock/test_example.txt')
303
386
  http = Net::HTTP.new(uri.host, uri.port)
@@ -312,7 +395,7 @@ class TestFakeWeb < Test::Unit::TestCase
312
395
  response = nil
313
396
  proxy_address = nil
314
397
  proxy_port = nil
315
-
398
+ FakeWeb.register_uri('http://mock/test_example.txt', :file => File.dirname(__FILE__) + '/fixtures/test_example.txt')
316
399
  uri = URI.parse('http://mock/test_example.txt')
317
400
  http = Net::HTTP::Proxy(proxy_address, proxy_port).new(
318
401
  uri.host, (uri.port or 80))
@@ -323,9 +406,10 @@ class TestFakeWeb < Test::Unit::TestCase
323
406
  assert_equal 'test example content', response.body
324
407
  end
325
408
 
326
- def test_reponse_type
409
+ def test_response_type
410
+ FakeWeb.register_uri('http://mock/test_example.txt', :string => "test")
327
411
  Net::HTTP.start('mock') do |http|
328
- response = http.get('/test_example.txt', '')
412
+ response = http.get('/test_example.txt')
329
413
  assert_kind_of(Net::HTTPSuccess, response)
330
414
  end
331
415
  end
@@ -350,4 +434,42 @@ class TestFakeWeb < Test::Unit::TestCase
350
434
  3.times { assert_equal 'thrice', Net::HTTP.get(uri) }
351
435
  4.times { assert_equal 'ever_more', Net::HTTP.get(uri) }
352
436
  end
437
+
438
+ def test_mock_request_using_response_with_transfer_encoding_header_has_valid_transfer_encoding_header
439
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_with_transfer_encoding')
440
+ response = nil
441
+ Net::HTTP.start('www.google.com') do |query|
442
+ response = query.get('/')
443
+ end
444
+ assert_not_nil response['transfer-encoding']
445
+ assert response['transfer-encoding'] == 'chunked'
446
+ end
447
+
448
+ def test_mock_request_using_response_without_transfer_encoding_header_does_not_have_a_transfer_encoding_header
449
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_without_transfer_encoding')
450
+ response = nil
451
+ Net::HTTP.start('www.google.com') do |query|
452
+ response = query.get('/')
453
+ end
454
+ assert !response.key?('transfer-encoding')
455
+ end
456
+
457
+ def test_mock_request_using_response_from_curl_has_original_transfer_encoding_header
458
+ FakeWeb.register_uri('http://www.google.com/', :response => File.dirname(__FILE__) + '/fixtures/google_response_from_curl')
459
+ response = nil
460
+ Net::HTTP.start('www.google.com') do |query|
461
+ response = query.get('/')
462
+ end
463
+ assert_not_nil response['transfer-encoding']
464
+ assert response['transfer-encoding'] == 'chunked'
465
+ end
466
+
467
+ def test_txt_file_should_have_three_lines
468
+ FakeWeb.register_uri('http://www.google.com/', :file => File.dirname(__FILE__) + '/fixtures/test_txt_file')
469
+ response = nil
470
+ Net::HTTP.start('www.google.com') do |query|
471
+ response = query.get('/')
472
+ end
473
+ assert response.body.split(/\n/).size == 3, "response has #{response.body.split(/\n/).size} lines should have 3"
474
+ end
353
475
  end