Blaine Cook
2006-May-23 23:35 UTC
[Rails] [ANN] FakeWeb test helper for Net::HTTP / open-uri web requests
Hey All, I''ve posted the first release of FakeWeb, a little library to help with all your http client testing needs. This helper makes it trivial to setup an idempodent environment for you to test any web service requests in your applications. Available on RubyForge, http://rubyforge.org/projects/fakeweb/ == Overview * Force Net::HTTP (and any dependent libraries, e.g. open-uri) to return arbitrary responses or exceptions for a given set of request URLs. * Speed up tests that involve remote HTTP round trips. * 100% C0 test coverage as reported by rcov * Works for all regular HTTP requests, as well as Proxied and HTTPS requests. == Two-line Example FakeWeb.register_uri("http://example.com/", :string => "Hello World") open("http://example.com/").string # => "Hello World" == Another Example FakeWeb.register_uri("http://example.com/", :response => `curl -i http://www.google.com/`) Net::HTTP.get_response("example.com", "/") # => Net::HTTPResponse equivalent to fetching http://www.google.com/ Versions 1.0.0 and 1.1.0 are available, the former works with Ruby 1.8.2, and the latter (and all subsequent releases) works with Ruby 1.8.4. See http://fakeweb.rubyforge.org/ for more information and documentation.