README.markdown in sham_rack-1.3.2 vs README.markdown in sham_rack-1.3.3

- old
+ new

@@ -1,16 +1,16 @@ ShamRack ======== -ShamRack plumbs Net:HTTP into [Rack][rack]. +ShamRack plumbs HTTP requests into [Rack][rack]. What's it for, again? --------------------- Well, it makes it easy to _stub out external (HTTP) services_, which is handy in development and testing environments, or when you want to _test your HTTP client code_. -You can also use it to _test your Rack application_ (or Sinatra, or Rails, or Merb) using arbitrary HTTP client libraries, to check interoperability. For instance, you could test your app using: +You can also use it to _test your Rack application_ (or Sinatra, or Rails, or Merb) using a variety of HTTP client libraries, to check interoperability. For instance, you could test your app using: * [`rest-client`][rest-client] * [`httparty`][httparty] * [`oauth`][oauth] @@ -26,16 +26,16 @@ ### A simple inline application require 'sham_rack' - ShamRack.at("www.example.com") do |env| + ShamRack.at("www.greetings.com") do |env| ["200 OK", { "Content-type" => "text/plain" }, "Hello, world!"] end require 'open-uri' - open("http://www.example.com/").read #=> "Hello, world!" + open("http://www.greetings.com/").read #=> "Hello, world!" ### Sinatra integration ShamRack.at("sinatra.xyz").sinatra do get "/hello/:subject" do @@ -65,10 +65,44 @@ open("http://stubbed.com/greeting").read #=> "Hello, world!" @stub_app.last_request.path #=> "/greeting" Or, just use Sinatra, as described above ... it's almost as succinct, and heaps more powerful. +### When you're done testing + + ShamRack.unmount_all + + open("http://stubbed.com/greeting").read #=> OpenURI::HTTPError + +Supported HTTP client libraries +------------------------------- + +### Net::HTTP and friends + +ShamRack supports requests made using Net::HTTP, or any of the numerous APIs built on top of it: + + uri = URI.parse("http://www.greetings.com/") + Net::HTTP.get_response(uri).body #=> "Hello, world!" + + require 'open-uri' + open("http://www.greetings.com/").read #=> "Hello, world!" + + require 'restclient' + RestClient.get("http://www.greetings.com/").to_s #=> "Hello, world!" + + require 'mechanize' + Mechanize.new.get("http://www.greetings.com/").body #=> "Hello, world!" + +### Patron (experimental) + +We've recently added support for [Patron][patron]: + + require 'sham_rack/patron' + + patron = Patron::Session.new + patron.get("http://www.greetings.com/").body #=> "Hello, world!" + What's the catch? ----------------- * Your Rack request-handling code runs in the same Ruby VM, in fact the same Thread, as your request. @@ -83,5 +117,7 @@ [sinatra]: http://www.sinatrarb.com/ [rest-client]: http://github.com/adamwiggins/rest-client [httparty]: http://github.com/jnunemaker/httparty [oauth]: http://oauth.rubyforge.org/ [fakeweb]: http://fakeweb.rubyforge.org/ +[mechanize]: http://mechanize.rubyforge.org +[patron]: http://github.com/toland/Patron