Permalink
Browse files

Add some sugar for mounting plain Rack apps.

Before:

    ShamRack.mount(app, address)

After:

    ShamRack.at(address).run(app)
  • Loading branch information...
1 parent d0702fa commit e74a03d740917ed00fe93f765fdff15aad02a51c @mdub committed Apr 4, 2013
Showing with 21 additions and 6 deletions.
  1. +2 −2 README.markdown
  2. +7 −4 lib/sham_rack/registry.rb
  3. +12 −0 spec/sham_rack_spec.rb
View
@@ -53,9 +53,9 @@ Using it
run MyApp.new
end
-### Any old app
+### Any old Rack app
- ShamRack.mount(my_google_stub, "google.com")
+ ShamRack.at("google.com").run(my_google_stub)
### General-purpose stubbing
@@ -48,22 +48,25 @@ def initialize(address, port = nil)
@port = port
end
+ def run(app)
+ ShamRack.mount(app, @address, @port)
+ end
+
def rackup(&block)
require "rack"
- app = Rack::Builder.new(&block).to_app
- ShamRack.mount(app, @address, @port)
+ run(Rack::Builder.new(&block).to_app)
end
def sinatra(&block)
require "sinatra/base"
sinatra_app = Class.new(Sinatra::Base)
sinatra_app.class_eval(&block)
- ShamRack.mount(sinatra_app.new, @address, @port)
+ run(sinatra_app.new)
end
def stub
require "sham_rack/stub_web_service"
- ShamRack.mount(StubWebService.new, @address, @port)
+ run(StubWebService.new)
end
end
@@ -86,6 +86,18 @@
end
+ describe "#run" do
+
+ it "is sugar for ShamRack.mount" do
+
+ ShamRack.at("hello.xyz").run(GreetingApp.new)
+
+ open("http://hello.xyz").read.should == "Hello, world"
+
+ end
+
+ end
+
describe "#rackup" do
before do

0 comments on commit e74a03d

Please sign in to comment.