Clean-up settings test

This commit is contained in:
Simon Rozet 2009-12-23 03:50:40 +01:00
parent c6304830cb
commit b1936b6a28
1 changed files with 42 additions and 53 deletions

View File

@ -3,24 +3,25 @@ require File.dirname(__FILE__) + '/helper'
class SettingsTest < Test::Unit::TestCase class SettingsTest < Test::Unit::TestCase
setup do setup do
@base = Sinatra.new(Sinatra::Base) @base = Sinatra.new(Sinatra::Base)
@base.set :environment, :foo
@application = Sinatra.new(Sinatra::Application) @application = Sinatra.new(Sinatra::Application)
@base.set :environment, :development @application.set :environment, :foo
@application.set :environment, :development
end end
it 'sets options to literal values' do it 'sets settings to literal values' do
@base.set(:foo, 'bar') @base.set(:foo, 'bar')
assert @base.respond_to?(:foo) assert @base.respond_to?(:foo)
assert_equal 'bar', @base.foo assert_equal 'bar', @base.foo
end end
it 'sets options to Procs' do it 'sets settings to Procs' do
@base.set(:foo, Proc.new { 'baz' }) @base.set(:foo, Proc.new { 'baz' })
assert @base.respond_to?(:foo) assert @base.respond_to?(:foo)
assert_equal 'baz', @base.foo assert_equal 'baz', @base.foo
end end
it "sets multiple options with a Hash" do it "sets multiple settings with a Hash" do
@base.set :foo => 1234, @base.set :foo => 1234,
:bar => 'Hello World', :bar => 'Hello World',
:baz => Proc.new { 'bizzle' } :baz => Proc.new { 'bizzle' }
@ -29,7 +30,7 @@ class SettingsTest < Test::Unit::TestCase
assert_equal 'bizzle', @base.baz assert_equal 'bizzle', @base.baz
end end
it 'inherits option methods when subclassed' do it 'inherits settings methods when subclassed' do
@base.set :foo, 'bar' @base.set :foo, 'bar'
@base.set :biz, Proc.new { 'baz' } @base.set :biz, Proc.new { 'baz' }
@ -40,7 +41,7 @@ class SettingsTest < Test::Unit::TestCase
assert_equal 'baz', sub.biz assert_equal 'baz', sub.biz
end end
it 'overrides options in subclass' do it 'overrides settings in subclass' do
@base.set :foo, 'bar' @base.set :foo, 'bar'
@base.set :biz, Proc.new { 'baz' } @base.set :biz, Proc.new { 'baz' }
sub = Class.new(@base) sub = Class.new(@base)
@ -78,31 +79,42 @@ class SettingsTest < Test::Unit::TestCase
assert_equal 'oops', @base.foo assert_equal 'oops', @base.foo
end end
it "sets multiple options to true with #enable" do it "sets multiple settings to true with #enable" do
@base.enable :sessions, :foo, :bar @base.enable :sessions, :foo, :bar
assert @base.sessions assert @base.sessions
assert @base.foo assert @base.foo
assert @base.bar assert @base.bar
end end
it "sets multiple options to false with #disable" do it "sets multiple settings to false with #disable" do
@base.disable :sessions, :foo, :bar @base.disable :sessions, :foo, :bar
assert !@base.sessions assert !@base.sessions
assert !@base.foo assert !@base.foo
assert !@base.bar assert !@base.bar
end end
it 'enables MethodOverride middleware when :methodoverride is enabled' do
@base.set :methodoverride, true
@base.put('/') { 'okay' }
@app = @base
post '/', {'_method'=>'PUT'}, {}
assert_equal 200, status
assert_equal 'okay', body
end
it 'is accessible from instances via #settings' do it 'is accessible from instances via #settings' do
assert_equal :development, @base.new.settings.environment assert_equal :foo, @base.new.settings.environment
end
describe 'methodoverride' do
it 'is disabled on Base' do
assert ! @base.methodoverride?
end
it 'is enabled on Application' do
assert @application.methodoverride?
end
it 'enables MethodOverride middleware' do
@base.set :methodoverride, true
@base.put('/') { 'okay' }
@app = @base
post '/', {'_method'=>'PUT'}, {}
assert_equal 200, status
assert_equal 'okay', body
end
end end
describe 'clean_trace' do describe 'clean_trace' do
@ -156,16 +168,12 @@ class SettingsTest < Test::Unit::TestCase
assert ! @base.run? assert ! @base.run?
end end
it 'is enabled on Application when not in test environment' do it 'is enabled on Application except in test environment' do
@application.set :environment, :development
assert @application.development?
assert @application.run? assert @application.run?
@application.set :environment, :development @application.set :environment, :test
assert @application.run? assert ! @application.run?
end end
# TODO: it 'is enabled when $0 == app_file'
end end
describe 'raise_errors' do describe 'raise_errors' do
@ -174,11 +182,6 @@ class SettingsTest < Test::Unit::TestCase
end end
it 'is enabled on Application only in test' do it 'is enabled on Application only in test' do
@application.set(:environment, :development)
assert @application.development?
assert ! @application.raise_errors?
@application.set(:environment, :production)
assert ! @application.raise_errors? assert ! @application.raise_errors?
@application.set(:environment, :test) @application.set(:environment, :test)
@ -187,23 +190,15 @@ class SettingsTest < Test::Unit::TestCase
end end
describe 'show_exceptions' do describe 'show_exceptions' do
%w[development test production none].each do |environment| it 'is disabled on Base' do
it "is disabled on Base in #{environment} environments" do assert ! @base.show_exceptions?
@base.set(:environment, environment)
assert ! @base.show_exceptions?
end
end end
it 'is enabled on Application only in development' do it 'is disabled on Application except in development' do
@base.set(:environment, :development)
assert @application.development?
assert @application.show_exceptions?
@application.set(:environment, :test)
assert ! @application.show_exceptions? assert ! @application.show_exceptions?
@base.set(:environment, :production) @application.set(:environment, :development)
assert ! @base.show_exceptions? assert @application.show_exceptions?
end end
it 'returns a friendly 500' do it 'returns a friendly 500' do
@ -263,8 +258,6 @@ class SettingsTest < Test::Unit::TestCase
it 'is disabled on Application' do it 'is disabled on Application' do
assert ! @application.sessions? assert ! @application.sessions?
end end
# TODO: it 'uses Rack::Session::Cookie when enabled' do
end end
describe 'logging' do describe 'logging' do
@ -272,14 +265,12 @@ class SettingsTest < Test::Unit::TestCase
assert ! @base.logging? assert ! @base.logging?
end end
it 'is enabled on Application when not in test environment' do it 'is enabled on Application except in test environment' do
assert @application.logging? assert @application.logging?
@application.set :environment, :test @application.set :environment, :test
assert ! @application.logging assert ! @application.logging
end end
# TODO: it 'uses Rack::CommonLogger when enabled' do
end end
describe 'static' do describe 'static' do
@ -290,9 +281,6 @@ class SettingsTest < Test::Unit::TestCase
it 'is enabled on Application' do it 'is enabled on Application' do
assert @application.static? assert @application.static?
end end
# TODO: it setup static routes if public is enabled
# TODO: however, that's already tested in static_test so...
end end
describe 'host' do describe 'host' do
@ -318,8 +306,8 @@ class SettingsTest < Test::Unit::TestCase
describe 'app_file' do describe 'app_file' do
it 'is nil' do it 'is nil' do
assert @base.app_file.nil? assert_nil @base.app_file
assert @application.app_file.nil? assert_nil @application.app_file
end end
end end
@ -371,6 +359,7 @@ class SettingsTest < Test::Unit::TestCase
describe 'lock' do describe 'lock' do
it 'is disabled by default' do it 'is disabled by default' do
assert ! @base.lock? assert ! @base.lock?
assert ! @application.lock?
end end
end end
end end