+
+
+
+
+
Params:
#{params.inspect}
-
-
-
#{Rack::Utils.escape_html(@error.class.name + ' - ' + @error.message.to_s)}
-
#{Rack::Utils.escape_html(@error.backtrace.join("\n"))}
-
-
+
+
+
#{Rack::Utils.escape_html(@error.class.name + ' - ' + @error.message.to_s)}
+
#{Rack::Utils.escape_html(@error.backtrace.join("\n"))}
+
+
- )
+ HTML
end
end
end
@@ -1381,14 +1348,12 @@ end
### Misc Core Extensions
module Kernel
-
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, nil
yield
ensure
$VERBOSE = old_verbose
end
-
end
class String
@@ -1399,58 +1364,47 @@ class String
Rack::Utils.escape(self)
end
alias :http_escape :to_param
-
+
# Converts +self+ from an escaped URI parameter value
# 'Foo%20Bar'.from_param # => 'Foo Bar'
def from_param
Rack::Utils.unescape(self)
end
alias :http_unescape :from_param
-
+
end
class Hash
-
def to_params
map { |k,v| "#{k}=#{URI.escape(v)}" }.join('&')
end
-
def symbolize_keys
self.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
end
-
def pass(*keys)
reject { |k,v| !keys.include?(k) }
end
-
end
class Symbol
-
- def to_proc
+ def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end
-
end
class Array
-
def to_hash
self.inject({}) { |h, (k, v)| h[k] = v; h }
end
-
def to_proc
Proc.new { |*args| args.shift.__send__(self[0], *(args + self[1..-1])) }
end
-
end
module Enumerable
-
def eject(&block)
find { |e| result = block[e] and break result }
end
-
end
### Core Extension results for throw :halt
@@ -1497,7 +1451,7 @@ end
at_exit do
raise $! if $!
if Sinatra.application.options.run
- Sinatra.run
+ Sinatra.run
end
end
diff --git a/lib/sinatra/test/methods.rb b/lib/sinatra/test/methods.rb
index 6fec510b..1c741b32 100644
--- a/lib/sinatra/test/methods.rb
+++ b/lib/sinatra/test/methods.rb
@@ -1,7 +1,7 @@
module Sinatra
-
+
module Test
-
+
module Methods
def easy_env_map
@@ -13,12 +13,12 @@ module Sinatra
:cookies => "HTTP_COOKIE"
}
end
-
+
def session(data, key = 'rack.session')
data = data.from_params if data.respond_to?(:from_params)
"#{Rack::Utils.escape(key)}=#{[Marshal.dump(data)].pack("m*")}"
end
-
+
def map_easys(params)
easy_env_map.inject(params.dup) do |m, (from, to)|
m[to] = m.delete(from) if m.has_key?(from); m
@@ -37,7 +37,7 @@ module Sinatra
@response = @request.request(m.upcase, path, {:input => input}.merge(env || {}))
end
end
-
+
def follow!
get_it(@response.location)
end
@@ -45,9 +45,9 @@ module Sinatra
def method_missing(name, *args)
@response.send(name, *args) rescue super
end
-
+
end
end
-
+
end
diff --git a/lib/sinatra/test/spec.rb b/lib/sinatra/test/spec.rb
index 5785e55a..73a429be 100644
--- a/lib/sinatra/test/spec.rb
+++ b/lib/sinatra/test/spec.rb
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/unit'
require 'test/spec'
class Test::Unit::TestCase
-
+
def should
@response.should
end
-
+
end
diff --git a/test/app_test.rb b/test/app_test.rb
index cc94839a..3f784e61 100644
--- a/test/app_test.rb
+++ b/test/app_test.rb
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/helper'
context "Sinatra" do
-
+
setup do
Sinatra.application = nil
end
@@ -17,32 +17,32 @@ context "Sinatra" do
get '/' do
nil
end
-
+
get_it '/'
should.be.ok
body.should == ''
end
-
+
specify "handles events" do
get '/:name' do
'Hello ' + params["name"]
end
-
+
get_it '/Blake'
-
+
should.be.ok
body.should.equal 'Hello Blake'
end
-
+
specify "handles splats" do
get '/hi/*' do
params["splat"].kind_of?(Array).should.equal true
params["splat"].first
end
-
+
get_it '/hi/Blake'
-
+
should.be.ok
body.should.equal 'Blake'
end
@@ -51,9 +51,9 @@ context "Sinatra" do
get '/say/*/to/*' do
params["splat"].join(' ')
end
-
+
get_it '/say/hello/to/world'
-
+
should.be.ok
body.should.equal 'hello world'
end
@@ -62,14 +62,14 @@ context "Sinatra" do
get '/say/*/to*/*' do
params["splat"].join(' ')
end
-
+
get_it '/say/hello/to/world'
-
+
should.be.ok
body.should.equal 'hello world' # second splat is empty
get_it '/say/hello/tomy/world'
-
+
should.be.ok
body.should.equal 'hello my world'
end
@@ -93,20 +93,20 @@ context "Sinatra" do
get '/' do
redirect '/blake'
end
-
+
get '/blake' do
'Mizerany'
end
-
+
get_it '/'
should.be.redirection
body.should.equal ''
-
+
follow!
should.be.ok
body.should.equal 'Mizerany'
end
-
+
specify "renders a body with a redirect" do
Sinatra::EventContext.any_instance.expects(:foo).returns('blah')
get "/" do
@@ -130,34 +130,34 @@ context "Sinatra" do
end
specify "body sets content and ends event" do
-
+
Sinatra::EventContext.any_instance.expects(:foo).never
-
+
get '/set_body' do
stop 'Hello!'
stop 'World!'
foo
end
-
+
get_it '/set_body'
-
+
should.be.ok
body.should.equal 'Hello!'
-
+
end
-
+
specify "should set status then call helper with a var" do
Sinatra::EventContext.any_instance.expects(:foo).once.with(1).returns('bah!')
-
+
get '/set_body' do
stop [404, [:foo, 1]]
end
-
+
get_it '/set_body'
-
+
should.be.not_found
body.should.equal 'bah!'
-
+
end
specify "should easily set response Content-Type" do
@@ -235,7 +235,7 @@ context "Sinatra" do
body.should.equal ''
end
-
+
specify "put'n with POST" do
put '/' do
'puted'
@@ -252,7 +252,7 @@ context "Sinatra" do
assert_equal 'puted', body
end
- # Some Ajax libraries downcase the _method parameter value. Make
+ # Some Ajax libraries downcase the _method parameter value. Make
# sure we can handle that.
specify "put'n with POST and lowercase _method param" do
put '/' do
diff --git a/test/application_test.rb b/test/application_test.rb
index 57a67bbf..a753821f 100644
--- a/test/application_test.rb
+++ b/test/application_test.rb
@@ -19,49 +19,49 @@ context "Looking up a request" do
specify "returns what's at the end" do
block = Proc.new { 'Hello' }
get '/', &block
-
+
result = Sinatra.application.lookup(
Rack::Request.new(
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/'
)
)
-
+
result.should.not.be.nil
result.block.should.be block
end
-
+
specify "takes params in path" do
block = Proc.new { 'Hello' }
get '/:foo', &block
-
+
result = Sinatra.application.lookup(
Rack::Request.new(
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/bar'
)
)
-
+
result.should.not.be.nil
result.block.should.be block
result.params.should.equal "foo" => 'bar'
end
-
+
end
context "An app returns" do
-
+
setup do
Sinatra.application = nil
end
-
+
specify "404 if no events found" do
request = Rack::MockRequest.new(@app)
get_it '/'
should.be.not_found
body.should.equal '
Not Found
'
end
-
+
specify "200 if success" do
get '/' do
'Hello World'
@@ -70,32 +70,32 @@ context "An app returns" do
should.be.ok
body.should.equal 'Hello World'
end
-
+
specify "an objects result from each if it has it" do
-
+
get '/' do
TesterWithEach.new
end
-
+
get_it '/'
should.be.ok
body.should.equal 'foobarbaz'
end
-
+
specify "the body set if set before the last" do
-
+
get '/' do
body 'Blake'
'Mizerany'
end
-
+
get_it '/'
should.be.ok
body.should.equal 'Blake'
end
-
+
end
context "Application#configure blocks" do
@@ -145,43 +145,43 @@ context "Default Application Configuration" do
end
context "Events in an app" do
-
+
setup do
Sinatra.application = nil
end
-
+
specify "evaluate in a clean context" do
helpers do
def foo
'foo'
end
end
-
+
get '/foo' do
foo
end
-
+
get_it '/foo'
should.be.ok
body.should.equal 'foo'
end
-
+
specify "get access to request, response, and params" do
get '/:foo' do
params["foo"] + params["bar"]
end
-
+
get_it '/foo?bar=baz'
should.be.ok
body.should.equal 'foobaz'
end
-
+
specify "can filters by agent" do
-
+
get '/', :agent => /Windows/ do
request.env['HTTP_USER_AGENT']
end
-
+
get_it '/', :env => { :agent => 'Windows' }
should.be.ok
body.should.equal 'Windows'
@@ -192,30 +192,30 @@ context "Events in an app" do
end
specify "can use regex to get parts of user-agent" do
-
+
get '/', :agent => /Windows (NT)/ do
params[:agent].first
end
-
+
get_it '/', :env => { :agent => 'Windows NT' }
body.should.equal 'NT'
end
-
+
specify "can deal with spaces in paths" do
-
+
path = '/path with spaces'
-
+
get path do
"Look ma, a path with spaces!"
end
-
+
get_it URI.encode(path)
-
+
body.should.equal "Look ma, a path with spaces!"
end
-
+
end
diff --git a/test/custom_error_test.rb b/test/custom_error_test.rb
index e479d6b3..7923345d 100644
--- a/test/custom_error_test.rb
+++ b/test/custom_error_test.rb
@@ -5,63 +5,58 @@ context "Custom Errors (in general)" do
setup do
Sinatra.application = nil
end
-
+
specify "override the default 404" do
-
+
get_it '/'
should.be.not_found
body.should.equal '
Not Found
'
-
+
error Sinatra::NotFound do
'Custom 404'
end
-
+
get_it '/'
should.be.not_found
body.should.equal 'Custom 404'
-
+
end
-
+
specify "override the default 500" do
Sinatra.application.options.raise_errors = false
-
+
get '/' do
raise 'asdf'
end
-
+
get_it '/'
status.should.equal 500
body.should.equal '
Internal Server Error
'
-
-
+
+
error do
'Custom 500 for ' + request.env['sinatra.error'].message
end
-
+
get_it '/'
-
+
get_it '/'
status.should.equal 500
body.should.equal 'Custom 500 for asdf'
-
+
Sinatra.application.options.raise_errors = true
end
-
+
class UnmappedError < RuntimeError; end
-
+
specify "should bring unmapped error back to the top" do
get '/' do
raise UnmappedError, 'test'
end
-
+
assert_raises(UnmappedError) do
get_it '/'
end
end
end
-
-
-
-
-
diff --git a/test/diddy_test.rb b/test/diddy_test.rb
index a6a1cfbe..27e4b664 100644
--- a/test/diddy_test.rb
+++ b/test/diddy_test.rb
@@ -11,11 +11,11 @@ context "Diddy" do
get '/' do
'asdf'
end
-
+
get_it '/'
assert ok?
assert_equal('asdf', body)
-
+
get '/foo', :host => 'foo.sinatrarb.com' do
'in foo!'
end
@@ -23,7 +23,7 @@ context "Diddy" do
get '/foo', :host => 'bar.sinatrarb.com' do
'in bar!'
end
-
+
get_it '/foo', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
assert ok?
assert_equal 'in foo!', body
@@ -31,10 +31,10 @@ context "Diddy" do
get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com'
assert ok?
assert_equal 'in bar!', body
-
+
get_it '/foo'
assert not_found?
-
+
end
end
diff --git a/test/erb_test.rb b/test/erb_test.rb
index 36c1e239..51a79593 100644
--- a/test/erb_test.rb
+++ b/test/erb_test.rb
@@ -5,19 +5,19 @@ context "Erb" do
setup do
Sinatra.application = nil
end
-
+
context "without layouts" do
-
+
setup do
Sinatra.application = nil
end
-
+
specify "should render" do
-
+
get '/no_layout' do
erb '<%= 1 + 1 %>'
end
-
+
get_it '/no_layout'
should.be.ok
body.should == '2'
@@ -44,62 +44,62 @@ context "Erb" do
body.should == 'foo'
end
end
-
+
context "with layouts" do
setup do
Sinatra.application = nil
end
-
+
specify "can be inline" do
-
+
layout do
%Q{This is <%= yield %>!}
end
-
+
get '/lay' do
erb 'Blake'
end
-
+
get_it '/lay'
should.be.ok
body.should.equal 'This is Blake!'
end
-
+
specify "can use named layouts" do
-
+
layout :pretty do
%Q{
<%= yield %>
}
end
-
+
get '/pretty' do
erb 'Foo', :layout => :pretty
end
-
+
get '/not_pretty' do
erb 'Bar'
end
-
+
get_it '/pretty'
body.should.equal '
Foo
'
-
+
get_it '/not_pretty'
body.should.equal 'Bar'
-
+
end
-
+
specify "can be read from a file if they're not inlined" do
-
+
get '/foo' do
@title = 'Welcome to the Hello Program'
erb 'Blake', :layout => :foo_layout,
:views_directory => File.dirname(__FILE__) + "/views"
end
-
+
get_it '/foo'
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
-
+
end
end
@@ -132,5 +132,5 @@ context "Erb" do
end
end
-
+
end
diff --git a/test/event_context_test.rb b/test/event_context_test.rb
index b9f9a69b..538d0082 100644
--- a/test/event_context_test.rb
+++ b/test/event_context_test.rb
@@ -3,13 +3,13 @@ require File.dirname(__FILE__) + '/helper'
context "EventContext" do
specify "DSLified setters" do
-
+
cx = Sinatra::EventContext.new(stub_everything, Rack::Response.new, {})
lambda {
cx.status 404
}.should.not.raise(ArgumentError)
-
+
end
-
+
end
diff --git a/test/events_test.rb b/test/events_test.rb
index 5c1c1021..d37c0872 100644
--- a/test/events_test.rb
+++ b/test/events_test.rb
@@ -13,7 +13,7 @@ context "Simple Events" do
event = Sinatra::Event.new(path, &b)
event.invoke(simple_request_hash(:get, request_path))
end
-
+
specify "return last value" do
block = Proc.new { 'Simple' }
result = invoke_simple('/', '/', &block)
@@ -21,27 +21,27 @@ context "Simple Events" do
result.block.should.be block
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'
-
+
# unscapes
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
result.should.not.be.nil
result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
end
-
+
specify "ignores to many /'s" do
result = invoke_simple('/x/y', '/x//y')
result.should.not.be.nil
end
-
+
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
-
+ end
+
end
diff --git a/test/haml_test.rb b/test/haml_test.rb
index 44e278ad..4e738ba7 100644
--- a/test/haml_test.rb
+++ b/test/haml_test.rb
@@ -5,95 +5,95 @@ context "Haml" do
setup do
Sinatra.application = nil
end
-
+
context "without layouts" do
-
+
setup do
Sinatra.application = nil
end
-
+
specify "should render" do
-
+
get '/no_layout' do
haml '== #{1+1}'
end
-
+
get_it '/no_layout'
should.be.ok
body.should == "2\n"
end
end
-
+
context "with layouts" do
setup do
Sinatra.application = nil
end
-
+
specify "can be inline" do
-
+
layout do
'== This is #{yield}!'
end
-
+
get '/lay' do
haml 'Blake'
end
-
+
get_it '/lay'
should.be.ok
body.should.equal "This is Blake\n!\n"
end
-
+
specify "can use named layouts" do
-
+
layout :pretty do
'%h1== #{yield}'
end
-
+
get '/pretty' do
haml 'Foo', :layout => :pretty
end
-
+
get '/not_pretty' do
haml 'Bar'
end
-
+
get_it '/pretty'
body.should.equal "
Foo
\n"
-
+
get_it '/not_pretty'
body.should.equal "Bar\n"
-
+
end
-
+
specify "can be read from a file if they're not inlined" do
-
+
get '/foo' do
@title = 'Welcome to the Hello Program'
haml 'Blake', :layout => :foo_layout,
:views_directory => File.dirname(__FILE__) + "/views"
end
-
+
get_it '/foo'
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
-
+
end
-
+
specify "can be read from file and layout from text" do
get '/foo' do
haml 'Test', :layout => '== Foo #{yield}'
end
-
+
get_it '/foo'
-
+
body.should.equal "Foo Test\n"
end
end
-
+
context "Templates (in general)" do
setup do
@@ -136,21 +136,21 @@ context "Haml" do
body.should.equal "
No Layout!
\n"
end
-
+
specify "can render with no layout" do
layout do
"X\n= yield\nX"
end
-
+
get '/' do
haml 'blake', :layout => false
end
-
+
get_it '/'
-
+
body.should.equal "blake\n"
end
-
+
specify "raises error if template not found" do
get '/' do
haml :not_found
@@ -175,7 +175,7 @@ context "Haml" do
body.should.equal "asdf\n"
end
-
+
end
describe 'Options passed to the HAML interpreter' do
diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb
index 918af061..e664b104 100644
--- a/test/mapped_error_test.rb
+++ b/test/mapped_error_test.rb
@@ -3,59 +3,59 @@ require File.dirname(__FILE__) + '/helper'
class FooError < RuntimeError; end
context "Mapped errors" do
-
+
setup do
Sinatra.application = nil
end
-
+
specify "are rescued and run in context" do
-
+
error FooError do
'MAPPED ERROR!'
end
-
+
get '/' do
raise FooError.new
end
-
+
get_it '/'
-
+
should.be.server_error
body.should.equal 'MAPPED ERROR!'
-
+
end
specify "renders empty if no each method on result" do
-
+
error FooError do
nil
end
-
+
get '/' do
raise FooError.new
end
-
+
get_it '/'
-
+
should.be.server_error
body.should.be.empty
-
+
end
specify "doesn't override status if set" do
-
+
error FooError do
status(200)
end
-
+
get '/' do
raise FooError.new
end
-
+
get_it '/'
-
+
should.be.ok
-
+
end
-
+
end
diff --git a/test/rest_test.rb b/test/rest_test.rb
index 8a126ad8..5c24e9c4 100644
--- a/test/rest_test.rb
+++ b/test/rest_test.rb
@@ -1,12 +1,13 @@
require File.dirname(__FILE__) + '/helper'
+# XXX: How does any of this have anything to do with REST?
context "RESTful tests" do
specify "should take xml" do
post '/foo.xml' do
request.body.string
end
-
+
post_it '/foo.xml', '
'
assert ok?
assert_equal('
', body)
diff --git a/test/sass_test.rb b/test/sass_test.rb
index b24762b5..ee6d4f41 100644
--- a/test/sass_test.rb
+++ b/test/sass_test.rb
@@ -5,7 +5,7 @@ context "Sass" do
setup do
Sinatra.application = nil
end
-
+
context "Templates (in general)" do
setup do
@@ -23,7 +23,7 @@ context "Sass" do
body.should.equal "#sass {\n background_color: #FFF; }\n"
end
-
+
specify "raise an error if template not found" do
get '/' do
sass :not_found
@@ -31,27 +31,27 @@ context "Sass" do
lambda { get_it '/' }.should.raise(Errno::ENOENT)
end
-
+
specify "ignore default layout file with .sass extension" do
get '/' do
sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end
-
+
get_it '/'
should.be.ok
body.should.equal "#sass {\n background_color: #FFF; }\n"
end
-
+
specify "ignore explicitly specified layout file" do
get '/' do
sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end
-
+
get_it '/'
should.be.ok
body.should.equal "#sass {\n background_color: #FFF; }\n"
end
-
+
end
end
diff --git a/test/sessions_test.rb b/test/sessions_test.rb
index 37912304..b50cb8fb 100644
--- a/test/sessions_test.rb
+++ b/test/sessions_test.rb
@@ -13,7 +13,7 @@ context "Sessions" do
get '/test' do
session[:test] == true ? "true" : "false"
end
-
+
get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
assert ok?
assert !include?('Set-Cookie')
@@ -33,7 +33,7 @@ context "Sessions" do
get_it '/foo', :env => { :host => 'foo.sinatrarb.com' }
assert ok?
- assert include?('Set-Cookie')
+ assert include?('Set-Cookie')
end
-
+
end
diff --git a/test/streaming_test.rb b/test/streaming_test.rb
index 998bbc66..d507f1be 100644
--- a/test/streaming_test.rb
+++ b/test/streaming_test.rb
@@ -86,7 +86,7 @@ context "Static files (by default)" do
end
context "SendData" do
-
+
setup do
Sinatra.application = nil
end
@@ -95,13 +95,13 @@ context "SendData" do
get '/' do
send_data 'asdf', :status => 500
end
-
+
get_it '/'
-
+
should.be.server_error
body.should.equal 'asdf'
end
-
+
specify "should include a Content-Disposition header" do
get '/' do
send_file File.dirname(__FILE__) + '/public/foo.xml'
diff --git a/test/sym_params_test.rb b/test/sym_params_test.rb
index 3f398444..2172be0c 100644
--- a/test/sym_params_test.rb
+++ b/test/sym_params_test.rb
@@ -10,7 +10,7 @@ context "Symbol Params" do
get '/' do
params[:foo] + params['foo']
end
-
+
get_it '/', :foo => "X"
assert_equal('XX', body)
end
diff --git a/test/template_test.rb b/test/template_test.rb
index cafac91a..41b439b8 100644
--- a/test/template_test.rb
+++ b/test/template_test.rb
@@ -1,30 +1,30 @@
require File.dirname(__FILE__) + '/helper'
context "Templates (in general)" do
-
+
specify "are read from files if Symbols" do
-
+
get '/from_file' do
@name = 'Alena'
erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
end
-
+
get_it '/from_file'
-
+
body.should.equal 'You rock Alena!'
-
+
end
-
+
specify "use layout.ext by default if available" do
-
+
get '/layout_from_file' do
erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end
-
+
get_it '/layout_from_file'
should.be.ok
body.should.equal "x This is foo! x \n"
-
+
end
-
+
end
diff --git a/test/use_in_file_templates_test.rb b/test/use_in_file_templates_test.rb
index ca61a051..265f07de 100644
--- a/test/use_in_file_templates_test.rb
+++ b/test/use_in_file_templates_test.rb
@@ -6,34 +6,33 @@ context "Rendering in file templates" do
Sinatra.application = nil
use_in_file_templates!
end
-
+
specify "should set template" do
assert Sinatra.application.templates[:foo]
end
-
+
specify "should set layout" do
assert Sinatra.application.templates[:layout]
end
-
+
specify "should render without layout if specified" do
get '/' do
haml :foo, :layout => false
end
-
+
get_it '/'
assert_equal "this is foo\n", body
end
-
+
specify "should render with layout if specified" do
get '/' do
haml :foo
end
-
+
get_it '/'
assert_equal "X\nthis is foo\nX\n", body
end
-
-
+
end
__END__