Fix whitespace errors across all source files and tests

I can't stand this shit anymore.
This commit is contained in:
Ryan Tomayko 2008-08-31 00:39:26 -07:00
parent 7be3682605
commit 60d50062d7
19 changed files with 537 additions and 588 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
module Sinatra module Sinatra
module Test module Test
module Methods module Methods
def easy_env_map def easy_env_map
@ -13,12 +13,12 @@ module Sinatra
:cookies => "HTTP_COOKIE" :cookies => "HTTP_COOKIE"
} }
end end
def session(data, key = 'rack.session') def session(data, key = 'rack.session')
data = data.from_params if data.respond_to?(:from_params) data = data.from_params if data.respond_to?(:from_params)
"#{Rack::Utils.escape(key)}=#{[Marshal.dump(data)].pack("m*")}" "#{Rack::Utils.escape(key)}=#{[Marshal.dump(data)].pack("m*")}"
end end
def map_easys(params) def map_easys(params)
easy_env_map.inject(params.dup) do |m, (from, to)| easy_env_map.inject(params.dup) do |m, (from, to)|
m[to] = m.delete(from) if m.has_key?(from); m 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 || {})) @response = @request.request(m.upcase, path, {:input => input}.merge(env || {}))
end end
end end
def follow! def follow!
get_it(@response.location) get_it(@response.location)
end end
@ -45,9 +45,9 @@ module Sinatra
def method_missing(name, *args) def method_missing(name, *args)
@response.send(name, *args) rescue super @response.send(name, *args) rescue super
end end
end end
end end
end end

View File

@ -2,9 +2,9 @@ require File.dirname(__FILE__) + '/unit'
require 'test/spec' require 'test/spec'
class Test::Unit::TestCase class Test::Unit::TestCase
def should def should
@response.should @response.should
end end
end end

View File

@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
context "Sinatra" do context "Sinatra" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
@ -17,32 +17,32 @@ context "Sinatra" do
get '/' do get '/' do
nil nil
end end
get_it '/' get_it '/'
should.be.ok should.be.ok
body.should == '' body.should == ''
end end
specify "handles events" do specify "handles events" do
get '/:name' do get '/:name' do
'Hello ' + params["name"] 'Hello ' + params["name"]
end end
get_it '/Blake' get_it '/Blake'
should.be.ok should.be.ok
body.should.equal 'Hello Blake' body.should.equal 'Hello Blake'
end end
specify "handles splats" do specify "handles splats" do
get '/hi/*' do get '/hi/*' do
params["splat"].kind_of?(Array).should.equal true params["splat"].kind_of?(Array).should.equal true
params["splat"].first params["splat"].first
end end
get_it '/hi/Blake' get_it '/hi/Blake'
should.be.ok should.be.ok
body.should.equal 'Blake' body.should.equal 'Blake'
end end
@ -51,9 +51,9 @@ context "Sinatra" do
get '/say/*/to/*' do get '/say/*/to/*' do
params["splat"].join(' ') params["splat"].join(' ')
end end
get_it '/say/hello/to/world' get_it '/say/hello/to/world'
should.be.ok should.be.ok
body.should.equal 'hello world' body.should.equal 'hello world'
end end
@ -62,14 +62,14 @@ context "Sinatra" do
get '/say/*/to*/*' do get '/say/*/to*/*' do
params["splat"].join(' ') params["splat"].join(' ')
end end
get_it '/say/hello/to/world' get_it '/say/hello/to/world'
should.be.ok should.be.ok
body.should.equal 'hello world' # second splat is empty body.should.equal 'hello world' # second splat is empty
get_it '/say/hello/tomy/world' get_it '/say/hello/tomy/world'
should.be.ok should.be.ok
body.should.equal 'hello my world' body.should.equal 'hello my world'
end end
@ -93,20 +93,20 @@ context "Sinatra" do
get '/' do get '/' do
redirect '/blake' redirect '/blake'
end end
get '/blake' do get '/blake' do
'Mizerany' 'Mizerany'
end end
get_it '/' get_it '/'
should.be.redirection should.be.redirection
body.should.equal '' body.should.equal ''
follow! follow!
should.be.ok should.be.ok
body.should.equal 'Mizerany' body.should.equal 'Mizerany'
end end
specify "renders a body with a redirect" do specify "renders a body with a redirect" do
Sinatra::EventContext.any_instance.expects(:foo).returns('blah') Sinatra::EventContext.any_instance.expects(:foo).returns('blah')
get "/" do get "/" do
@ -130,34 +130,34 @@ context "Sinatra" do
end end
specify "body sets content and ends event" do specify "body sets content and ends event" do
Sinatra::EventContext.any_instance.expects(:foo).never Sinatra::EventContext.any_instance.expects(:foo).never
get '/set_body' do get '/set_body' do
stop 'Hello!' stop 'Hello!'
stop 'World!' stop 'World!'
foo foo
end end
get_it '/set_body' get_it '/set_body'
should.be.ok should.be.ok
body.should.equal 'Hello!' body.should.equal 'Hello!'
end end
specify "should set status then call helper with a var" do specify "should set status then call helper with a var" do
Sinatra::EventContext.any_instance.expects(:foo).once.with(1).returns('bah!') Sinatra::EventContext.any_instance.expects(:foo).once.with(1).returns('bah!')
get '/set_body' do get '/set_body' do
stop [404, [:foo, 1]] stop [404, [:foo, 1]]
end end
get_it '/set_body' get_it '/set_body'
should.be.not_found should.be.not_found
body.should.equal 'bah!' body.should.equal 'bah!'
end end
specify "should easily set response Content-Type" do specify "should easily set response Content-Type" do
@ -235,7 +235,7 @@ context "Sinatra" do
body.should.equal '' body.should.equal ''
end end
specify "put'n with POST" do specify "put'n with POST" do
put '/' do put '/' do
'puted' 'puted'
@ -252,7 +252,7 @@ context "Sinatra" do
assert_equal 'puted', body assert_equal 'puted', body
end end
# Some Ajax libraries downcase the _method parameter value. Make # Some Ajax libraries downcase the _method parameter value. Make
# sure we can handle that. # sure we can handle that.
specify "put'n with POST and lowercase _method param" do specify "put'n with POST and lowercase _method param" do
put '/' do put '/' do

