Browse files

Get rid of Default

TODO: clean the options^Wsettings test
  • Loading branch information...
1 parent 1b2ab3a commit af1ee6ae94f4eeb438ce2273055b8c129bfece2a @sr sr committed Oct 14, 2009
Showing with 59 additions and 62 deletions.
  1. +0 −3 lib/sinatra/base.rb
  2. +8 −8 test/extensions_test.rb
  3. +1 −1 test/middleware_test.rb
  4. +50 −50 test/options_test.rb
View
3 lib/sinatra/base.rb
@@ -1083,9 +1083,6 @@ def self.register(*extensions, &block) #:nodoc:
end
end
- # Deprecated.
- Default = Application
-
# Sinatra delegation mixin. Mixing this module into an object causes all
# methods to be delegated to the Sinatra::Application class. Used primarily
# at the top-level.
View
16 test/extensions_test.rb
@@ -35,9 +35,9 @@ def fizz!(name); end
Sinatra::Base.register FooExtensions
assert Sinatra::Base.respond_to?(:foo)
- Sinatra::Default.register BarExtensions
- assert Sinatra::Default.respond_to?(:bar)
- assert Sinatra::Default.respond_to?(:foo)
+ Sinatra::Application.register BarExtensions
+ assert Sinatra::Application.respond_to?(:bar)
+ assert Sinatra::Application.respond_to?(:foo)
assert !Sinatra::Base.respond_to?(:bar)
end
@@ -48,16 +48,16 @@ def im_in_ur_anonymous_module; end
assert Sinatra::Base.respond_to?(:im_in_ur_anonymous_module)
end
- it 'will make sure any public methods added via Default#register are delegated to Sinatra::Delegator' do
- Sinatra::Default.register FooExtensions
+ it 'will make sure any public methods added via Application#register are delegated to Sinatra::Delegator' do
+ Sinatra::Application.register FooExtensions
assert Sinatra::Delegator.private_instance_methods.
map { |m| m.to_sym }.include?(:foo)
assert !Sinatra::Delegator.private_instance_methods.
map { |m| m.to_sym }.include?(:im_hiding_in_ur_foos)
end
it 'will handle special method names' do
- Sinatra::Default.register PainExtensions
+ Sinatra::Application.register PainExtensions
assert Sinatra::Delegator.private_instance_methods.
map { |m| m.to_sym }.include?(:foo=)
assert Sinatra::Delegator.private_instance_methods.
@@ -71,10 +71,10 @@ def im_in_ur_anonymous_module; end
assert !Sinatra::Delegator.private_instance_methods.include?("quux")
end
- it 'will extend the Sinatra::Default application by default' do
+ it 'will extend the Sinatra::Application application by default' do
Sinatra.register BazExtensions
assert !Sinatra::Base.respond_to?(:baz)
- assert Sinatra::Default.respond_to?(:baz)
+ assert Sinatra::Application.respond_to?(:baz)
end
module BizzleExtension
View
2 test/middleware_test.rb
@@ -2,7 +2,7 @@
class MiddlewareTest < Test::Unit::TestCase
setup do
- @app = mock_app(Sinatra::Default) {
+ @app = mock_app(Sinatra::Application) {
get '/*' do
response.headers['X-Tests'] = env['test.ran'].
map { |n| n.split('::').last }.
View
100 test/options_test.rb
@@ -2,10 +2,10 @@
class OptionsTest < Test::Unit::TestCase
setup do
- @base = Sinatra.new(Sinatra::Base)
- @default = Sinatra.new(Sinatra::Default)
- @base.set :environment, :development
- @default.set :environment, :development
+ @base = Sinatra.new(Sinatra::Base)
+ @application = Sinatra.new(Sinatra::Application)
+ @base.set :environment, :development
+ @application.set :environment, :development
end
it 'sets options to literal values' do
@@ -114,8 +114,8 @@ def clean_backtrace(trace)
assert @base.clean_trace?
end
- it 'is enabled on Default' do
- assert @default.clean_trace?
+ it 'is enabled on Application' do
+ assert @application.clean_trace?
end
it 'does nothing when disabled' do
@@ -156,13 +156,13 @@ def clean_backtrace(trace)
assert ! @base.run?
end
- it 'is enabled on Default when not in test environment' do
- @default.set :environment, :development
- assert @default.development?
- assert @default.run?
+ it 'is enabled on Application when not in test environment' do
+ @application.set :environment, :development
+ assert @application.development?
+ assert @application.run?
- @default.set :environment, :development
- assert @default.run?
+ @application.set :environment, :development
+ assert @application.run?
end
# TODO: it 'is enabled when $0 == app_file'
@@ -173,16 +173,16 @@ def clean_backtrace(trace)
assert @base.raise_errors?
end
- it 'is enabled on Default only in test' do
- @default.set(:environment, :development)
- assert @default.development?
- assert ! @default.raise_errors?
+ it 'is enabled on Application only in test' do
+ @application.set(:environment, :development)
+ assert @application.development?
+ assert ! @application.raise_errors?
- @default.set(:environment, :production)
- assert ! @default.raise_errors?
+ @application.set(:environment, :production)
+ assert ! @application.raise_errors?
- @default.set(:environment, :test)
- assert @default.raise_errors?
+ @application.set(:environment, :test)
+ assert @application.raise_errors?
end
end
@@ -194,20 +194,20 @@ def clean_backtrace(trace)
end
end
- it 'is enabled on Default only in development' do
+ it 'is enabled on Application only in development' do
@base.set(:environment, :development)
- assert @default.development?
- assert @default.show_exceptions?
+ assert @application.development?
+ assert @application.show_exceptions?
- @default.set(:environment, :test)
- assert ! @default.show_exceptions?
+ @application.set(:environment, :test)
+ assert ! @application.show_exceptions?
@base.set(:environment, :production)
assert ! @base.show_exceptions?
end
it 'returns a friendly 500' do
- klass = Sinatra.new(Sinatra::Default)
+ klass = Sinatra.new(Sinatra::Application)
mock_app(klass) {
enable :show_exceptions
@@ -228,12 +228,12 @@ def clean_backtrace(trace)
assert ! @base.dump_errors?
end
- it 'is enabled on Default' do
- assert @default.dump_errors?
+ it 'is enabled on Application' do
+ assert @application.dump_errors?
end
it 'dumps exception with backtrace to rack.errors' do
- klass = Sinatra.new(Sinatra::Default)
+ klass = Sinatra.new(Sinatra::Application)
mock_app(klass) {
disable :raise_errors
@@ -260,8 +260,8 @@ def clean_backtrace(trace)
assert ! @base.sessions?
end
- it 'is disabled on Default' do
- assert ! @default.sessions?
+ it 'is disabled on Application' do
+ assert ! @application.sessions?
end
# TODO: it 'uses Rack::Session::Cookie when enabled' do
@@ -272,11 +272,11 @@ def clean_backtrace(trace)
assert ! @base.logging?
end
- it 'is enabled on Default when not in test environment' do
- assert @default.logging?
+ it 'is enabled on Application when not in test environment' do
+ assert @application.logging?
- @default.set :environment, :test
- assert ! @default.logging
+ @application.set :environment, :test
+ assert ! @application.logging
end
# TODO: it 'uses Rack::CommonLogger when enabled' do
@@ -287,8 +287,8 @@ def clean_backtrace(trace)
assert ! @base.static?
end
- it 'is enabled on Default' do
- assert @default.static?
+ it 'is enabled on Application' do
+ assert @application.static?
end
# TODO: it setup static routes if public is enabled
@@ -298,73 +298,73 @@ def clean_backtrace(trace)
describe 'host' do
it 'defaults to 0.0.0.0' do
assert_equal '0.0.0.0', @base.host
- assert_equal '0.0.0.0', @default.host
+ assert_equal '0.0.0.0', @application.host
end
end
describe 'port' do
it 'defaults to 4567' do
assert_equal 4567, @base.port
- assert_equal 4567, @default.port
+ assert_equal 4567, @application.port
end
end
describe 'server' do
it 'is one of thin, mongrel, webrick' do
assert_equal %w[thin mongrel webrick], @base.server
- assert_equal %w[thin mongrel webrick], @default.server
+ assert_equal %w[thin mongrel webrick], @application.server
end
end
describe 'app_file' do
it 'is nil' do
assert @base.app_file.nil?
- assert @default.app_file.nil?
+ assert @application.app_file.nil?
end
end
describe 'root' do
it 'is nil if app_file is not set' do
assert @base.root.nil?
- assert @default.root.nil?
+ assert @application.root.nil?
end
it 'is equal to the expanded basename of app_file' do
@base.app_file = __FILE__
assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
- @default.app_file = __FILE__
- assert_equal File.expand_path(File.dirname(__FILE__)), @default.root
+ @application.app_file = __FILE__
+ assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
end
end
describe 'views' do
it 'is nil if root is not set' do
assert @base.views.nil?
- assert @default.views.nil?
+ assert @application.views.nil?
end
it 'is set to root joined with views/' do
@base.root = File.dirname(__FILE__)
assert_equal File.dirname(__FILE__) + "/views", @base.views
- @default.root = File.dirname(__FILE__)
- assert_equal File.dirname(__FILE__) + "/views", @default.views
+ @application.root = File.dirname(__FILE__)
+ assert_equal File.dirname(__FILE__) + "/views", @application.views
end
end
describe 'public' do
it 'is nil if root is not set' do
assert @base.public.nil?
- assert @default.public.nil?
+ assert @application.public.nil?
end
it 'is set to root joined with public/' do
@base.root = File.dirname(__FILE__)
assert_equal File.dirname(__FILE__) + "/public", @base.public
- @default.root = File.dirname(__FILE__)
- assert_equal File.dirname(__FILE__) + "/public", @default.public
+ @application.root = File.dirname(__FILE__)
+ assert_equal File.dirname(__FILE__) + "/public", @application.public
end
end

0 comments on commit af1ee6a

Please sign in to comment.