ShamRack
ShamRack plumbs Net:HTTP into Rack, providing infrastructure for testing arbitrary Rack-based apps using arbitrary HTTP clients, all from the comfort of your own Ruby VM.
What's it for, again?
Well, you can test your HTTP client code, using ShamRack to fake out an external web-service (Sinatra helps, here).
Or, you can ShamRack.mount your actual Sinatra/Rails/Merb/Rack app, which is handy if you want to test access using an HTTP client library such as:
Installing it
gem sources -a http://gems.github.com
sudo gem install mdub-sham_rack
Using it
require 'sham_rack'
rack_app = lambda { |env| ["200 OK", { "Content-type" => "text/plain" }, "Hello, world!"] }
ShamRack.mount(rack_app, "www.example.com")
require 'open-uri'
open("http://www.example.com/").read #=> "Hello, world!"
Sinatra integration
ShamRack.sinatra("sinatra.xyz") do
get "/hello/:subject" do
"Hello, #{params[:subject]}"
end
end
open("http://sinatra.xyz/hello/stranger").read #=> "Hello, stranger"
Rackup support
ShamRack.rackup("rackup.xyz") do
use Some::Middleware
use Some::Other::Middleware
run MyApp.new
end
What's the catch?
- It's brand new! (there will be dragons)
- Your Rack request-handling code runs in the same Ruby VM, in fact the same Thread, as your request.