Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created October 6, 2011 10:05
Show Gist options
  • Save ashmoran/1267034 to your computer and use it in GitHub Desktop.
Save ashmoran/1267034 to your computer and use it in GitHub Desktop.
Testing a rack-mount router
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
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