Permalink
Browse files

Note Patron support, and add demos showing usage of some other Net:HT…

…TP-based APIs.
  • Loading branch information...
1 parent 70a3888 commit affb7bd14d52967f361212a4ed13395ad65258ff @mdub committed Dec 22, 2010
Showing with 36 additions and 6 deletions.
  1. +35 −5 README.markdown
  2. +1 −1 lib/sham_rack/version.rb
View
@@ -1,14 +1,14 @@
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]
@@ -28,12 +28,12 @@ Using it
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
@@ -69,10 +69,38 @@ Or, just use Sinatra, as described above ... it's almost as succinct, and heaps
### When you're done testing
- ShamRack.unmount_all
+ 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?
-----------------
@@ -91,3 +119,5 @@ Thanks to
[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
View
@@ -1,3 +1,3 @@
module ShamRack
- VERSION = "1.3.3.dev"
+ VERSION = "1.3.3"
end

0 comments on commit affb7bd

Please sign in to comment.