public
Description: run Rack applications in-process, without a server
Homepage:
Clone URL: git://github.com/mdub/sham_rack.git
name age message
file .gitignore Wed Jun 03 04:20:50 -0700 2009 Prep for Rubyforge release. [mdub]
file CHANGES.markdown Fri Jun 05 01:47:31 -0700 2009 Pass back headers provided by Rack app in the H... [mdub]
file README.markdown Thu Jul 30 04:50:01 -0700 2009 Fix typo. [mdub]
file Rakefile Wed Jun 03 04:33:32 -0700 2009 RDoc tweaks prior to Rubyforge release. [mdub]
file VERSION.yml Fri Jun 05 01:51:30 -0700 2009 Version bump to 1.1.2 [mdub]
directory benchmark/ Sat Jun 27 05:05:33 -0700 2009 Compare performance of ShamRack vs running a Ra... [mdub]
directory lib/ Fri Jun 05 01:47:31 -0700 2009 Pass back headers provided by Rack app in the H... [mdub]
file sham_rack.gemspec Fri Jun 05 01:52:45 -0700 2009 Update gemspec. [mdub]
directory spec/ Fri Jun 05 01:47:31 -0700 2009 Pass back headers provided by Rack app in the H... [mdub]
README.markdown

ShamRack

ShamRack plumbs Net:HTTP into 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:

all without having to boot it in a server.

Installing it

gem sources -a http://gems.github.com
sudo gem install mdub-sham_rack

Using it

A simple inline application

require 'sham_rack'

ShamRack.at("www.example.com") do |env|
  ["200 OK", { "Content-type" => "text/plain" }, "Hello, world!"]
end

require 'open-uri'
open("http://www.example.com/").read            #=> "Hello, world!"

Sinatra integration

ShamRack.at("sinatra.xyz").sinatra do
  get "/hello/:subject" do
    "Hello, #{params[:subject]}"
  end
end

open("http://sinatra.xyz/hello/stranger").read  #=> "Hello, stranger"

Rackup support

ShamRack.at("rackup.xyz").rackup do
  use Some::Middleware
  use Some::Other::Middleware
  run MyApp.new
end

Any old app

ShamRack.mount(my_google_stub, "google.com")

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.

Thanks to

  • Blaine Cook for FakeWeb, which was an inspiration for ShamRack.
  • Perryn Fowler for his efforts plumbing Net::HTTP into ActionController::TestProcess.
  • Christian Neukirchen et al for the chewy goodness that is Rack.