benschwarz-smoke 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/Rakefile +47 -0
  2. data/VERSION.yml +2 -2
  3. data/lib/core_ext/string.rb +6 -0
  4. data/lib/smoke/cache.rb +38 -23
  5. data/lib/smoke/request.rb +4 -8
  6. data/lib/smoke.rb +7 -2
  7. data/rdoc/classes/Smoke/Origin.html +340 -0
  8. data/rdoc/classes/Smoke/Source/Data.html +126 -0
  9. data/rdoc/classes/Smoke/Source/Feed.html +117 -0
  10. data/rdoc/classes/Smoke/Source/YQL.html +223 -0
  11. data/rdoc/classes/Smoke.html +260 -0
  12. data/rdoc/created.rid +1 -0
  13. data/rdoc/files/README_markdown.html +180 -0
  14. data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
  15. data/rdoc/files/lib/smoke/origin_rb.html +49 -0
  16. data/rdoc/files/lib/smoke/request_rb.html +49 -0
  17. data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
  18. data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
  19. data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
  20. data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
  21. data/rdoc/files/lib/smoke_rb.html +65 -0
  22. data/rdoc/fr_class_index.html +21 -0
  23. data/rdoc/fr_file_index.html +28 -0
  24. data/rdoc/fr_method_index.html +4459 -0
  25. data/rdoc/index.html +15 -0
  26. data/rdoc/rdoc-style.css +319 -0
  27. data/spec/smoke/cache_spec.rb +28 -6
  28. data/vendor/crack/History +15 -0
  29. data/vendor/crack/LICENSE +20 -0
  30. data/vendor/crack/README.rdoc +42 -0
  31. data/vendor/crack/Rakefile +49 -0
  32. data/vendor/crack/VERSION.yml +4 -0
  33. data/vendor/crack/crack.gemspec +61 -0
  34. data/vendor/crack/lib/crack/core_extensions.rb +128 -0
  35. data/vendor/crack/lib/crack/json.rb +68 -0
  36. data/vendor/crack/lib/crack/xml.rb +214 -0
  37. data/vendor/crack/lib/crack.rb +7 -0
  38. data/vendor/crack/test/crack_test.rb +4 -0
  39. data/vendor/crack/test/data/twittersearch-firefox.json +1 -0
  40. data/vendor/crack/test/data/twittersearch-ie.json +1 -0
  41. data/vendor/crack/test/hash_test.rb +56 -0
  42. data/vendor/crack/test/json_test.rb +66 -0
  43. data/vendor/crack/test/string_test.rb +31 -0
  44. data/vendor/crack/test/test_helper.rb +12 -0
  45. data/vendor/crack/test/xml_test.rb +489 -0
  46. data/vendor/dependencies/README.markdown +113 -0
  47. data/vendor/dependencies/Rakefile +5 -0
  48. data/vendor/dependencies/bin/dep +83 -0
  49. data/vendor/dependencies/dependencies.gemspec +15 -0
  50. data/vendor/dependencies/dependencies.gemspec.erb +27 -0
  51. data/vendor/dependencies/lib/dependencies/dep.rb +99 -0
  52. data/vendor/dependencies/lib/dependencies.rb +5 -0
  53. data/vendor/dependencies/test/dependencies_test.rb +228 -0
  54. data/vendor/dependencies/test/foobaz-0.3.gem +0 -0
  55. data/vendor/fakeweb/CHANGELOG +163 -0
  56. data/vendor/fakeweb/LICENSE.txt +281 -0
  57. data/vendor/fakeweb/README.rdoc +193 -0
  58. data/vendor/fakeweb/Rakefile +76 -0
  59. data/vendor/fakeweb/fakeweb.gemspec +21 -0
  60. data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +71 -0
  61. data/vendor/fakeweb/lib/fake_web/registry.rb +103 -0
  62. data/vendor/fakeweb/lib/fake_web/responder.rb +113 -0
  63. data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
  64. data/vendor/fakeweb/lib/fake_web/stub_socket.rb +15 -0
  65. data/vendor/fakeweb/lib/fake_web/utility.rb +22 -0
  66. data/vendor/fakeweb/lib/fake_web.rb +172 -0
  67. data/vendor/fakeweb/lib/fakeweb.rb +2 -0
  68. data/vendor/fakeweb/test/fixtures/google_response_from_curl +12 -0
  69. data/vendor/fakeweb/test/fixtures/google_response_with_transfer_encoding +17 -0
  70. data/vendor/fakeweb/test/fixtures/google_response_without_transfer_encoding +11 -0
  71. data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
  72. data/vendor/fakeweb/test/fixtures/test_txt_file +3 -0
  73. data/vendor/fakeweb/test/test_allow_net_connect.rb +85 -0
  74. data/vendor/fakeweb/test/test_deprecations.rb +54 -0
  75. data/vendor/fakeweb/test/test_fake_authentication.rb +92 -0
  76. data/vendor/fakeweb/test/test_fake_web.rb +535 -0
  77. data/vendor/fakeweb/test/test_fake_web_open_uri.rb +58 -0
  78. data/vendor/fakeweb/test/test_helper.rb +74 -0
  79. data/vendor/fakeweb/test/test_missing_open_uri.rb +25 -0
  80. data/vendor/fakeweb/test/test_precedence.rb +51 -0
  81. data/vendor/fakeweb/test/test_query_string.rb +45 -0
  82. data/vendor/fakeweb/test/test_regexes.rb +103 -0
  83. data/vendor/fakeweb/test/test_response_headers.rb +73 -0
  84. data/vendor/fakeweb/test/test_trailing_slashes.rb +53 -0
  85. data/vendor/fakeweb/test/test_utility.rb +70 -0
  86. data/vendor/json-1.1.3/CHANGES +93 -0
  87. data/vendor/json-1.1.3/GPL +340 -0
  88. data/vendor/json-1.1.3/README +78 -0
  89. data/vendor/json-1.1.3/RUBY +58 -0
  90. data/vendor/json-1.1.3/Rakefile +309 -0
  91. data/vendor/json-1.1.3/TODO +1 -0
  92. data/vendor/json-1.1.3/VERSION +1 -0
  93. data/vendor/json-1.1.3/benchmarks/benchmark.txt +133 -0
  94. data/vendor/json-1.1.3/benchmarks/benchmark_generator.rb +48 -0
  95. data/vendor/json-1.1.3/benchmarks/benchmark_parser.rb +26 -0
  96. data/vendor/json-1.1.3/benchmarks/benchmark_rails.rb +26 -0
  97. data/vendor/json-1.1.3/bin/edit_json.rb +10 -0
  98. data/vendor/json-1.1.3/bin/prettify_json.rb +76 -0
  99. data/vendor/json-1.1.3/data/example.json +1 -0
  100. data/vendor/json-1.1.3/data/index.html +38 -0
  101. data/vendor/json-1.1.3/data/prototype.js +4184 -0
  102. data/vendor/json-1.1.3/ext/json/ext/generator/extconf.rb +9 -0
  103. data/vendor/json-1.1.3/ext/json/ext/generator/generator.c +875 -0
  104. data/vendor/json-1.1.3/ext/json/ext/generator/unicode.c +182 -0
  105. data/vendor/json-1.1.3/ext/json/ext/generator/unicode.h +53 -0
  106. data/vendor/json-1.1.3/ext/json/ext/parser/extconf.rb +9 -0
  107. data/vendor/json-1.1.3/ext/json/ext/parser/parser.c +1758 -0
  108. data/vendor/json-1.1.3/ext/json/ext/parser/parser.rl +638 -0
  109. data/vendor/json-1.1.3/ext/json/ext/parser/unicode.c +154 -0
  110. data/vendor/json-1.1.3/ext/json/ext/parser/unicode.h +58 -0
  111. data/vendor/json-1.1.3/install.rb +26 -0
  112. data/vendor/json-1.1.3/lib/json/Array.xpm +21 -0
  113. data/vendor/json-1.1.3/lib/json/FalseClass.xpm +21 -0
  114. data/vendor/json-1.1.3/lib/json/Hash.xpm +21 -0
  115. data/vendor/json-1.1.3/lib/json/Key.xpm +73 -0
  116. data/vendor/json-1.1.3/lib/json/NilClass.xpm +21 -0
  117. data/vendor/json-1.1.3/lib/json/Numeric.xpm +28 -0
  118. data/vendor/json-1.1.3/lib/json/String.xpm +96 -0
  119. data/vendor/json-1.1.3/lib/json/TrueClass.xpm +21 -0
  120. data/vendor/json-1.1.3/lib/json/add/core.rb +135 -0
  121. data/vendor/json-1.1.3/lib/json/add/rails.rb +58 -0
  122. data/vendor/json-1.1.3/lib/json/common.rb +354 -0
  123. data/vendor/json-1.1.3/lib/json/editor.rb +1362 -0
  124. data/vendor/json-1.1.3/lib/json/ext.rb +13 -0
  125. data/vendor/json-1.1.3/lib/json/json.xpm +1499 -0
  126. data/vendor/json-1.1.3/lib/json/pure/generator.rb +394 -0
  127. data/vendor/json-1.1.3/lib/json/pure/parser.rb +259 -0
  128. data/vendor/json-1.1.3/lib/json/pure.rb +75 -0
  129. data/vendor/json-1.1.3/lib/json/version.rb +9 -0
  130. data/vendor/json-1.1.3/lib/json.rb +235 -0
  131. data/vendor/json-1.1.3/tests/fixtures/fail1.json +1 -0
  132. data/vendor/json-1.1.3/tests/fixtures/fail10.json +1 -0
  133. data/vendor/json-1.1.3/tests/fixtures/fail11.json +1 -0
  134. data/vendor/json-1.1.3/tests/fixtures/fail12.json +1 -0
  135. data/vendor/json-1.1.3/tests/fixtures/fail13.json +1 -0
  136. data/vendor/json-1.1.3/tests/fixtures/fail14.json +1 -0
  137. data/vendor/json-1.1.3/tests/fixtures/fail18.json +1 -0
  138. data/vendor/json-1.1.3/tests/fixtures/fail19.json +1 -0
  139. data/vendor/json-1.1.3/tests/fixtures/fail2.json +1 -0
  140. data/vendor/json-1.1.3/tests/fixtures/fail20.json +1 -0
  141. data/vendor/json-1.1.3/tests/fixtures/fail21.json +1 -0
  142. data/vendor/json-1.1.3/tests/fixtures/fail22.json +1 -0
  143. data/vendor/json-1.1.3/tests/fixtures/fail23.json +1 -0
  144. data/vendor/json-1.1.3/tests/fixtures/fail24.json +1 -0
  145. data/vendor/json-1.1.3/tests/fixtures/fail25.json +1 -0
  146. data/vendor/json-1.1.3/tests/fixtures/fail27.json +2 -0
  147. data/vendor/json-1.1.3/tests/fixtures/fail28.json +2 -0
  148. data/vendor/json-1.1.3/tests/fixtures/fail3.json +1 -0
  149. data/vendor/json-1.1.3/tests/fixtures/fail4.json +1 -0
  150. data/vendor/json-1.1.3/tests/fixtures/fail5.json +1 -0
  151. data/vendor/json-1.1.3/tests/fixtures/fail6.json +1 -0
  152. data/vendor/json-1.1.3/tests/fixtures/fail7.json +1 -0
  153. data/vendor/json-1.1.3/tests/fixtures/fail8.json +1 -0
  154. data/vendor/json-1.1.3/tests/fixtures/fail9.json +1 -0
  155. data/vendor/json-1.1.3/tests/fixtures/pass1.json +56 -0
  156. data/vendor/json-1.1.3/tests/fixtures/pass15.json +1 -0
  157. data/vendor/json-1.1.3/tests/fixtures/pass16.json +1 -0
  158. data/vendor/json-1.1.3/tests/fixtures/pass17.json +1 -0
  159. data/vendor/json-1.1.3/tests/fixtures/pass2.json +1 -0
  160. data/vendor/json-1.1.3/tests/fixtures/pass26.json +1 -0
  161. data/vendor/json-1.1.3/tests/fixtures/pass3.json +6 -0
  162. data/vendor/json-1.1.3/tests/runner.rb +25 -0
  163. data/vendor/json-1.1.3/tests/test_json.rb +293 -0
  164. data/vendor/json-1.1.3/tests/test_json_addition.rb +161 -0
  165. data/vendor/json-1.1.3/tests/test_json_fixtures.rb +30 -0
  166. data/vendor/json-1.1.3/tests/test_json_generate.rb +100 -0
  167. data/vendor/json-1.1.3/tests/test_json_rails.rb +118 -0
  168. data/vendor/json-1.1.3/tests/test_json_unicode.rb +61 -0
  169. data/vendor/json-1.1.3/tools/fuzz.rb +140 -0
  170. data/vendor/json-1.1.3/tools/server.rb +62 -0
  171. data/vendor/moneta/LICENSE +20 -0
  172. data/vendor/moneta/README +51 -0
  173. data/vendor/moneta/Rakefile +60 -0
  174. data/vendor/moneta/TODO +4 -0
  175. data/vendor/moneta/benchmarks/various.rb +234 -0
  176. data/vendor/moneta/lib/moneta/basic_file.rb +111 -0
  177. data/vendor/moneta/lib/moneta/berkeley.rb +53 -0
  178. data/vendor/moneta/lib/moneta/couch.rb +63 -0
  179. data/vendor/moneta/lib/moneta/datamapper.rb +117 -0
  180. data/vendor/moneta/lib/moneta/file.rb +91 -0
  181. data/vendor/moneta/lib/moneta/lmc.rb +52 -0
  182. data/vendor/moneta/lib/moneta/memcache.rb +53 -0
  183. data/vendor/moneta/lib/moneta/memory.rb +11 -0
  184. data/vendor/moneta/lib/moneta/mongodb.rb +58 -0
  185. data/vendor/moneta/lib/moneta/redis.rb +49 -0
  186. data/vendor/moneta/lib/moneta/rufus.rb +41 -0
  187. data/vendor/moneta/lib/moneta/s3.rb +162 -0
  188. data/vendor/moneta/lib/moneta/sdbm.rb +33 -0
  189. data/vendor/moneta/lib/moneta/tyrant.rb +58 -0
  190. data/vendor/moneta/lib/moneta/xattr.rb +58 -0
  191. data/vendor/moneta/lib/moneta.rb +76 -0
  192. data/vendor/moneta/moneta.gemspec +32 -0
  193. data/vendor/moneta/script/destroy +14 -0
  194. data/vendor/moneta/script/generate +14 -0
  195. data/vendor/moneta/spec/moneta_basic_file_spec.rb +50 -0
  196. data/vendor/moneta/spec/moneta_berkeley_spec.rb +20 -0
  197. data/vendor/moneta/spec/moneta_couch_spec.rb +22 -0
  198. data/vendor/moneta/spec/moneta_datamapper_spec.rb +79 -0
  199. data/vendor/moneta/spec/moneta_file_spec.rb +21 -0
  200. data/vendor/moneta/spec/moneta_lmc_spec.rb +24 -0
  201. data/vendor/moneta/spec/moneta_memcache_spec.rb +16 -0
  202. data/vendor/moneta/spec/moneta_memory_spec.rb +12 -0
  203. data/vendor/moneta/spec/moneta_mongodb_spec.rb +16 -0
  204. data/vendor/moneta/spec/moneta_redis_spec.rb +16 -0
  205. data/vendor/moneta/spec/moneta_rufus_spec.rb +15 -0
  206. data/vendor/moneta/spec/moneta_s3_spec.rb +19 -0
  207. data/vendor/moneta/spec/moneta_sdbm_spec.rb +21 -0
  208. data/vendor/moneta/spec/moneta_tyrant_spec.rb +15 -0
  209. data/vendor/moneta/spec/moneta_xattr_spec.rb +21 -0
  210. data/vendor/moneta/spec/shared.rb +122 -0
  211. data/vendor/moneta/spec/spec_helper.rb +7 -0
  212. data/vendor/rest-client/README.rdoc +151 -0
  213. data/vendor/rest-client/Rakefile +58 -0
  214. data/vendor/rest-client/VERSION +1 -0
  215. data/vendor/rest-client/bin/restclient +87 -0
  216. data/vendor/rest-client/lib/rest_client.rb +2 -0
  217. data/vendor/rest-client/lib/restclient/exceptions.rb +88 -0
  218. data/vendor/rest-client/lib/restclient/mixin/response.rb +43 -0
  219. data/vendor/rest-client/lib/restclient/raw_response.rb +30 -0
  220. data/vendor/rest-client/lib/restclient/request.rb +238 -0
  221. data/vendor/rest-client/lib/restclient/resource.rb +146 -0
  222. data/vendor/rest-client/lib/restclient/response.rb +20 -0
  223. data/vendor/rest-client/lib/restclient.rb +99 -0
  224. data/vendor/rest-client/rest-client.gemspec +66 -0
  225. data/vendor/rest-client/spec/base.rb +4 -0
  226. data/vendor/rest-client/spec/exceptions_spec.rb +65 -0
  227. data/vendor/rest-client/spec/mixin/response_spec.rb +46 -0
  228. data/vendor/rest-client/spec/raw_response_spec.rb +17 -0
  229. data/vendor/rest-client/spec/request_spec.rb +476 -0
  230. data/vendor/rest-client/spec/resource_spec.rb +75 -0
  231. data/vendor/rest-client/spec/response_spec.rb +16 -0
  232. data/vendor/rest-client/spec/restclient_spec.rb +53 -0
  233. data/vendor/simple-rss/LICENSE +429 -0
  234. data/vendor/simple-rss/README +43 -0
  235. data/vendor/simple-rss/Rakefile +212 -0
  236. data/vendor/simple-rss/install.rb +40 -0
  237. data/vendor/simple-rss/lib/simple-rss.rb +150 -0
  238. data/vendor/simple-rss/simple-rss.gemspec +12 -0
  239. data/vendor/simple-rss/test/base/base_test.rb +51 -0
  240. data/vendor/simple-rss/test/data/atom.xml +45 -0
  241. data/vendor/simple-rss/test/data/not-rss.xml +8 -0
  242. data/vendor/simple-rss/test/data/rss09.rdf +79 -0
  243. data/vendor/simple-rss/test/data/rss20.xml +818 -0
  244. data/vendor/simple-rss/test/test_helper.rb +4 -0
  245. metadata +314 -40
