Created
October 6, 2011 10:05
-
-
Save ashmoran/1267034 to your computer and use it in GitHub Desktop.
Testing a rack-mount router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack/lobster' | |
module App | |
class Router | |
def initialize | |
@app = Rack::Mount::RouteSet.new do |set| | |
set.add_route ->(*args) { Rack::Lobster.new.call(*args) }, { :request_method => 'GET', :path_info => %r{^/lobster$} }, {}, :lobster | |
end | |
end | |
def call(*args) | |
@app.call(*args) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
module App | |
describe Router do | |
let(:lobster) { mock(Rack::Lobster, call: [ 200, { }, [ ] ]) } | |
subject { Router.new } | |
let(:session) { Rack::Test::Session.new(subject) } | |
before(:each) do | |
Rack::Lobster.stub(new: lobster) | |
end | |
it "routes the lobster" do | |
lobster.should_receive(:call) | |
session.get("/lobster") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment