From f4b11b967fc7f412a1885b0ab7953cbfc901edb6 Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Fri, 5 Jun 2009 21:53:27 -0700 Subject: [PATCH] Remove 0.9.x compatibility specs :) --- Rakefile | 21 +- compat/app_test.rb | 282 ----------------------- compat/application_test.rb | 262 --------------------- compat/builder_test.rb | 101 -------- compat/compat_test.rb | 12 - compat/custom_error_test.rb | 62 ----- compat/erb_test.rb | 136 ----------- compat/events_test.rb | 78 ------- compat/filter_test.rb | 30 --- compat/haml_test.rb | 236 ------------------- compat/helper.rb | 33 --- compat/mapped_error_test.rb | 72 ------ compat/pipeline_test.rb | 45 ---- compat/public/foo.xml | 1 - compat/sass_test.rb | 67 ------ compat/sessions_test.rb | 42 ---- compat/streaming_test.rb | 133 ----------- compat/sym_params_test.rb | 19 -- compat/template_test.rb | 30 --- compat/use_in_file_templates_test.rb | 47 ---- compat/views/foo.builder | 1 - compat/views/foo.erb | 1 - compat/views/foo.haml | 1 - compat/views/foo.sass | 2 - compat/views/foo_layout.erb | 2 - compat/views/foo_layout.haml | 2 - compat/views/layout_test/foo.builder | 1 - compat/views/layout_test/foo.erb | 1 - compat/views/layout_test/foo.haml | 1 - compat/views/layout_test/foo.sass | 2 - compat/views/layout_test/layout.builder | 3 - compat/views/layout_test/layout.erb | 1 - compat/views/layout_test/layout.haml | 1 - compat/views/layout_test/layout.sass | 2 - compat/views/no_layout/no_layout.builder | 1 - compat/views/no_layout/no_layout.haml | 1 - 36 files changed, 1 insertion(+), 1731 deletions(-) delete mode 100644 compat/app_test.rb delete mode 100644 compat/application_test.rb delete mode 100644 compat/builder_test.rb delete mode 100644 compat/compat_test.rb delete mode 100644 compat/custom_error_test.rb delete mode 100644 compat/erb_test.rb delete mode 100644 compat/events_test.rb delete mode 100644 compat/filter_test.rb delete mode 100644 compat/haml_test.rb delete mode 100644 compat/helper.rb delete mode 100644 compat/mapped_error_test.rb delete mode 100644 compat/pipeline_test.rb delete mode 100644 compat/public/foo.xml delete mode 100644 compat/sass_test.rb delete mode 100644 compat/sessions_test.rb delete mode 100644 compat/streaming_test.rb delete mode 100644 compat/sym_params_test.rb delete mode 100644 compat/template_test.rb delete mode 100644 compat/use_in_file_templates_test.rb delete mode 100644 compat/views/foo.builder delete mode 100644 compat/views/foo.erb delete mode 100644 compat/views/foo.haml delete mode 100644 compat/views/foo.sass delete mode 100644 compat/views/foo_layout.erb delete mode 100644 compat/views/foo_layout.haml delete mode 100644 compat/views/layout_test/foo.builder delete mode 100644 compat/views/layout_test/foo.erb delete mode 100644 compat/views/layout_test/foo.haml delete mode 100644 compat/views/layout_test/foo.sass delete mode 100644 compat/views/layout_test/layout.builder delete mode 100644 compat/views/layout_test/layout.erb delete mode 100644 compat/views/layout_test/layout.haml delete mode 100644 compat/views/layout_test/layout.sass delete mode 100644 compat/views/no_layout/no_layout.builder delete mode 100644 compat/views/no_layout/no_layout.haml diff --git a/Rakefile b/Rakefile index c541c340..34217102 100644 --- a/Rakefile +++ b/Rakefile @@ -2,35 +2,16 @@ require 'rake/clean' require 'rake/testtask' require 'fileutils' -task :default => [:test, :compat] +task :default => :test task :spec => :test # SPECS =============================================================== -task(:test) { puts "==> Running main test suite" } - Rake::TestTask.new(:test) do |t| t.test_files = FileList['test/*_test.rb'] t.ruby_opts = ['-rubygems'] if defined? Gem end -desc "Run < 0.9.x compatibility specs" -task :compat do - begin - require 'mocha' - require 'test/spec' - at_exit { exit 0 } # disable test-spec at_exit runner - - puts "==> Running compat test suite" - Rake::TestTask.new(:compat) do |t| - t.test_files = FileList['compat/*_test.rb'] - t.ruby_opts = ['-rubygems'] if defined? Gem - end - rescue LoadError - warn 'Skipping compat tests. mocha and/or test-spec gems not installed.' - end -end - # PACKAGING ============================================================ # Load the gemspec using the same limitations as github diff --git a/compat/app_test.rb b/compat/app_test.rb deleted file mode 100644 index 1a17eb63..00000000 --- a/compat/app_test.rb +++ /dev/null @@ -1,282 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Sinatra" do - - setup do - Sinatra.application = nil - end - - specify "should put all DSL methods on (main)" do - object = Object.new - methods = %w[get put post head delete configure template helpers set] - methods.each do |method| - object.private_methods.map { |m| m.to_sym }.should.include(method.to_sym) - end - end - - specify "should handle result of nil" 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 - - specify "handles multiple splats" do - get '/say/*/to/*' do - params["splat"].join(' ') - end - - get_it '/say/hello/to/world' - - should.be.ok - body.should.equal 'hello world' - end - - specify "allow empty splats" 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 - - specify "gives access to underlying response header Hash" do - get '/' do - header['X-Test'] = 'Is this thing on?' - headers 'X-Test2' => 'Foo', 'X-Test3' => 'Bar' - '' - end - - get_it '/' - should.be.ok - headers.should.include 'X-Test' - headers['X-Test'].should.equal 'Is this thing on?' - headers.should.include 'X-Test3' - headers['X-Test3'].should.equal 'Bar' - end - - specify "follows redirects" 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 - helpers do - def foo ; 'blah' ; end - end - get "/" do - redirect 'foo', :foo - end - get_it '/' - should.be.redirection - headers['Location'].should.equal 'foo' - body.should.equal 'blah' - end - - specify "redirects permanently with 301 status code" do - get "/" do - redirect 'foo', 301 - end - get_it '/' - should.be.redirection - headers['Location'].should.equal 'foo' - status.should.equal 301 - body.should.be.empty - end - - specify "stop sets content and ends event" do - get '/set_body' do - stop 'Hello!' - stop 'World!' - fail 'stop should have halted' - end - - get_it '/set_body' - - should.be.ok - body.should.equal 'Hello!' - - end - - specify "should easily set response Content-Type" do - get '/foo.html' do - content_type 'text/html', :charset => 'utf-8' - "

