1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/test/events_test.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

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
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
block = Proc.new { 'Simple' }
result = invoke_simple('/', '/', &block)
2007-11-27 23:26:48 -05:00
result.should.not.be.nil
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
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
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-27 23:16:12 -05:00
end