View File

@ -19,49 +19,49 @@ context "Looking up a request" do
specify "returns what's at the end" do specify "returns what's at the end" do
block = Proc.new { 'Hello' } block = Proc.new { 'Hello' }
get '/', &block get '/', &block
result = Sinatra.application.lookup( result = Sinatra.application.lookup(
Rack::Request.new( Rack::Request.new(
'REQUEST_METHOD' => 'GET', 'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/' 'PATH_INFO' => '/'
) )
) )
result.should.not.be.nil result.should.not.be.nil
result.block.should.be block result.block.should.be block
end end
specify "takes params in path" do specify "takes params in path" do
block = Proc.new { 'Hello' } block = Proc.new { 'Hello' }
get '/:foo', &block get '/:foo', &block
result = Sinatra.application.lookup( result = Sinatra.application.lookup(
Rack::Request.new( Rack::Request.new(
'REQUEST_METHOD' => 'GET', 'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/bar' 'PATH_INFO' => '/bar'
) )
) )
result.should.not.be.nil result.should.not.be.nil
result.block.should.be block result.block.should.be block
result.params.should.equal "foo" => 'bar' result.params.should.equal "foo" => 'bar'
end end
end end
context "An app returns" do context "An app returns" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "404 if no events found" do specify "404 if no events found" do
request = Rack::MockRequest.new(@app) request = Rack::MockRequest.new(@app)
get_it '/' get_it '/'
should.be.not_found should.be.not_found
body.should.equal '<h1>Not Found</h1>' body.should.equal '<h1>Not Found</h1>'
end end
specify "200 if success" do specify "200 if success" do
get '/' do get '/' do
'Hello World' 'Hello World'
@ -70,32 +70,32 @@ context "An app returns" do
should.be.ok should.be.ok
body.should.equal 'Hello World' body.should.equal 'Hello World'
end end
specify "an objects result from each if it has it" do specify "an objects result from each if it has it" do
get '/' do get '/' do
TesterWithEach.new TesterWithEach.new
end end
get_it '/' get_it '/'
should.be.ok should.be.ok
body.should.equal 'foobarbaz' body.should.equal 'foobarbaz'
end end
specify "the body set if set before the last" do specify "the body set if set before the last" do
get '/' do get '/' do
body 'Blake' body 'Blake'
'Mizerany' 'Mizerany'
end end
get_it '/' get_it '/'
should.be.ok should.be.ok
body.should.equal 'Blake' body.should.equal 'Blake'
end end
end end
context "Application#configure blocks" do context "Application#configure blocks" do
@ -145,43 +145,43 @@ context "Default Application Configuration" do
end end
context "Events in an app" do context "Events in an app" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "evaluate in a clean context" do specify "evaluate in a clean context" do
helpers do helpers do
def foo def foo
'foo' 'foo'
end end
end end
get '/foo' do get '/foo' do
foo foo
end end
get_it '/foo' get_it '/foo'
should.be.ok should.be.ok
body.should.equal 'foo' body.should.equal 'foo'
end end
specify "get access to request, response, and params" do specify "get access to request, response, and params" do
get '/:foo' do get '/:foo' do
params["foo"] + params["bar"] params["foo"] + params["bar"]
end end
get_it '/foo?bar=baz' get_it '/foo?bar=baz'
should.be.ok should.be.ok
body.should.equal 'foobaz' body.should.equal 'foobaz'
end end
specify "can filters by agent" do specify "can filters by agent" do
get '/', :agent => /Windows/ do get '/', :agent => /Windows/ do
request.env['HTTP_USER_AGENT'] request.env['HTTP_USER_AGENT']
end end
get_it '/', :env => { :agent => 'Windows' } get_it '/', :env => { :agent => 'Windows' }
should.be.ok should.be.ok
body.should.equal 'Windows' body.should.equal 'Windows'
@ -192,30 +192,30 @@ context "Events in an app" do
end end
specify "can use regex to get parts of user-agent" do specify "can use regex to get parts of user-agent" do
get '/', :agent => /Windows (NT)/ do get '/', :agent => /Windows (NT)/ do
params[:agent].first params[:agent].first
end end
get_it '/', :env => { :agent => 'Windows NT' } get_it '/', :env => { :agent => 'Windows NT' }
body.should.equal 'NT' body.should.equal 'NT'
end end
specify "can deal with spaces in paths" do specify "can deal with spaces in paths" do
path = '/path with spaces' path = '/path with spaces'
get path do get path do
"Look ma, a path with spaces!" "Look ma, a path with spaces!"
end end
get_it URI.encode(path) get_it URI.encode(path)
body.should.equal "Look ma, a path with spaces!" body.should.equal "Look ma, a path with spaces!"
end end
end end

