Skip to content

Commit

Permalink
Fix constant resolution in specs under 1.9
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rtomayko committed Feb 3, 2009
1 parent 18dff71 commit d074e0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions test/helpers_test.rb
Expand Up @@ -380,10 +380,10 @@ def send_file_app(opts={})
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
Expand Down
12 changes: 6 additions & 6 deletions 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
Expand Down Expand Up @@ -80,9 +83,6 @@ class FooError < RuntimeError
assert_equal 404, status
end

class FooNotFound < Sinatra::NotFound
end

it "cascades for subclasses of Sinatra::NotFound" do
mock_app {
set :raise_errors, true
Expand Down
4 changes: 3 additions & 1 deletion test/middleware_test.rb
Expand Up @@ -4,7 +4,9 @@
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
}
Expand Down
18 changes: 8 additions & 10 deletions test/static_test.rb
@@ -1,25 +1,23 @@
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']
assert response.headers.include?('Last-Modified')
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 }
Expand All @@ -29,16 +27,16 @@
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']
assert response.headers.include?('Last-Modified')
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
Expand All @@ -50,13 +48,13 @@

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

Expand Down

0 comments on commit d074e0c

Please sign in to comment.