@@ -0,0 +1,103 @@
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 { |hash, key| hash[key] = {} }
13
+ end
14
+
15
+ def register_uri(method, uri, options)
16
+ uri_map[normalize_uri(uri)][method] = [*[options]].flatten.collect do |option|
17
+ FakeWeb::Responder.new(method, uri, option, option[:times])
18
+ end
19
+ end
20
+
21
+ def registered_uri?(method, uri)
22
+ normalized_uri = normalize_uri(uri)
23
+ !responses_for(method, uri).empty?
24
+ end
25
+
26
+ def response_for(method, uri, &block)
27
+ responses = responses_for(method, uri)
28
+ return nil if responses.empty?
29
+
30
+ next_response = responses.last
31
+ responses.each do |response|
32
+ if response.times and response.times > 0
33
+ response.times -= 1
34
+ next_response = response
35
+ break
36
+ end
37
+ end
38
+
39
+ next_response.response(&block)
40
+ end
41
+
42
+
43
+ private
44
+
45
+ def responses_for(method, uri)
46
+ uri = normalize_uri(uri)
47
+
48
+ if uri_map[uri].has_key?(method)
49
+ uri_map[uri][method]
50
+ elsif uri_map[uri].has_key?(:any)
51
+ uri_map[uri][:any]
52
+ elsif uri_map_matches?(method, uri)
53
+ uri_map_matches(method, uri)
54
+ elsif uri_map_matches(:any, uri)
55
+ uri_map_matches(:any, uri)
56
+ else
57
+ []
58
+ end
59
+ end
60
+
61
+ def uri_map_matches?(method, uri)
62
+ !uri_map_matches(method, uri).nil?
63
+ end
64
+
65
+ def uri_map_matches(method, uri)
66
+ uri = normalize_uri(uri.to_s).to_s
67
+ uri = Utility.strip_default_port_from_uri(uri)
68
+
69
+ matches = uri_map.select { |registered_uri, method_hash|
70
+ registered_uri.is_a?(Regexp) && uri.match(registered_uri) && method_hash.has_key?(method)
71
+ }
72
+
73
+ if matches.size > 1
74
+ raise MultipleMatchingRegexpsError,
75
+ "More than one regular expression matched this request: #{method.to_s.upcase} #{uri}"
76
+ end
77
+
78
+ matches.map { |_, method_hash| method_hash[method] }.first
79
+ end
80
+
81
+ def normalize_uri(uri)
82
+ return uri if uri.is_a?(Regexp)
83
+ normalized_uri =
84
+ case uri
85
+ when URI then uri
86
+ when String
87
+ uri = 'http://' + uri unless uri.match('^https?://')
88
+ URI.parse(uri)
89
+ end
90
+ normalized_uri.query = sort_query_params(normalized_uri.query)
91
+ normalized_uri.normalize
92
+ end
93
+
94
+ def sort_query_params(query)
95
+ if query.nil? || query.empty?
96
+ nil
97
+ else
98
+ query.split('&').sort.join('&')
99
+ end
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,113 @@
1
+ module FakeWeb
2
+ class Responder #:nodoc:
3
+
4
+ attr_accessor :method, :uri, :options, :times
5
+ KNOWN_OPTIONS = [:body, :exception, :response, :status].freeze
6
+
7
+ def initialize(method, uri, options, times)
8
+ self.method = method
9
+ self.uri = uri
10
+ self.options = options
11
+ self.times = times ? times : 1
12
+
13
+ if options.has_key?(:file) || options.has_key?(:string)
14
+ print_file_string_options_deprecation_warning
15
+ options[:body] = options.delete(:file) || options.delete(:string)
16
+ end
17
+ end
18
+
19
+ def response(&block)
20
+ if has_baked_response?
21
+ response = baked_response
22
+ else
23
+ code, msg = meta_information
24
+ response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
25
+ response.instance_variable_set(:@body, body)
26
+ headers_extracted_from_options.each { |name, value| response[name] = value }
27
+ end
28
+
29
+ response.instance_variable_set(:@read, true)
30
+ response.extend FakeWeb::Response
31
+
32
+ optionally_raise(response)
33
+
34
+ yield response if block_given?
35
+
36
+ response
37
+ end
38
+
39
+ private
40
+
41
+ def headers_extracted_from_options
42
+ options.reject {|name, _| KNOWN_OPTIONS.include?(name) }.map { |name, value|
43
+ [name.to_s.split("_").map { |segment| segment.capitalize }.join("-"), value]
44
+ }
45
+ end
46
+
47
+ def body
48
+ return '' unless options.has_key?(:body)
49
+
50
+ if !options[:body].include?("\0") && File.exists?(options[:body]) && !File.directory?(options[:body])
51
+ File.read(options[:body])
52
+ else
53
+ options[:body]
54
+ end
55
+ end
56
+
57
+ def baked_response
58
+ resp = case options[:response]
59
+ when Net::HTTPResponse then options[:response]
60
+ when String
61
+ socket = Net::BufferedIO.new(options[:response])
62
+ r = Net::HTTPResponse.read_new(socket)
63
+
64
+ # Store the oiriginal transfer-encoding
65
+ saved_transfer_encoding = r.instance_eval {
66
+ @header['transfer-encoding'] if @header.key?('transfer-encoding')
67
+ }
68
+
69
+ # read the body of response.
70
+ r.instance_eval { @header['transfer-encoding'] = nil }
71
+ r.reading_body(socket, true) {}
72
+
73
+ # Delete the transfer-encoding key from r.@header if there wasn't one,
74
+ # else restore the saved_transfer_encoding.
75
+ if saved_transfer_encoding.nil?
76
+ r.instance_eval { @header.delete('transfer-encoding') }
77
+ else
78
+ r.instance_eval { @header['transfer-encoding'] = saved_transfer_encoding }
79
+ end
80
+ r
81
+ else raise StandardError, "Handler unimplemented for response #{options[:response]}"
82
+ end
83
+ end
84
+
85
+ def has_baked_response?
86
+ options.has_key?(:response)
87
+ end
88
+
89
+ def optionally_raise(response)
90
+ return unless options.has_key?(:exception)
91
+
92
+ case options[:exception].to_s
93
+ when "Net::HTTPError", "OpenURI::HTTPError"
94
+ raise options[:exception].new('Exception from FakeWeb', response)
95
+ else
96
+ raise options[:exception].new('Exception from FakeWeb')
97
+ end
98
+ end
99
+
100
+ def meta_information
101
+ options.has_key?(:status) ? options[:status] : [200, 'OK']
102
+ end
103
+
104
+ def print_file_string_options_deprecation_warning
105
+ which = options.has_key?(:file) ? :file : :string
106
+ $stderr.puts
107
+ $stderr.puts "Deprecation warning: FakeWeb's :#{which} option has been renamed to :body."
108
+ $stderr.puts "Just replace :#{which} with :body in your FakeWeb.register_uri calls."
109
+ $stderr.puts "Called at #{caller[6]}"
110
+ end
111
+
112
+ end
113
+ 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,15 @@
1
+ module FakeWeb
2
+ class StubSocket #:nodoc:
3
+
4
+ def initialize(*args)
5
+ end
6
+
7
+ def closed?
8
+ @closed ||= true
9
+ end
10
+
11
+ def readuntil(*args)
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module FakeWeb
2
+ module Utility #:nodoc:
3
+
4
+ def self.decode_userinfo_from_header(header)
5
+ header.sub(/^Basic /, "").unpack("m").first
6
+ end
7
+
8
+ def self.encode_unsafe_chars_in_userinfo(userinfo)
9
+ unsafe_in_userinfo = /[^#{URI::REGEXP::PATTERN::UNRESERVED};&=+$,]|^(#{URI::REGEXP::PATTERN::ESCAPED})/
10
+ userinfo.split(":").map { |part| URI.escape(part, unsafe_in_userinfo) }.join(":")
11
+ end
12
+
13
+ def self.strip_default_port_from_uri(uri)
14
+ case uri
15
+ when %r{^http://} then uri.sub(%r{:80(/|$)}, '\1')
16
+ when %r{^https://} then uri.sub(%r{:443(/|$)}, '\1')
17
+ else uri
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,172 @@
1
+ require 'singleton'
2
+
3
+ require 'fake_web/ext/net_http'
4
+ require 'fake_web/registry'
5
+ require 'fake_web/response'
6
+ require 'fake_web/responder'
7
+ require 'fake_web/stub_socket'
8
+ require 'fake_web/utility'
9
+
10
+ module FakeWeb
11
+
12
+ # Resets the FakeWeb Registry. This will force all subsequent web requests to
13
+ # behave as real requests.
14
+ def self.clean_registry
15
+ Registry.instance.clean_registry
16
+ end
17
+
18
+ # Enables or disables real HTTP connections for requests that don't match
19
+ # registered URIs.
20
+ #
21
+ # If you set <tt>FakeWeb.allow_net_connect = false</tt> and subsequently try
22
+ # to make a request to a URI you haven't registered with #register_uri, a
23
+ # NetConnectNotAllowedError will be raised. This is handy when you want to
24
+ # make sure your tests are self-contained, or want to catch the scenario
25
+ # when a URI is changed in implementation code without a corresponding test
26
+ # change.
27
+ #
28
+ # When <tt>FakeWeb.allow_net_connect = true</tt> (the default), requests to
29
+ # URIs not stubbed with FakeWeb are passed through to Net::HTTP.
30
+ def self.allow_net_connect=(allowed)
31
+ @allow_net_connect = allowed
32
+ end
33
+
34
+ # Enable pass-through to Net::HTTP by default.
35
+ self.allow_net_connect = true
36
+
37
+ # Returns +true+ if requests to URIs not registered with FakeWeb are passed
38
+ # through to Net::HTTP for normal processing (the default). Returns +false+
39
+ # if an exception is raised for these requests.
40
+ def self.allow_net_connect?
41
+ @allow_net_connect
42
+ end
43
+
44
+ # This exception is raised if you set <tt>FakeWeb.allow_net_connect =
45
+ # false</tt> and subsequently try to make a request to a URI you haven't
46
+ # stubbed.
47
+ class NetConnectNotAllowedError < StandardError; end;
48
+
49
+ # This exception is raised if a Net::HTTP request matches more than one of
50
+ # the regular expression-based stubs you've registered. To fix the problem,
51
+ # disambiguate the regular expressions by making them more specific.
52
+ class MultipleMatchingRegexpsError < StandardError; end;
53
+
54
+ # call-seq:
55
+ # FakeWeb.register_uri(method, uri, options)
56
+ #
57
+ # Register requests using the HTTP method specified by the symbol +method+
58
+ # for +uri+ to be handled according to +options+. If you specify the method
59
+ # <tt>:any</tt>, the response will be reigstered for any request for +uri+.
60
+ # +uri+ can be a +String+, +URI+, or +Regexp+ object. +options+ must be either
61
+ # a +Hash+ or an +Array+ of +Hashes+ (see below), which must contain one of
62
+ # these two keys:
63
+ #
64
+ # <tt>:body</tt>::
65
+ # A string which is used as the body of the response. If the string refers
66
+ # to a valid filesystem path, the contents of that file will be read and used
67
+ # as the body of the response instead. (This used to be two options,
68
+ # <tt>:string</tt> and <tt>:file</tt>, respectively. These are now deprecated.)
69
+ # <tt>:response</tt>::
70
+ # Either an <tt>Net::HTTPResponse</tt>, an +IO+, or a +String+ which is used
71
+ # as the full response for the request.
72
+ #
73
+ # The easier way by far is to pass the <tt>:response</tt> option to
74
+ # +register_uri+ as a +String+ or an (open for reads) +IO+ object which
75
+ # will be used as the complete HTTP response, including headers and body.
76
+ # If the string points to a readable file, this file will be used as the
77
+ # content for the request.
78
+ #
79
+ # To obtain a complete response document, you can use the +curl+ command,
80
+ # like so:
81
+ #
82
+ # curl -i http://www.example.com/ > response_for_www.example.com
83
+ #
84
+ # which can then be used in your test environment like so:
85
+ #
86
+ # FakeWeb.register_uri(:get, 'http://www.example.com/', :response => 'response_for_www.example.com')
87
+ #
88
+ # See the <tt>Net::HTTPResponse</tt>
89
+ # documentation[http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTPResponse.html]
90
+ # for more information on creating custom response objects.
91
+ #
92
+ # +options+ may also be an +Array+ containing a list of the above-described
93
+ # +Hash+. In this case, FakeWeb will rotate through each provided response,
94
+ # you may optionally provide:
95
+ #
96
+ # <tt>:times</tt>::
97
+ # The number of times this response will be used. Decremented by one each time it's called.
98
+ # FakeWeb will use the final provided request indefinitely, regardless of its :times parameter.
99
+ #
100
+ # Two optional arguments are also accepted:
101
+ #
102
+ # <tt>:status</tt>::
103
+ # Passing <tt>:status</tt> as a two-value array will set the response code
104
+ # and message. The defaults are <tt>200</tt> and <tt>OK</tt>, respectively.
105
+ # Example:
106
+ # FakeWeb.register_uri("http://www.example.com/", :body => "Go away!", :status => [404, "Not Found"])
107
+ # <tt>:exception</tt>::
108
+ # The argument passed via <tt>:exception</tt> will be raised when the
109
+ # specified URL is requested. Any +Exception+ class is valid. Example:
110
+ # FakeWeb.register_uri('http://www.example.com/', :exception => Net::HTTPError)
111
+ #
112
+ # If you're using the <tt>:body</tt> response type, you can pass additional
113
+ # options to specify the HTTP headers to be used in the response. Example:
114
+ #
115
+ # FakeWeb.register_uri(:get, "http://example.com/index.txt", :body => "Hello", :content_type => "text/plain")
116
+ def self.register_uri(*args)
117
+ case args.length
118
+ when 3
119
+ Registry.instance.register_uri(*args)
120
+ when 2
121
+ print_missing_http_method_deprecation_warning(*args)
122
+ Registry.instance.register_uri(:any, *args)
123
+ else
124
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 3)")
125
+ end
126
+ end
127
+
128
+ # call-seq:
129
+ # FakeWeb.response_for(method, uri)
130
+ #
131
+ # Returns the faked Net::HTTPResponse object associated with +method+ and +uri+.
132
+ def self.response_for(*args, &block) #:nodoc: :yields: response
133
+ case args.length
134
+ when 2
135
+ Registry.instance.response_for(*args, &block)
136
+ when 1
137
+ print_missing_http_method_deprecation_warning(*args)
138
+ Registry.instance.response_for(:any, *args, &block)
139
+ else
140
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 2)")
141
+ end
142
+ end
143
+
144
+ # call-seq:
145
+ # FakeWeb.registered_uri?(method, uri)
146
+ #
147
+ # Returns true if a +method+ request for +uri+ is registered with FakeWeb.
148
+ # Specify a method of <tt>:any</tt> to check for against all HTTP methods.
149
+ def self.registered_uri?(*args)
150
+ case args.length
151
+ when 2
152
+ Registry.instance.registered_uri?(*args)
153
+ when 1
154
+ print_missing_http_method_deprecation_warning(*args)
155
+ Registry.instance.registered_uri?(:any, *args)
156
+ else
157
+ raise ArgumentError.new("wrong number of arguments (#{args.length} for 2)")
158
+ end
159
+ end
160
+
161
+ private
162
+
163
+ def self.print_missing_http_method_deprecation_warning(*args)
164
+ method = caller.first.match(/`(.*?)'/)[1]
165
+ new_args = args.map { |a| a.inspect }.unshift(":any")
166
+ new_args.last.gsub!(/^\{|\}$/, "").gsub!("=>", " => ") if args.last.is_a?(Hash)
167
+ $stderr.puts
168
+ $stderr.puts "Deprecation warning: FakeWeb requires an HTTP method argument (or use :any). Try this:"
169
+ $stderr.puts " FakeWeb.#{method}(#{new_args.join(', ')})"
170
+ $stderr.puts "Called at #{caller[1]}"
171
+ end
172
+ end
@@ -0,0 +1,2 @@
1
+ # So you can require "fakeweb" instead of "fake_web"
2
+ require "fake_web"
@@ -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 @@
1
+ test example content
@@ -0,0 +1,3 @@
1
+ line 1
2
+ line 2
3
+ line 3
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class TestFakeWebAllowNetConnect < Test::Unit::TestCase
4
+
5
+ def test_unregistered_requests_are_passed_through_when_allow_net_connect_is_true
6
+ FakeWeb.allow_net_connect = true
7
+ setup_expectations_for_real_apple_hot_news_request
8
+ Net::HTTP.get(URI.parse("http://images.apple.com/main/rss/hotnews/hotnews.rss"))
9
+ end
10
+
11
+ def test_raises_for_unregistered_requests_when_allow_net_connect_is_false
12
+ FakeWeb.allow_net_connect = false
13
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
14
+ Net::HTTP.get(URI.parse("http://example.com/"))
15
+ end
16
+ end
17
+
18
+ def test_exception_message_includes_unregistered_request_method_and_uri_but_no_default_port
19
+ FakeWeb.allow_net_connect = false
20
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
21
+ Net::HTTP.get(URI.parse("http://example.com/"))
22
+ end
23
+ assert exception.message.include?("GET http://example.com/")
24
+
25
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
26
+ http = Net::HTTP.new("example.com", 443)
27
+ http.use_ssl = true
28
+ http.get("/")
29
+ end
30
+ assert exception.message.include?("GET https://example.com/")
31
+ end
32
+
33
+ def test_exception_message_includes_unregistered_request_port_when_not_default
34
+ FakeWeb.allow_net_connect = false
35
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
36
+ Net::HTTP.start("example.com", 8000) { |http| http.get("/") }
37
+ end
38
+ assert exception.message.include?("GET http://example.com:8000/")
39
+
40
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
41
+ http = Net::HTTP.new("example.com", 4433)
42
+ http.use_ssl = true
43
+ http.get("/")
44
+ end
45
+ assert exception.message.include?("GET https://example.com:4433/")
46
+ end
47
+
48
+ def test_exception_message_includes_unregistered_request_port_when_not_default_with_path
49
+ FakeWeb.allow_net_connect = false
50
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
51
+ Net::HTTP.start("example.com", 8000) { |http| http.get("/test") }
52
+ end
53
+ assert exception.message.include?("GET http://example.com:8000/test")
54
+
55
+ exception = assert_raise FakeWeb::NetConnectNotAllowedError do
56
+ http = Net::HTTP.new("example.com", 4433)
57
+ http.use_ssl = true
58
+ http.get("/test")
59
+ end
60
+ assert exception.message.include?("GET https://example.com:4433/test")
61
+ end
62
+
63
+ def test_question_mark_method_returns_true_after_setting_allow_net_connect_to_true
64
+ FakeWeb.allow_net_connect = true
65
+ assert FakeWeb.allow_net_connect?
66
+ end
67
+
68
+ def test_question_mark_method_returns_false_after_setting_allow_net_connect_to_false
69
+ FakeWeb.allow_net_connect = false
70
+ assert !FakeWeb.allow_net_connect?
71
+ end
72
+
73
+ end
74
+
75
+
76
+ class TestFakeWebAllowNetConnectWithCleanState < Test::Unit::TestCase
77
+ # Our test_helper.rb sets allow_net_connect = false in an inherited #setup
78
+ # method. Disable that here to test the default setting.
79
+ def setup; end
80
+ def teardown; end
81
+
82
+ def test_allow_net_connect_is_true_by_default
83
+ assert FakeWeb.allow_net_connect?
84
+ end
85
+ end