Hello, World

" - end - - get_it '/foo.html' - should.be.ok - headers['Content-Type'].should.equal 'text/html;charset=utf-8' - body.should.equal '

Hello, World

' - - get '/foo_test.xml' do - content_type :xml - "" - end - - get_it '/foo_test.xml' - should.be.ok - headers['Content-Type'].should.equal 'application/xml' - body.should.equal '' - end - - specify "supports conditional GETs with last_modified" do - modified_at = Time.now - get '/maybe' do - last_modified modified_at - 'response body, maybe' - end - - get_it '/maybe' - should.be.ok - body.should.equal 'response body, maybe' - - get_it '/maybe', :env => { 'HTTP_IF_MODIFIED_SINCE' => modified_at.httpdate } - status.should.equal 304 - body.should.equal '' - end - - specify "supports conditional GETs with entity_tag" do - get '/strong' do - entity_tag 'FOO' - 'foo response' - end - - get_it '/strong' - should.be.ok - body.should.equal 'foo response' - - get_it '/strong', {}, - 'HTTP_IF_NONE_MATCH' => '"BAR"' - should.be.ok - body.should.equal 'foo response' - - get_it '/strong', {}, - 'HTTP_IF_NONE_MATCH' => '"FOO"' - status.should.equal 304 - body.should.equal '' - - get_it '/strong', {}, - 'HTTP_IF_NONE_MATCH' => '"BAR", *' - status.should.equal 304 - body.should.equal '' - end - - specify "delegates HEAD requests to GET handlers" do - get '/invisible' do - "I am invisible to the world" - end - - head_it '/invisible' - should.be.ok - body.should.not.equal "I am invisible to the world" - body.should.equal '' - end - - - specify "supports PUT" do - put '/' do - 'puted' - end - put_it '/' - assert_equal 'puted', body - end - - specify "rewrites POSTs with _method param to PUT" do - put '/' do - 'puted' - end - post_it '/', :_method => 'PUT' - assert_equal 'puted', body - end - - specify "rewrites POSTs with lowercase _method param to PUT" do - put '/' do - 'puted' - end - post_it '/', :_method => 'put' - body.should.equal 'puted' - end - - specify "does not rewrite GETs with _method param to PUT" do - get '/' do - 'getted' - end - get_it '/', :_method => 'put' - should.be.ok - body.should.equal 'getted' - end - - specify "ignores _method query string parameter on non-POST requests" do - post '/' do - 'posted' - end - put '/' do - 'booo' - end - post_it "/?_method=PUT" - should.be.ok - body.should.equal 'posted' - end - - specify "does not read body if content type is not url encoded" do - post '/foo.xml' do - request.env['CONTENT_TYPE'].should.be == 'application/xml' - request.content_type.should.be == 'application/xml' - request.body.read - end - - post_it '/foo.xml', '', :content_type => 'application/xml' - @response.should.be.ok - @response.body.should.be == '' - end - -end diff --git a/compat/application_test.rb b/compat/application_test.rb deleted file mode 100644 index af8d33b2..00000000 --- a/compat/application_test.rb +++ /dev/null @@ -1,262 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -require 'uri' - -class TesterWithEach - def each - yield 'foo' - yield 'bar' - yield 'baz' - 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' - end - get_it '/' - 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 "404 if NotFound is raised" do - - get '/' do - raise Sinatra::NotFound - end - - get_it '/' - should.be.not_found - - end - -end - -context "Application#configure blocks" do - - setup do - Sinatra.application = nil - end - - specify "run when no environment specified" do - ref = false - configure { ref = true } - ref.should.equal true - end - - specify "run when matching environment specified" do - ref = false - configure(:test) { ref = true } - ref.should.equal true - end - - specify "do not run when no matching environment specified" do - configure(:foo) { flunk "block should not have been executed" } - configure(:development, :production, :foo) { flunk "block should not have been executed" } - end - - specify "accept multiple environments" do - ref = false - configure(:foo, :test, :bar) { ref = true } - ref.should.equal true - end - -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' - - get_it '/', :env => { :agent => 'Mac' } - should.not.be.ok - - 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 - - specify "route based on host" do - - get '/' do - 'asdf' - end - - get_it '/' - assert ok? - assert_equal('asdf', body) - - get '/foo', :host => 'foo.sinatrarb.com' do - 'in foo!' - end - - 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 - - get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com' - assert ok? - assert_equal 'in bar!', body - - get_it '/foo' - assert not_found? - - end - -end - - -context "Options in an app" do - - setup do - Sinatra.application = nil - @app = Sinatra::application - end - - specify "can be set singly on app" do - @app.set :foo, 1234 - @app.options.foo.should.equal 1234 - end - - specify "can be set singly from top-level" do - set_option :foo, 1234 - @app.options.foo.should.equal 1234 - end - - specify "can be set multiply on app" do - @app.options.foo.should.be.nil - @app.set :foo => 1234, - :bar => 'hello, world' - @app.options.foo.should.equal 1234 - @app.options.bar.should.equal 'hello, world' - end - - specify "can be set multiply from top-level" do - @app.options.foo.should.be.nil - set_options :foo => 1234, - :bar => 'hello, world' - @app.options.foo.should.equal 1234 - @app.options.bar.should.equal 'hello, world' - end - - specify "can be enabled on app" do - @app.options.foo.should.be.nil - @app.enable :sessions, :foo, :bar - @app.options.sessions.should.equal true - @app.options.foo.should.equal true - @app.options.bar.should.equal true - end - - specify "can be enabled from top-level" do - @app.options.foo.should.be.nil - enable :sessions, :foo, :bar - @app.options.sessions.should.equal true - @app.options.foo.should.equal true - @app.options.bar.should.equal true - end - - specify "can be disabled on app" do - @app.options.foo.should.be.nil - @app.disable :sessions, :foo, :bar - @app.options.sessions.should.equal false - @app.options.foo.should.equal false - @app.options.bar.should.equal false - end - - specify "can be enabled from top-level" do - @app.options.foo.should.be.nil - disable :sessions, :foo, :bar - @app.options.sessions.should.equal false - @app.options.foo.should.equal false - @app.options.bar.should.equal false - end - -end diff --git a/compat/builder_test.rb b/compat/builder_test.rb deleted file mode 100644 index 5abc83bd..00000000 --- a/compat/builder_test.rb +++ /dev/null @@ -1,101 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Builder" 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 - builder 'xml.instruct!' - end - - get_it '/no_layout' - should.be.ok - body.should == %(\n) - - end - - specify "should render inline block" do - - get '/no_layout_and_inlined' do - @name = "Frank & Mary" - builder do |xml| - xml.couple @name - end - end - - get_it '/no_layout_and_inlined' - should.be.ok - body.should == %(Frank & Mary\n) - - end - - end - - - - context "Templates (in general)" do - - setup do - Sinatra.application = nil - end - - specify "are read from files if Symbols" do - - get '/from_file' do - @name = 'Blue' - builder :foo, :views_directory => File.dirname(__FILE__) + "/views" - end - - get_it '/from_file' - should.be.ok - body.should.equal %(You rock Blue!\n) - - end - - specify "use layout.ext by default if available" do - - get '/' do - builder :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test" - end - - get_it '/' - should.be.ok - body.should.equal "\nis foo!\n\n" - - end - - specify "renders without layout" do - - get '/' do - builder :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout" - end - - get_it '/' - should.be.ok - body.should.equal "No Layout!\n" - - end - - specify "raises error if template not found" do - - get '/' do - builder :not_found - end - - lambda { get_it '/' }.should.raise(Errno::ENOENT) - - end - - end - -end diff --git a/compat/compat_test.rb b/compat/compat_test.rb deleted file mode 100644 index 00978197..00000000 --- a/compat/compat_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Compat" do - setup do - Sinatra.application = nil - @app = Sinatra.application - end - - specify "makes EventContext available" do - assert_same Sinatra::Default, Sinatra::EventContext - end -end diff --git a/compat/custom_error_test.rb b/compat/custom_error_test.rb deleted file mode 100644 index e4fdb759..00000000 --- a/compat/custom_error_test.rb +++ /dev/null @@ -1,62 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Custom Errors" 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/compat/erb_test.rb b/compat/erb_test.rb deleted file mode 100644 index 51a79593..00000000 --- a/compat/erb_test.rb +++ /dev/null @@ -1,136 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -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' - - end - - specify "should take an options hash with :locals set with a string" do - get '/locals' do - erb '<%= foo %>', :locals => {:foo => "Bar"} - end - - get_it '/locals' - should.be.ok - body.should == 'Bar' - end - - specify "should take an options hash with :locals set with a complex object" do - get '/locals-complex' do - erb '<%= foo[0] %>', :locals => {:foo => ["foo", "bar", "baz"]} - end - - get_it '/locals-complex' - should.be.ok - 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 - - 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 - -end diff --git a/compat/events_test.rb b/compat/events_test.rb deleted file mode 100644 index 42cdb95c..00000000 --- a/compat/events_test.rb +++ /dev/null @@ -1,78 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Simple Events" do - def simple_request_hash(method, path) - Rack::Request.new({ - 'REQUEST_METHOD' => method.to_s.upcase, - 'PATH_INFO' => path - }) - end - - class MockResult < Struct.new(:block, :params) - end - - def invoke_simple(path, request_path, &b) - params = nil - get path do - params = self.params - b.call if b - end - get_it request_path - MockResult.new(b, params) - end - - setup { Sinatra.application = nil } - - specify "return last value" do - block = Proc.new { 'Simple' } - result = invoke_simple('/', '/', &block) - result.should.not.be.nil - 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 - Sinatra.application = nil - result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany') - result.should.not.be.nil - result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany' - end - - specify "takes optional params in path" do - result = invoke_simple('/?:foo?/?:bar?', '/a/b') - result.should.not.be.nil - result.params.should.equal "foo" => 'a', "bar" => 'b' - - Sinatra.application = nil - result = invoke_simple('/?:foo?/?:bar?', '/a/') - result.should.not.be.nil - result.params.should.equal "foo" => 'a', "bar" => nil - - Sinatra.application = nil - result = invoke_simple('/?:foo?/?:bar?', '/a') - result.should.not.be.nil - result.params.should.equal "foo" => 'a', "bar" => nil - - Sinatra.application = nil - result = invoke_simple('/:foo?/?:bar?', '/') - result.should.not.be.nil - result.params.should.equal "foo" => nil, "bar" => nil - 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 diff --git a/compat/filter_test.rb b/compat/filter_test.rb deleted file mode 100644 index 0a52ec6f..00000000 --- a/compat/filter_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "before filters" do - - setup do - Sinatra.application = nil - @app = Sinatra.application - end - - specify "should be executed in the order defined" do - invoked = 0x0 - @app.before { invoked = 0x01 } - @app.before { invoked |= 0x02 } - @app.get('/') { 'Hello World' } - get_it '/' - should.be.ok - body.should.be == 'Hello World' - invoked.should.be == 0x03 - end - - specify "should be capable of modifying the request" do - @app.get('/foo') { 'foo' } - @app.get('/bar') { 'bar' } - @app.before { request.path_info = '/bar' } - get_it '/foo' - should.be.ok - body.should.be == 'bar' - end - -end diff --git a/compat/haml_test.rb b/compat/haml_test.rb deleted file mode 100644 index 532414cd..00000000 --- a/compat/haml_test.rb +++ /dev/null @@ -1,236 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -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 - Sinatra.application = nil - end - - specify "are read from files if Symbols" do - - get '/from_file' do - @name = 'Alena' - haml :foo, :views_directory => File.dirname(__FILE__) + "/views" - end - - get_it '/from_file' - - body.should.equal "You rock Alena!\n" - - end - - specify "use layout.ext by default if available" do - - get '/' do - haml :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test" - end - - get_it '/' - should.be.ok - body.should.equal "x This is foo!\n x\n" - - end - - specify "renders without layout" do - - get '/' do - haml :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout" - end - - get_it '/' - should.be.ok - 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 - end - - lambda { get_it '/' }.should.raise(Errno::ENOENT) - end - - specify "use layout.ext by default if available" do - - template :foo do - 'asdf' - end - - get '/' do - haml :foo, :layout => false, - :views_directory => File.dirname(__FILE__) + "/views/layout_test" - end - - get_it '/' - should.be.ok - body.should.equal "asdf\n" - - end - - end - - describe 'Options passed to the HAML interpreter' do - setup do - Sinatra.application = nil - end - - specify 'default to filename and line of caller' do - - get '/' do - haml 'foo' - end - - Haml::Engine.expects(:new).with('foo', {:filename => __FILE__, - :line => (__LINE__-4)}).returns(stub(:render => 'foo')) - - get_it '/' - should.be.ok - - end - - specify 'can be configured by passing :options to haml' do - - get '/' do - haml 'foo', :options => {:format => :html4} - end - - Haml::Engine.expects(:new).with('foo', {:filename => __FILE__, - :line => (__LINE__-4), :format => :html4}).returns(stub(:render => 'foo')) - - get_it '/' - should.be.ok - - end - - specify 'can be configured using set_option :haml' do - - configure do - set_option :haml, :format => :html4, - :escape_html => true - end - - get '/' do - haml 'foo' - end - - Haml::Engine.expects(:new).with('foo', {:filename => __FILE__, - :line => (__LINE__-4), :format => :html4, - :escape_html => true}).returns(stub(:render => 'foo')) - - get_it '/' - should.be.ok - - end - - end - -end diff --git a/compat/helper.rb b/compat/helper.rb deleted file mode 100644 index 696fe96e..00000000 --- a/compat/helper.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'rubygems' -require 'mocha' - -# disable warnings in compat specs. -$VERBOSE = nil - -$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib" - -ENV['RACK_ENV'] ||= 'test' - -require 'sinatra' -require 'sinatra/test' -require 'sinatra/test/unit' -require 'sinatra/test/spec' - -module Sinatra::Test - # we need to remove the new test helper methods since they conflict with - # the top-level methods of the same name. - %w(get head post put delete).each do |verb| - remove_method verb - end - include Sinatra::Delegator -end - -class Test::Unit::TestCase - include Sinatra::Test - - PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS) - - def setup - @app = lambda { |env| Sinatra::Application.call(env) } - end -end diff --git a/compat/mapped_error_test.rb b/compat/mapped_error_test.rb deleted file mode 100644 index e6256b47..00000000 --- a/compat/mapped_error_test.rb +++ /dev/null @@ -1,72 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -class FooError < RuntimeError; end - -context "Mapped errors" do - - setup do - Sinatra.application = nil - Sinatra.application.options.raise_errors = false - end - - specify "are rescued and run in context" do - - error FooError do - 'MAPPED ERROR!' - end - - get '/' do - raise FooError - 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 - 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 - end - - get_it '/' - - should.be.ok - - end - - specify "raises errors when the raise_errors option is set" do - Sinatra.application.options.raise_errors = true - error FooError do - end - get '/' do - raise FooError - end - assert_raises(FooError) { get_it('/') } - end - -end diff --git a/compat/pipeline_test.rb b/compat/pipeline_test.rb deleted file mode 100644 index a9eb360a..00000000 --- a/compat/pipeline_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -class UpcaseMiddleware - def initialize(app, *args, &block) - @app = app - @args = args - @block = block - end - def call(env) - env['PATH_INFO'] = env['PATH_INFO'].to_s.upcase - @app.call(env) - end -end - -context "Middleware Pipelines" do - - setup do - Sinatra.application = nil - @app = Sinatra.application - end - - teardown do - Sinatra.application = nil - end - - specify "should add middleware with use" do - block = Proc.new { |env| } - @app.use UpcaseMiddleware - @app.use UpcaseMiddleware, "foo", "bar" - @app.use UpcaseMiddleware, "foo", "bar", &block - @app.send(:middleware).should.include([UpcaseMiddleware, [], nil]) - @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], nil]) - @app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], block]) - end - - specify "should run middleware added with use" do - get('/foo') { "FAIL!" } - get('/FOO') { "PASS!" } - use UpcaseMiddleware - get_it '/foo' - should.be.ok - body.should.equal "PASS!" - end - -end diff --git a/compat/public/foo.xml b/compat/public/foo.xml deleted file mode 100644 index 74d9a6d3..00000000 --- a/compat/public/foo.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/compat/sass_test.rb b/compat/sass_test.rb deleted file mode 100644 index 1b9745cc..00000000 --- a/compat/sass_test.rb +++ /dev/null @@ -1,67 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Sass" do - - setup do - Sinatra.application = nil - end - - context "Templates (in general)" do - - setup do - Sinatra.application = nil - end - - specify "are read from files if Symbols" do - - get '/from_file' do - sass :foo, :views_directory => File.dirname(__FILE__) + "/views" - end - - get_it '/from_file' - should.be.ok - body.should.equal "#sass {\n background_color: #FFF; }\n" - - end - - specify "raise an error if template not found" do - get '/' do - sass :not_found - end - - 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 - - it "passes :sass option to the Sass engine" do - get '/' do - sass "#sass\n :background-color #FFF\n :color #000\n", :sass => {:style => :compact} - end - - get_it '/' - should.be.ok - body.should.equal "#sass { background-color: #FFF; color: #000; }\n" - end - - end - -end diff --git a/compat/sessions_test.rb b/compat/sessions_test.rb deleted file mode 100644 index 9d9622db..00000000 --- a/compat/sessions_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Sessions" do - - setup { Sinatra.application = nil } - - specify "should be off by default" do - get '/asdf' do - session[:test] = true - "asdf" - end - - get '/test' do - session[:test] == true ? "true" : "false" - end - - get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com' - assert ok? - assert !include?('Set-Cookie') - end - - specify "should be able to store data accross requests" do - set_option :sessions, true - set_option :environment, :not_test # necessary because sessions are disabled - - get '/foo' do - session[:test] = true - "asdf" - end - - get '/bar' do - session[:test] == true ? "true" : "false" - end - - get_it '/foo', :env => { :host => 'foo.sinatrarb.com' } - assert ok? - assert include?('Set-Cookie') - - set_option :environment, :test - end - -end diff --git a/compat/streaming_test.rb b/compat/streaming_test.rb deleted file mode 100644 index cf3727be..00000000 --- a/compat/streaming_test.rb +++ /dev/null @@ -1,133 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Static files (by default)" do - - setup do - Sinatra.application = nil - Sinatra.application.options.public = File.dirname(__FILE__) + '/public' - end - - specify "are served from root/public" do - get_it '/foo.xml' - should.be.ok - headers['Content-Length'].should.equal '12' - headers['Content-Type'].should.equal 'application/xml' - body.should.equal "\n" - end - - specify "are not served when verb is not GET or HEAD" do - post_it '/foo.xml' - # these should actually be giving back a 405 Method Not Allowed but that - # complicates the routing logic quite a bit. - should.be.not_found - status.should.equal 404 - end - - specify "are served when verb is HEAD but missing a body" do - head_it '/foo.xml' - should.be.ok - headers['Content-Length'].should.equal '12' - headers['Content-Type'].should.equal 'application/xml' - body.should.equal "" - end - - # static files override dynamic/internal events and ... - specify "are served when conflicting events exists" do - get '/foo.xml' do - 'this is not foo.xml!' - end - get_it '/foo.xml' - should.be.ok - body.should.equal "\n" - end - - specify "are irrelevant when request_method is not GET/HEAD" do - put '/foo.xml' do - 'putted!' - end - put_it '/foo.xml' - should.be.ok - body.should.equal 'putted!' - - get_it '/foo.xml' - should.be.ok - body.should.equal "\n" - end - - specify "include a Last-Modified header" do - last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml') - get_it('/foo.xml') - should.be.ok - body.should.not.be.empty - headers['Last-Modified'].should.equal last_modified.httpdate - end - - # Deprecated. Use: ConditionalGet middleware. - specify "are not served when If-Modified-Since matches" do - last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml') - @request = Rack::MockRequest.new(Sinatra.application) - @response = @request.get('/foo.xml', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate) - status.should.equal 304 - body.should.be.empty - end - - specify "should omit Content-Disposition headers" do - get_it('/foo.xml') - should.be.ok - headers['Content-Disposition'].should.be.nil - headers['Content-Transfer-Encoding'].should.be.nil - end - - specify "should be served even if their path is url escaped" do - get_it('/fo%6f.xml') - should.be.ok - body.should.equal "\n" - end - -end - -context "SendData" do - - setup do - Sinatra.application = nil - end - - # Deprecated. send_data is going away. - specify "should send the data with options" do - get '/' do - send_data 'asdf', :status => 500 - end - - get_it '/' - - should.be.server_error - body.should.equal 'asdf' - end - - # Deprecated. The Content-Disposition is no longer handled by sendfile. - specify "should include a Content-Disposition header" do - get '/' do - send_file File.dirname(__FILE__) + '/public/foo.xml', - :disposition => 'attachment' - end - - get_it '/' - - should.be.ok - headers['Content-Disposition'].should.not.be.nil - headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"' - end - - specify "should include a Content-Disposition header when :disposition set to attachment" do - get '/' do - send_file File.dirname(__FILE__) + '/public/foo.xml', - :disposition => 'attachment' - end - - get_it '/' - - should.be.ok - headers['Content-Disposition'].should.not.be.nil - headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"' - end -end diff --git a/compat/sym_params_test.rb b/compat/sym_params_test.rb deleted file mode 100644 index 2172be0c..00000000 --- a/compat/sym_params_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Symbol Params" do - - setup do - Sinatra.application = nil - end - - specify "should be accessable as Strings or Symbols" do - get '/' do - params[:foo] + params['foo'] - end - - get_it '/', :foo => "X" - assert_equal('XX', body) - end - -end - diff --git a/compat/template_test.rb b/compat/template_test.rb deleted file mode 100644 index 1e27578f..00000000 --- a/compat/template_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Templates" 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/compat/use_in_file_templates_test.rb b/compat/use_in_file_templates_test.rb deleted file mode 100644 index 265f07de..00000000 --- a/compat/use_in_file_templates_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require File.dirname(__FILE__) + '/helper' - -context "Rendering in file templates" do - - setup 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__ - -@@ foo -this is foo - -@@ layout -X -= yield -X - diff --git a/compat/views/foo.builder b/compat/views/foo.builder deleted file mode 100644 index dfa91a64..00000000 --- a/compat/views/foo.builder +++ /dev/null @@ -1 +0,0 @@ -xml.exclaim "You rock #{@name}!" diff --git a/compat/views/foo.erb b/compat/views/foo.erb deleted file mode 100644 index fac96378..00000000 --- a/compat/views/foo.erb +++ /dev/null @@ -1 +0,0 @@ -You rock <%= @name %>! \ No newline at end of file diff --git a/compat/views/foo.haml b/compat/views/foo.haml deleted file mode 100644 index 0fcc4f40..00000000 --- a/compat/views/foo.haml +++ /dev/null @@ -1 +0,0 @@ -== You rock #{@name}! \ No newline at end of file diff --git a/compat/views/foo.sass b/compat/views/foo.sass deleted file mode 100644 index 12340f70..00000000 --- a/compat/views/foo.sass +++ /dev/null @@ -1,2 +0,0 @@ -#sass - :background_color #FFF \ No newline at end of file diff --git a/compat/views/foo_layout.erb b/compat/views/foo_layout.erb deleted file mode 100644 index 6e39e8c7..00000000 --- a/compat/views/foo_layout.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= @title %> -Hi <%= yield %> diff --git a/compat/views/foo_layout.haml b/compat/views/foo_layout.haml deleted file mode 100644 index 5c041fb0..00000000 --- a/compat/views/foo_layout.haml +++ /dev/null @@ -1,2 +0,0 @@ -== #{@title} -== Hi #{yield} diff --git a/compat/views/layout_test/foo.builder b/compat/views/layout_test/foo.builder deleted file mode 100644 index 910eb1de..00000000 --- a/compat/views/layout_test/foo.builder +++ /dev/null @@ -1 +0,0 @@ -xml.this "is foo!" diff --git a/compat/views/layout_test/foo.erb b/compat/views/layout_test/foo.erb deleted file mode 100644 index 10872edd..00000000 --- a/compat/views/layout_test/foo.erb +++ /dev/null @@ -1 +0,0 @@ -This is foo! \ No newline at end of file diff --git a/compat/views/layout_test/foo.haml b/compat/views/layout_test/foo.haml deleted file mode 100644 index 10872edd..00000000 --- a/compat/views/layout_test/foo.haml +++ /dev/null @@ -1 +0,0 @@ -This is foo! \ No newline at end of file diff --git a/compat/views/layout_test/foo.sass b/compat/views/layout_test/foo.sass deleted file mode 100644 index 12340f70..00000000 --- a/compat/views/layout_test/foo.sass +++ /dev/null @@ -1,2 +0,0 @@ -#sass - :background_color #FFF \ No newline at end of file diff --git a/compat/views/layout_test/layout.builder b/compat/views/layout_test/layout.builder deleted file mode 100644 index 9491f574..00000000 --- a/compat/views/layout_test/layout.builder +++ /dev/null @@ -1,3 +0,0 @@ -xml.layout do - xml << yield -end diff --git a/compat/views/layout_test/layout.erb b/compat/views/layout_test/layout.erb deleted file mode 100644 index 7fec122a..00000000 --- a/compat/views/layout_test/layout.erb +++ /dev/null @@ -1 +0,0 @@ -x <%= yield %> x diff --git a/compat/views/layout_test/layout.haml b/compat/views/layout_test/layout.haml deleted file mode 100644 index 75efae53..00000000 --- a/compat/views/layout_test/layout.haml +++ /dev/null @@ -1 +0,0 @@ -== x #{yield} x diff --git a/compat/views/layout_test/layout.sass b/compat/views/layout_test/layout.sass deleted file mode 100644 index b2ee9d07..00000000 --- a/compat/views/layout_test/layout.sass +++ /dev/null @@ -1,2 +0,0 @@ -b0rked! -= yield \ No newline at end of file diff --git a/compat/views/no_layout/no_layout.builder b/compat/views/no_layout/no_layout.builder deleted file mode 100644 index cbf4be6d..00000000 --- a/compat/views/no_layout/no_layout.builder +++ /dev/null @@ -1 +0,0 @@ -xml.foo "No Layout!" diff --git a/compat/views/no_layout/no_layout.haml b/compat/views/no_layout/no_layout.haml deleted file mode 100644 index 0e6bd342..00000000 --- a/compat/views/no_layout/no_layout.haml +++ /dev/null @@ -1 +0,0 @@ -%h1 No Layout! \ No newline at end of file