From d074e0c6f0dd8f5b2f0388f9057838f8a5e88d9b Mon Sep 17 00:00:00 2001 From: Ryan Tomayko Date: Fri, 30 Jan 2009 17:27:17 -0800 Subject: [PATCH] Fix constant resolution in specs under 1.9 The way constants are set/resolved in class_eval blocks seems to have changed significantly. Move constants to top-level to remedy the situation for now. --- test/helpers_test.rb | 6 +++--- test/mapped_error_test.rb | 12 ++++++------ test/middleware_test.rb | 4 +++- test/static_test.rb | 18 ++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/helpers_test.rb b/test/helpers_test.rb index c397dc86..d9815926 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -380,10 +380,10 @@ describe 'Helpers#etag' do end end -describe 'Adding new helpers' do - module HelperOne; def one; '1'; end; end - module HelperTwo; def two; '2'; end; end +module HelperOne; def one; '1'; end; end +module HelperTwo; def two; '2'; end; end +describe 'Adding new helpers' do it 'should allow passing a list of modules' do mock_app { helpers HelperOne, HelperTwo diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb index f9991650..c176aed8 100644 --- a/test/mapped_error_test.rb +++ b/test/mapped_error_test.rb @@ -1,9 +1,12 @@ require File.dirname(__FILE__) + '/helper' -describe 'Exception Mappings' do - class FooError < RuntimeError - end +class FooError < RuntimeError +end +class FooNotFound < Sinatra::NotFound +end + +describe 'Exception Mappings' do it 'invokes handlers registered with ::error when raised' do mock_app { set :raise_errors, false @@ -80,9 +83,6 @@ describe 'Exception Mappings' do assert_equal 404, status end - class FooNotFound < Sinatra::NotFound - end - it "cascades for subclasses of Sinatra::NotFound" do mock_app { set :raise_errors, true diff --git a/test/middleware_test.rb b/test/middleware_test.rb index 82887024..9f7eeebd 100644 --- a/test/middleware_test.rb +++ b/test/middleware_test.rb @@ -4,7 +4,9 @@ describe "Middleware" do before do @app = mock_app(Sinatra::Default) { get '/*' do - response.headers['X-Tests'] = env['test.ran'].join(', ') + response.headers['X-Tests'] = env['test.ran']. + map { |n| n.split('::').last }. + join(', ') env['PATH_INFO'] end } diff --git a/test/static_test.rb b/test/static_test.rb index 2dbca2d5..b79d5f92 100644 --- a/test/static_test.rb +++ b/test/static_test.rb @@ -1,17 +1,15 @@ require File.dirname(__FILE__) + '/helper' describe 'Static' do - F = ::File - before do mock_app { set :static, true - set :public, F.dirname(__FILE__) + set :public, File.dirname(__FILE__) } end it 'serves GET requests for files in the public directory' do - get "/#{F.basename(__FILE__)}" + get "/#{File.basename(__FILE__)}" assert ok? assert_equal File.read(__FILE__), body assert_equal File.size(__FILE__).to_s, response['Content-Length'] @@ -19,7 +17,7 @@ describe 'Static' do end it 'produces a body that can be iterated over multiple times' do - env = Rack::MockRequest.env_for("/#{F.basename(__FILE__)}") + env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}") status, headers, body = @app.call(env) buf1, buf2 = [], [] body.each { |part| buf1 << part } @@ -29,7 +27,7 @@ describe 'Static' do end it 'serves HEAD requests for files in the public directory' do - head "/#{F.basename(__FILE__)}" + head "/#{File.basename(__FILE__)}" assert ok? assert_equal '', body assert_equal File.size(__FILE__).to_s, response['Content-Length'] @@ -37,8 +35,8 @@ describe 'Static' do end it 'serves files in preference to custom routes' do - @app.get("/#{F.basename(__FILE__)}") { 'Hello World' } - get "/#{F.basename(__FILE__)}" + @app.get("/#{File.basename(__FILE__)}") { 'Hello World' } + get "/#{File.basename(__FILE__)}" assert ok? assert body != 'Hello World' end @@ -50,13 +48,13 @@ describe 'Static' do it 'passes to the next handler when the static option is disabled' do @app.set :static, false - get "/#{F.basename(__FILE__)}" + get "/#{File.basename(__FILE__)}" assert not_found? end it 'passes to the next handler when the public option is nil' do @app.set :public, nil - get "/#{F.basename(__FILE__)}" + get "/#{File.basename(__FILE__)}" assert not_found? end