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 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

View File

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

View File

@ -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

View File

@ -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 '<h1>Not Found</h1>'
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

View File

@ -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 '<h1>Not Found</h1>'
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 '<h1>Internal Server Error</h1>'
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

View File

@ -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

View File

@ -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{<h1><%= yield %></h1>}
end
get '/pretty' do
erb 'Foo', :layout => :pretty
end
get '/not_pretty' do
erb 'Bar'
end
get_it '/pretty'
body.should.equal '<h1>Foo</h1>'
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

View File

@ -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

View File

@ -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

View File

@ -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 "<h1>Foo</h1>\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 "<h1>No Layout!</h1>\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

View File

@ -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

View File

@ -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', '<myxml></myxml>'
assert ok?
assert_equal('<myxml></myxml>', body)

View File

@ -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

View File

@ -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

View File

@ -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'

View File

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

View File

@ -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

View File

@ -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__