1 require File.dirname(__FILE__) + '/../lib/sinatra'
6 context "Simple Events" do
8 def simple_request_hash(method, path)
10 'REQUEST_METHOD' => method.to_s.upcase,
15 def invoke_simple(path, request_path, &b)
16 event = Sinatra::Event.new(path, &b)
17 event.invoke(simple_request_hash(:get, request_path))
20 specify "return last value" do
21 block = Proc.new { 'Simple' }
22 result = invoke_simple('/', '/', &block)
23 result.should.not.be.nil
24 result.block.should.be block
25 result.params.should.equal Hash.new
28 specify "takes params in path" do
29 result = invoke_simple('/:foo/:bar', '/a/b')
30 result.should.not.be.nil
31 result.params.should.equal :foo => 'a', :bar => 'b'
34 result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
35 result.should.not.be.nil
36 result.params.should.equal :foo => 'a', :bar => 'blake mizerany'
39 specify "ignores to many /'s" do
40 result = invoke_simple('/x/y', '/x//y')
41 result.should.not.be.nil
44 specify "understands splat" do
45 invoke_simple('/foo/*', '/foo/bar').should.not.be.nil
46 invoke_simple('/foo/*', '/foo/bar/baz').should.not.be.nil
47 invoke_simple('/foo/*', '/foo/baz').should.not.be.nil