README.rdoc in fakeweb-1.2.7 vs README.rdoc in fakeweb-1.2.8

- old
+ new

@@ -4,18 +4,15 @@ level, without modifying code or writing extensive stubs. == Installation -The latest release of FakeWeb is once again available from your friendly -RubyForge mirror. Just install the gem: + gem install fakeweb - sudo gem install fakeweb - Note: the gem was previously available as +FakeWeb+ (capital letters), but now all versions are simply registered as +fakeweb+. If you have any old +FakeWeb+ -gems lying around, remove them: <tt>sudo gem uninstall FakeWeb</tt> +gems lying around, remove them: <tt>gem uninstall FakeWeb</tt> == Help and discussion RDocs for the current release are available at http://fakeweb.rubyforge.org. @@ -27,11 +24,10 @@ == Examples Start by requiring FakeWeb: - require 'rubygems' require 'fakeweb' === Registering basic string responses FakeWeb.register_uri(:get, "http://example.com/test1", :body => "Hello World!") @@ -43,10 +39,15 @@ => FakeWeb is bypassed and the response from a real request is returned You can also call <tt>register_uri</tt> with a regular expression, to match more than one URI. + FakeWeb.register_uri(:get, %r|http://example\.com/|, :body => "Hello World!") + + Net::HTTP.get(URI.parse("http://example.com/test3")) + => "Hello World!" + === Replaying a recorded response page = `curl -is http://www.google.com/` FakeWeb.register_uri(:get, "http://www.google.com/", :response => page) @@ -69,21 +70,21 @@ FakeWeb.register_uri(:any, "http://example.com", :body => "response for any HTTP method") If you use the <tt>:any</tt> symbol, the URI you specify will be completely stubbed out (regardless of the HTTP method of the request). This can be useful -for RPC-like services, where the HTTP method isn't significant. (Older +for RPC-style services, where the HTTP method isn't significant. (Older versions of FakeWeb always behaved like this, and didn't accept the first +method+ argument above; this syntax is now deprecated.) === Rotating responses -You can optionally call FakeWeb.register_uri with an array of options hashes; -these are used, in order, to respond to repeated requests. Once you run out of -responses, further requests always receive the last response. (You can also send -a response more than once before rotating, by specifying a <tt>:times</tt> -option for that response.) +You can optionally call <tt>FakeWeb.register_uri</tt> with an array of options +hashes; these are used, in order, to respond to repeated requests. Once you run +out of responses, further requests always receive the last response. (You can +also send a response more than once before rotating, by specifying a +<tt>:times</tt> option for that response.) FakeWeb.register_uri(:delete, "http://example.com/posts/1", [{:body => "Post 1 deleted.", :status => ["200", "OK"]}, {:body => "Post not found", :status => ["404", "Not Found"]}]) @@ -93,12 +94,12 @@ req.delete("/posts/1").body # => "Post not found" end === Using HTTP basic authentication -You can stub requests that use basic authentication with +userinfo+ strings in -the URIs: +You can fake requests that use basic authentication by adding +userinfo+ strings +to your URIs: FakeWeb.register_uri(:get, "http://example.com/secret", :body => "Unauthorized", :status => ["401", "Unauthorized"]) FakeWeb.register_uri(:get, "http://user:pass@example.com/secret", :body => "Authorized") Net::HTTP.start("example.com") do |http| @@ -108,12 +109,12 @@ http.request(req) # => "Authorized" end === Clearing registered URIs -The FakeWeb registry is a singleton that lasts for the duration of your -program, maintaining every fake response you register. If needed, you -can clean out the registry and remove all registered URIs: +The FakeWeb registry is a singleton that lasts for the duration of your program, +maintaining every fake response you register. If needed, you can clean out the +registry and remove all registered URIs: FakeWeb.clean_registry === Blocking all real requests