spec/galago/router_spec.rb in galago-router-0.0.1 vs spec/galago/router_spec.rb in galago-router-0.0.2

- old
+ new

@@ -1,47 +1,27 @@ require 'spec_helper' module Galago describe Router do - let(:router) { Class.new(Router) } - - describe '.call' do - it 'tells the router to process the request' do - expect(router.router).to receive(:process_request).with('env') - router.call('env') - end - end - describe '.routes' do it 'adds the specified routes' do - router.routes do + router = Router.new do get '/foo' , to: lambda { |env| 'bar' } post '/foo' , to: lambda { |env| 'bar' } patch '/foo' , to: lambda { |env| 'bar' } put '/foo' , to: lambda { |env| 'bar' } delete '/foo' , to: lambda { |env| 'bar' } end - expect(router.router).to have_route(:get, '/foo') - expect(router.router).to have_route(:post, '/foo') - expect(router.router).to have_route(:patch, '/foo') - expect(router.router).to have_route(:put, '/foo') - expect(router.router).to have_route(:delete, '/foo') + expect(router).to have_route(:get, '/foo') + expect(router).to have_route(:post, '/foo') + expect(router).to have_route(:patch, '/foo') + expect(router).to have_route(:put, '/foo') + expect(router).to have_route(:delete, '/foo') end end - describe '.router' do - it 'builds an instance if the router' do - expect(router.router).to be_a Router - end - - it 'remembers the router that was built' do - router_id = router.router.object_id - expect(router.router.object_id).to eql router_id - end - end - describe "#add_route" do let(:rack_app) do lambda { |env| "RackApp" } end @@ -81,26 +61,26 @@ expect(router).not_to have_route(:get, '/users') end end - describe "process_request" do + describe "#call" do it "calls the rack app when the route is found" do router = Router.new router.add_route(:get, '/foo', lambda { |env| [200, {}, 'bar'] }) - response = router.process_request({ + response = router.call({ 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/foo' }) expect(response).to eql [200, {}, 'bar'] end it "returns 404 when no route matchs the path" do router = Router.new - response = router.process_request({ + response = router.call({ 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/bar' }) expect(response[0]).to eql(404)