View File

@ -5,63 +5,58 @@ context "Custom Errors (in general)" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "override the default 404" do specify "override the default 404" do
get_it '/' get_it '/'
should.be.not_found should.be.not_found
body.should.equal '<h1>Not Found</h1>' body.should.equal '<h1>Not Found</h1>'
error Sinatra::NotFound do error Sinatra::NotFound do
'Custom 404' 'Custom 404'
end end
get_it '/' get_it '/'
should.be.not_found should.be.not_found
body.should.equal 'Custom 404' body.should.equal 'Custom 404'
end end
specify "override the default 500" do specify "override the default 500" do
Sinatra.application.options.raise_errors = false Sinatra.application.options.raise_errors = false
get '/' do get '/' do
raise 'asdf' raise 'asdf'
end end
get_it '/' get_it '/'
status.should.equal 500 status.should.equal 500
body.should.equal '<h1>Internal Server Error</h1>' body.should.equal '<h1>Internal Server Error</h1>'
error do error do
'Custom 500 for ' + request.env['sinatra.error'].message 'Custom 500 for ' + request.env['sinatra.error'].message
end end
get_it '/' get_it '/'
get_it '/' get_it '/'
status.should.equal 500 status.should.equal 500
body.should.equal 'Custom 500 for asdf' body.should.equal 'Custom 500 for asdf'
Sinatra.application.options.raise_errors = true Sinatra.application.options.raise_errors = true
end end
class UnmappedError < RuntimeError; end class UnmappedError < RuntimeError; end
specify "should bring unmapped error back to the top" do specify "should bring unmapped error back to the top" do
get '/' do get '/' do
raise UnmappedError, 'test' raise UnmappedError, 'test'
end end
assert_raises(UnmappedError) do assert_raises(UnmappedError) do
get_it '/' get_it '/'
end end
end end
end end

