2008-08-31 03:35:35 -04:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
2007-11-27 23:16:12 -05:00
|
|
|
|
|
|
|
context "Simple Events" do
|
2007-11-28 00:55:05 -05:00
|
|
|
def simple_request_hash(method, path)
|
2008-03-04 19:30:06 -05:00
|
|
|
Rack::Request.new({
|
2007-11-28 00:55:05 -05:00
|
|
|
'REQUEST_METHOD' => method.to_s.upcase,
|
|
|
|
'PATH_INFO' => path
|
2008-03-04 19:30:06 -05:00
|
|
|
})
|
2007-11-28 00:55:05 -05:00
|
|
|
end
|
|
|
|
|
2008-12-13 16:06:02 -05:00
|
|
|
class MockResult < Struct.new(:block, :params)
|
|
|
|
end
|
|
|
|
|
2007-11-28 01:31:31 -05:00
|
|
|
def invoke_simple(path, request_path, &b)
|
2008-12-13 16:06:02 -05:00
|
|
|
params = nil
|
2009-01-13 12:53:53 -05:00
|
|
|
get path do
|
|
|
|
params = self.params
|
|
|
|
b.call if b
|
|
|
|
end
|
2008-12-13 16:06:02 -05:00
|
|
|
get_it request_path
|
|
|
|
MockResult.new(b, params)
|
2007-11-28 00:55:05 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2009-01-13 12:53:53 -05:00
|
|
|
setup { Sinatra.application = nil }
|
|
|
|
|
2007-11-28 00:55:05 -05:00
|
|
|
specify "return last value" do
|
2007-11-28 01:31:31 -05:00
|
|
|
block = Proc.new { 'Simple' }
|
|
|
|
result = invoke_simple('/', '/', &block)
|
2007-11-27 23:26:48 -05:00
|
|
|
result.should.not.be.nil
|
2007-11-28 01:31:31 -05:00
|
|
|
result.block.should.be block
|
2007-11-28 00:55:05 -05:00
|
|
|
result.params.should.equal Hash.new
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-28 00:55:05 -05:00
|
|
|
specify "takes params in path" do
|
|
|
|
result = invoke_simple('/:foo/:bar', '/a/b')
|
|
|
|
result.should.not.be.nil
|
2008-03-31 21:48:06 -04:00
|
|
|
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-28 00:55:05 -05:00
|
|
|
# unscapes
|
2009-01-13 12:53:53 -05:00
|
|
|
Sinatra.application = nil
|
2007-11-28 00:55:05 -05:00
|
|
|
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
|
|
|
|
result.should.not.be.nil
|
2008-03-31 21:48:06 -04:00
|
|
|
result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
|
2007-11-27 23:26:48 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-09-08 14:24:35 -04:00
|
|
|
specify "takes optional params in path" do
|
|
|
|
result = invoke_simple('/?:foo?/?:bar?', '/a/b')
|
|
|
|
result.should.not.be.nil
|
|
|
|
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
|
|
|
|
2009-01-13 12:53:53 -05:00
|
|
|
Sinatra.application = nil
|
2008-09-08 14:24:35 -04:00
|
|
|
result = invoke_simple('/?:foo?/?:bar?', '/a/')
|
|
|
|
result.should.not.be.nil
|
|
|
|
result.params.should.equal "foo" => 'a', "bar" => nil
|
|
|
|
|
2009-01-13 12:53:53 -05:00
|
|
|
Sinatra.application = nil
|
2008-09-08 14:24:35 -04:00
|
|
|
result = invoke_simple('/?:foo?/?:bar?', '/a')
|
|
|
|
result.should.not.be.nil
|
|
|
|
result.params.should.equal "foo" => 'a', "bar" => nil
|
|
|
|
|
2009-01-13 12:53:53 -05:00
|
|
|
Sinatra.application = nil
|
2008-09-08 14:24:35 -04:00
|
|
|
result = invoke_simple('/:foo?/?:bar?', '/')
|
|
|
|
result.should.not.be.nil
|
|
|
|
result.params.should.equal "foo" => nil, "bar" => nil
|
|
|
|
end
|
|
|
|
|
2007-11-28 00:55:05 -05:00
|
|
|
specify "ignores to many /'s" do
|
|
|
|
result = invoke_simple('/x/y', '/x//y')
|
|
|
|
result.should.not.be.nil
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-01-11 20:01:00 -05:00
|
|
|
specify "understands splat" do
|
|
|
|
invoke_simple('/foo/*', '/foo/bar').should.not.be.nil
|
|
|
|
invoke_simple('/foo/*', '/foo/bar/baz').should.not.be.nil
|
|
|
|
invoke_simple('/foo/*', '/foo/baz').should.not.be.nil
|
2008-08-31 03:39:26 -04:00
|
|
|
end
|
|
|
|
|
2007-11-27 23:16:12 -05:00
|
|
|
end
|