From d45485425302e12b314e509d6924f4094ca4d034 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Tue, 27 Nov 2007 22:52:52 -0800 Subject: [PATCH] serving simple events --- lib/sinatra.rb | 5 +++++ test/application_test.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index 17b8f71..5213306 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -48,6 +48,11 @@ module Sinatra events[env['REQUEST_METHOD'].downcase.to_sym].eject(&[:invoke, env]) end + def call(env) + return [404, {}, 'Not Found'] unless event = lookup(env) + [200, {}, event.block.call] + end + end end diff --git a/test/application_test.rb b/test/application_test.rb index 9017345..644ca46 100644 --- a/test/application_test.rb +++ b/test/application_test.rb @@ -34,3 +34,32 @@ context "Looking up a request" do end end + + +context "Calling an app" do + + setup do + @app = Sinatra::Application.new + end + + # - 404 if no events found + + specify "404 if no events found" do + request = Rack::MockRequest.new(@app) + result = request.get('/') + result.should.be.not_found + result.body.should.equal 'Not Found' + end + + specify "200 if success" do + @app.define_event(:get, '/') do + 'Hello World' + end + + request = Rack::MockRequest.new(@app) + result = request.get('/') + result.should.be.ok + result.body.should.equal 'Hello World' + end + +end -- 2.11.4.GIT