View File

@ -11,11 +11,11 @@ context "Diddy" do
get '/' do get '/' do
'asdf' 'asdf'
end end
get_it '/' get_it '/'
assert ok? assert ok?
assert_equal('asdf', body) assert_equal('asdf', body)
get '/foo', :host => 'foo.sinatrarb.com' do get '/foo', :host => 'foo.sinatrarb.com' do
'in foo!' 'in foo!'
end end
@ -23,7 +23,7 @@ context "Diddy" do
get '/foo', :host => 'bar.sinatrarb.com' do get '/foo', :host => 'bar.sinatrarb.com' do
'in bar!' 'in bar!'
end end
get_it '/foo', {}, 'HTTP_HOST' => 'foo.sinatrarb.com' get_it '/foo', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
assert ok? assert ok?
assert_equal 'in foo!', body assert_equal 'in foo!', body
@ -31,10 +31,10 @@ context "Diddy" do
get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com' get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com'
assert ok? assert ok?
assert_equal 'in bar!', body assert_equal 'in bar!', body
get_it '/foo' get_it '/foo'
assert not_found? assert not_found?
end end
end end

View File

@ -5,19 +5,19 @@ context "Erb" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
context "without layouts" do context "without layouts" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "should render" do specify "should render" do
get '/no_layout' do get '/no_layout' do
erb '<%= 1 + 1 %>' erb '<%= 1 + 1 %>'
end end
get_it '/no_layout' get_it '/no_layout'
should.be.ok should.be.ok
body.should == '2' body.should == '2'
@ -44,62 +44,62 @@ context "Erb" do
body.should == 'foo' body.should == 'foo'
end end
end end
context "with layouts" do context "with layouts" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "can be inline" do specify "can be inline" do
layout do layout do
%Q{This is <%= yield %>!} %Q{This is <%= yield %>!}
end end
get '/lay' do get '/lay' do
erb 'Blake' erb 'Blake'
end end
get_it '/lay' get_it '/lay'
should.be.ok should.be.ok
body.should.equal 'This is Blake!' body.should.equal 'This is Blake!'
end end
specify "can use named layouts" do specify "can use named layouts" do
layout :pretty do layout :pretty do
%Q{<h1><%= yield %></h1>} %Q{<h1><%= yield %></h1>}
end end
get '/pretty' do get '/pretty' do
erb 'Foo', :layout => :pretty erb 'Foo', :layout => :pretty
end end
get '/not_pretty' do get '/not_pretty' do
erb 'Bar' erb 'Bar'
end end
get_it '/pretty' get_it '/pretty'
body.should.equal '<h1>Foo</h1>' body.should.equal '<h1>Foo</h1>'
get_it '/not_pretty' get_it '/not_pretty'
body.should.equal 'Bar' body.should.equal 'Bar'
end end
specify "can be read from a file if they're not inlined" do specify "can be read from a file if they're not inlined" do
get '/foo' do get '/foo' do
@title = 'Welcome to the Hello Program' @title = 'Welcome to the Hello Program'
erb 'Blake', :layout => :foo_layout, erb 'Blake', :layout => :foo_layout,
:views_directory => File.dirname(__FILE__) + "/views" :views_directory => File.dirname(__FILE__) + "/views"
end end
get_it '/foo' get_it '/foo'
body.should.equal "Welcome to the Hello Program\nHi Blake\n" body.should.equal "Welcome to the Hello Program\nHi Blake\n"
end end
end end
@ -132,5 +132,5 @@ context "Erb" do
end end
end end
end end

View File

