2007-11-27 23:16:12 -05:00
|
|
|
require File.dirname(__FILE__) + '/../lib/sinatra'
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'test/spec'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-11-28 01:31:31 -05:00
|
|
|
def invoke_simple(path, request_path, &b)
|
|
|
|
event = Sinatra::Event.new(path, &b)
|
2007-11-28 00:55:05 -05:00
|
|
|
event.invoke(simple_request_hash(:get, request_path))
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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'
|
2007-11-27 23:16:12 -05:00
|
|
|
|
2007-11-28 00:55:05 -05:00
|
|
|
# unscapes
|
|
|
|
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
|
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-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
|
|
|
|
end
|
2007-11-28 01:31:31 -05:00
|
|
|
|
2007-11-27 23:16:12 -05:00
|
|
|
end
|