Permalink
Browse files

only extend main object for top level dsl

  • Loading branch information...
1 parent 57b73e3 commit 46bdb7dcf842afdb3bce57a6753eb4d909b1225d @rkh rkh committed Nov 5, 2011
Showing with 24 additions and 4 deletions.
  1. +3 −1 lib/sinatra/main.rb
  2. +15 −1 test/integration/app.rb
  3. +6 −2 test/integration_test.rb
View
@@ -25,4 +25,6 @@ class Application < Base
at_exit { Application.run! if $!.nil? && Application.run? }
end
-include Sinatra::Delegator
+# include would include the module in Object
+# extend only extends the `main` object
+extend Sinatra::Delegator
@@ -1,6 +1,20 @@
require 'sinatra'
+configure do
+ set :foo, :bar
+end
+
get '/app_file' do
content_type :txt
settings.app_file
-end
+end
+
+get '/mainonly' do
+ object = Object.new
+ begin
+ object.send(:get, '/foo') { }
+ 'false'
+ rescue NameError
+ 'true'
+ end
+end
@@ -44,9 +44,13 @@ def with_server
Process.kill("TERM", pipe.pid) if pipe
end
- it 'starts a top level application' do
+ def assert_content(url, content)
with_server do
- assert_equal open("http://127.0.0.1:#{port}/app_file").read, app_file
+ response = open("http://127.0.0.1:#{port}#{url}")
+ assert_equal response.read, content
end
end
+
+ it('sets the app_file') { assert_content "/app_file", app_file }
+ it('only extends main') { assert_content "/mainonly", "true" }
end

0 comments on commit 46bdb7d

Please sign in to comment.