@ -3,13 +3,13 @@ require File.dirname(__FILE__) + '/helper'
context "EventContext" do context "EventContext" do
specify "DSLified setters" do specify "DSLified setters" do
cx = Sinatra::EventContext.new(stub_everything, Rack::Response.new, {}) cx = Sinatra::EventContext.new(stub_everything, Rack::Response.new, {})
lambda { lambda {
cx.status 404 cx.status 404
}.should.not.raise(ArgumentError) }.should.not.raise(ArgumentError)
end end
end end

View File

@ -13,7 +13,7 @@ context "Simple Events" do
event = Sinatra::Event.new(path, &b) event = Sinatra::Event.new(path, &b)
event.invoke(simple_request_hash(:get, request_path)) event.invoke(simple_request_hash(:get, request_path))
end end
specify "return last value" do specify "return last value" do
block = Proc.new { 'Simple' } block = Proc.new { 'Simple' }
result = invoke_simple('/', '/', &block) result = invoke_simple('/', '/', &block)
@ -21,27 +21,27 @@ context "Simple Events" do
result.block.should.be block result.block.should.be block
result.params.should.equal Hash.new result.params.should.equal Hash.new
end end
specify "takes params in path" do specify "takes params in path" do
result = invoke_simple('/:foo/:bar', '/a/b') result = invoke_simple('/:foo/:bar', '/a/b')
result.should.not.be.nil result.should.not.be.nil
result.params.should.equal "foo" => 'a', "bar" => 'b' result.params.should.equal "foo" => 'a', "bar" => 'b'
# unscapes # unscapes
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany') result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
result.should.not.be.nil result.should.not.be.nil
result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany' result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
end end
specify "ignores to many /'s" do specify "ignores to many /'s" do
result = invoke_simple('/x/y', '/x//y') result = invoke_simple('/x/y', '/x//y')
result.should.not.be.nil result.should.not.be.nil
end end
specify "understands splat" do specify "understands splat" do
invoke_simple('/foo/*', '/foo/bar').should.not.be.nil invoke_simple('/foo/*', '/foo/bar').should.not.be.nil
invoke_simple('/foo/*', '/foo/bar/baz').should.not.be.nil invoke_simple('/foo/*', '/foo/bar/baz').should.not.be.nil
invoke_simple('/foo/*', '/foo/baz').should.not.be.nil invoke_simple('/foo/*', '/foo/baz').should.not.be.nil
end end
end end

View File

@ -5,95 +5,95 @@ context "Haml" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
context "without layouts" do context "without layouts" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "should render" do specify "should render" do
get '/no_layout' do get '/no_layout' do
haml '== #{1+1}' haml '== #{1+1}'
end end
get_it '/no_layout' get_it '/no_layout'
should.be.ok should.be.ok
body.should == "2\n" body.should == "2\n"
end end
end end
context "with layouts" do context "with layouts" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "can be inline" do specify "can be inline" do
layout do layout do
'== This is #{yield}!' '== This is #{yield}!'
end end
get '/lay' do get '/lay' do
haml 'Blake' haml 'Blake'
end end
get_it '/lay' get_it '/lay'
should.be.ok should.be.ok
body.should.equal "This is Blake\n!\n" body.should.equal "This is Blake\n!\n"
end end
specify "can use named layouts" do specify "can use named layouts" do
layout :pretty do layout :pretty do
'%h1== #{yield}' '%h1== #{yield}'
end end
get '/pretty' do get '/pretty' do
haml 'Foo', :layout => :pretty haml 'Foo', :layout => :pretty
end end
get '/not_pretty' do get '/not_pretty' do
haml 'Bar' haml 'Bar'
end end
get_it '/pretty' get_it '/pretty'
body.should.equal "<h1>Foo</h1>\n" body.should.equal "<h1>Foo</h1>\n"
get_it '/not_pretty' get_it '/not_pretty'
body.should.equal "Bar\n" body.should.equal "Bar\n"
end end
specify "can be read from a file if they're not inlined" do specify "can be read from a file if they're not inlined" do
get '/foo' do get '/foo' do
@title = 'Welcome to the Hello Program' @title = 'Welcome to the Hello Program'
haml 'Blake', :layout => :foo_layout, haml 'Blake', :layout => :foo_layout,
:views_directory => File.dirname(__FILE__) + "/views" :views_directory => File.dirname(__FILE__) + "/views"
end end
get_it '/foo' get_it '/foo'
body.should.equal "Welcome to the Hello Program\nHi Blake\n" body.should.equal "Welcome to the Hello Program\nHi Blake\n"
end end
specify "can be read from file and layout from text" do specify "can be read from file and layout from text" do
get '/foo' do get '/foo' do
haml 'Test', :layout => '== Foo #{yield}' haml 'Test', :layout => '== Foo #{yield}'
end end
get_it '/foo' get_it '/foo'
body.should.equal "Foo Test\n" body.should.equal "Foo Test\n"
end end
end end
context "Templates (in general)" do context "Templates (in general)" do
setup do setup do
@ -136,21 +136,21 @@ context "Haml" do
body.should.equal "<h1>No Layout!</h1>\n" body.should.equal "<h1>No Layout!</h1>\n"
end end
specify "can render with no layout" do specify "can render with no layout" do
layout do layout do
"X\n= yield\nX" "X\n= yield\nX"
end end
get '/' do get '/' do
haml 'blake', :layout => false haml 'blake', :layout => false
end end
get_it '/' get_it '/'
body.should.equal "blake\n" body.should.equal "blake\n"
end end
specify "raises error if template not found" do specify "raises error if template not found" do
get '/' do get '/' do
haml :not_found haml :not_found
@ -175,7 +175,7 @@ context "Haml" do
body.should.equal "asdf\n" body.should.equal "asdf\n"
end end
end end
describe 'Options passed to the HAML interpreter' do describe 'Options passed to the HAML interpreter' do

View File

@ -3,59 +3,59 @@ require File.dirname(__FILE__) + '/helper'
class FooError < RuntimeError; end class FooError < RuntimeError; end
context "Mapped errors" do context "Mapped errors" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
specify "are rescued and run in context" do specify "are rescued and run in context" do
error FooError do error FooError do
'MAPPED ERROR!' 'MAPPED ERROR!'
end end
get '/' do get '/' do
raise FooError.new raise FooError.new
end end
get_it '/' get_it '/'
should.be.server_error should.be.server_error
body.should.equal 'MAPPED ERROR!' body.should.equal 'MAPPED ERROR!'
end end
specify "renders empty if no each method on result" do specify "renders empty if no each method on result" do
error FooError do error FooError do
nil nil
end end
get '/' do get '/' do
raise FooError.new raise FooError.new
end end
get_it '/' get_it '/'
should.be.server_error should.be.server_error
body.should.be.empty body.should.be.empty
end end
specify "doesn't override status if set" do specify "doesn't override status if set" do
error FooError do error FooError do
status(200) status(200)
end end
get '/' do get '/' do
raise FooError.new raise FooError.new
end end
get_it '/' get_it '/'
should.be.ok should.be.ok
end end
end end

View File

@ -1,12 +1,13 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
# XXX: How does any of this have anything to do with REST?
context "RESTful tests" do context "RESTful tests" do
specify "should take xml" do specify "should take xml" do
post '/foo.xml' do post '/foo.xml' do
request.body.string request.body.string
end end
post_it '/foo.xml', '<myxml></myxml>' post_it '/foo.xml', '<myxml></myxml>'
assert ok? assert ok?
assert_equal('<myxml></myxml>', body) assert_equal('<myxml></myxml>', body)

View File

@ -5,7 +5,7 @@ context "Sass" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
context "Templates (in general)" do context "Templates (in general)" do
setup do setup do
@ -23,7 +23,7 @@ context "Sass" do
body.should.equal "#sass {\n background_color: #FFF; }\n" body.should.equal "#sass {\n background_color: #FFF; }\n"
end end
specify "raise an error if template not found" do specify "raise an error if template not found" do
get '/' do get '/' do
sass :not_found sass :not_found
@ -31,27 +31,27 @@ context "Sass" do
lambda { get_it '/' }.should.raise(Errno::ENOENT) lambda { get_it '/' }.should.raise(Errno::ENOENT)
end end
specify "ignore default layout file with .sass extension" do specify "ignore default layout file with .sass extension" do
get '/' do get '/' do
sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test" sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end end
get_it '/' get_it '/'
should.be.ok should.be.ok
body.should.equal "#sass {\n background_color: #FFF; }\n" body.should.equal "#sass {\n background_color: #FFF; }\n"
end end
specify "ignore explicitly specified layout file" do specify "ignore explicitly specified layout file" do
get '/' do get '/' do
sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test" sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end end
get_it '/' get_it '/'
should.be.ok should.be.ok
body.should.equal "#sass {\n background_color: #FFF; }\n" body.should.equal "#sass {\n background_color: #FFF; }\n"
end end
end end
end end

View File

@ -13,7 +13,7 @@ context "Sessions" do
get '/test' do get '/test' do
session[:test] == true ? "true" : "false" session[:test] == true ? "true" : "false"
end end
get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com' get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
assert ok? assert ok?
assert !include?('Set-Cookie') assert !include?('Set-Cookie')
@ -33,7 +33,7 @@ context "Sessions" do
get_it '/foo', :env => { :host => 'foo.sinatrarb.com' } get_it '/foo', :env => { :host => 'foo.sinatrarb.com' }
assert ok? assert ok?
assert include?('Set-Cookie') assert include?('Set-Cookie')
end end
end end

View File

@ -86,7 +86,7 @@ context "Static files (by default)" do
end end
context "SendData" do context "SendData" do
setup do setup do
Sinatra.application = nil Sinatra.application = nil
end end
@ -95,13 +95,13 @@ context "SendData" do
get '/' do get '/' do
send_data 'asdf', :status => 500 send_data 'asdf', :status => 500
end end
get_it '/' get_it '/'
should.be.server_error should.be.server_error
body.should.equal 'asdf' body.should.equal 'asdf'
end end
specify "should include a Content-Disposition header" do specify "should include a Content-Disposition header" do
get '/' do get '/' do
send_file File.dirname(__FILE__) + '/public/foo.xml' send_file File.dirname(__FILE__) + '/public/foo.xml'

View File

@ -10,7 +10,7 @@ context "Symbol Params" do
get '/' do get '/' do
params[:foo] + params['foo'] params[:foo] + params['foo']
end end
get_it '/', :foo => "X" get_it '/', :foo => "X"
assert_equal('XX', body) assert_equal('XX', body)
end end

View File

@ -1,30 +1,30 @@
require File.dirname(__FILE__) + '/helper' require File.dirname(__FILE__) + '/helper'
context "Templates (in general)" do context "Templates (in general)" do
specify "are read from files if Symbols" do specify "are read from files if Symbols" do
get '/from_file' do get '/from_file' do
@name = 'Alena' @name = 'Alena'
erb :foo, :views_directory => File.dirname(__FILE__) + "/views" erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
end end
get_it '/from_file' get_it '/from_file'
body.should.equal 'You rock Alena!' body.should.equal 'You rock Alena!'
end end
specify "use layout.ext by default if available" do specify "use layout.ext by default if available" do
get '/layout_from_file' do get '/layout_from_file' do
erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test" erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
end end
get_it '/layout_from_file' get_it '/layout_from_file'
should.be.ok should.be.ok
body.should.equal "x This is foo! x \n" body.should.equal "x This is foo! x \n"
end end
end end

View File

@ -6,34 +6,33 @@ context "Rendering in file templates" do
Sinatra.application = nil Sinatra.application = nil
use_in_file_templates! use_in_file_templates!
end end
specify "should set template" do specify "should set template" do
assert Sinatra.application.templates[:foo] assert Sinatra.application.templates[:foo]
end end
specify "should set layout" do specify "should set layout" do
assert Sinatra.application.templates[:layout] assert Sinatra.application.templates[:layout]
end end
specify "should render without layout if specified" do specify "should render without layout if specified" do
get '/' do get '/' do
haml :foo, :layout => false haml :foo, :layout => false
end end
get_it '/' get_it '/'
assert_equal "this is foo\n", body assert_equal "this is foo\n", body
end end
specify "should render with layout if specified" do specify "should render with layout if specified" do
get '/' do get '/' do
haml :foo haml :foo
end end
get_it '/' get_it '/'
assert_equal "X\nthis is foo\nX\n", body assert_equal "X\nthis is foo\nX\n", body
end end
end end
__END__ __END__