sinatra-sinatra 0.9.1.3 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,10 +1,83 @@
1
1
  = 0.9.2 / unreleased
2
2
 
3
+ * This version is compatible with Rack 1.0. [Rein Henrichs]
4
+
5
+ * The development-mode unhandled exception / error page has been
6
+ greatly enhanced, functionally and aesthetically. The error
7
+ page is used when the :show_exceptions option is enabled and an
8
+ exception propagates outside of a route handler or before filter.
9
+ [Simon Rozet / Matte Noble / Ryan Tomayko]
10
+
11
+ * Backtraces that move through templates now include filenames and
12
+ line numbers where possible. [#51 / S. Brent Faulkner]
13
+
14
+ * All templates now have an app-level option for setting default
15
+ template options (:haml, :sass, :erb, :builder). The app-level
16
+ option value must be a Hash if set and is merged with the
17
+ template options specified to the render method (Base#haml,
18
+ Base#erb, Base#builder). [S. Brent Faulkner, Ryan Tomayko]
19
+
20
+ * The method signature for all template rendering methods has
21
+ been unified: "def engine(template, options={}, locals={})".
22
+ The options Hash now takes the generic :views, :layout, and
23
+ :locals options but also any template-specific options. The
24
+ generic options are removed before calling the template specific
25
+ render method. Locals may be specified using either the
26
+ :locals key in the options hash or a second Hash option to the
27
+ rendering method. [#191 / Ryan Tomayko]
28
+
29
+ * The receiver is now passed to "configure" blocks. This
30
+ allows for the following idiom in top-level apps:
31
+ configure { |app| set :foo, app.root + '/foo' }
32
+ [TJ Holowaychuck / Ryan Tomayko]
33
+
34
+ * The "sinatra/test" lib is deprecated and will be removed in
35
+ Sinatra 1.0. This includes the Sinatra::Test module and
36
+ Sinatra::TestHarness class in addition to all the framework
37
+ test helpers that were deprecated in 0.9.1. The Rack::Test
38
+ lib should be used instead: http://gitrdoc.com/brynary/rack-test
39
+ [#176 / Simon Rozet]
40
+
3
41
  * Development mode source file reloading has been removed. The
4
42
  "shotgun" (http://rtomayko.github.com/shotgun/) program can be
5
43
  used to achieve the same basic functionality in most situations.
6
44
  Passenger users should use the "tmp/always_restart.txt"
7
- file (http://tinyurl.com/c67o4h). [#166]
45
+ file (http://tinyurl.com/c67o4h). [#166 / Ryan Tomayko]
46
+
47
+ * Auto-requiring template libs in the erb, builder, haml, and
48
+ sass methods is deprecated due to thread-safety issues. You must
49
+ require the template libs explicitly in your app file. [Simon Rozet]
50
+
51
+ * A new Sinatra::Base#route_missing method was added. route_missing
52
+ is sent when no route matches the request or all route handlers
53
+ pass. The default implementation forwards the request to the
54
+ downstream app when running as middleware (i.e., "@app" is
55
+ non-nil), or raises a NotFound exception when no downstream app
56
+ is defined. Subclasses can override this method to perform custom
57
+ route miss logic. [Jon Crosby]
58
+
59
+ * A new Sinatra::Base#route_eval method was added. The method
60
+ yields to the block and throws :halt with the result. Subclasses
61
+ can override this method to tap into the route execution logic.
62
+ [TJ Holowaychuck]
63
+
64
+ * Fix the "-x" (enable request mutex / locking) command line
65
+ argument. Passing -x now properly sets the :lock option.
66
+ [S. Brent Faulkner, Ryan Tomayko]
67
+
68
+ * Fix writer ("foo=") and predicate ("foo?") methods in extension
69
+ modules not being added to the registering class.
70
+ [#172 / Pat Nakajima]
71
+
72
+ * Fix in-file templates when running alongside activesupport and
73
+ fatal errors when requiring activesupport before sinatra
74
+ [#178 / Brian Candler]
75
+
76
+ * Fix various issues running on Google AppEngine.
77
+ [Samuel Goebert, Simon Rozet]
78
+
79
+ * Fix in-file templates __END__ detection when __END__ exists with
80
+ other stuff on a line [Yoji Shidara]
8
81
 
9
82
  = 0.9.1.1 / 2009-03-09
10
83
 
data/README.rdoc CHANGED
@@ -437,34 +437,38 @@ typically don't have to +use+ them explicitly.
437
437
 
438
438
  == Testing
439
439
 
440
- The Sinatra::Test mixin and Sinatra::TestHarness class include a variety of
441
- helper methods for testing your Sinatra app:
440
+ Sinatra tests can be written using any Rack-based testing library
441
+ or framework. {Rack::Test}[http://gitrdoc.com/brynary/rack-test] is
442
+ recommended:
442
443
 
443
444
  require 'my_sinatra_app'
444
- require 'test/unit'
445
- require 'sinatra/test'
445
+ require 'rack/test'
446
446
 
447
447
  class MyAppTest < Test::Unit::TestCase
448
- include Sinatra::Test
448
+ include Rack::Test::Methods
449
+
450
+ def app
451
+ Sinatra::Application
452
+ end
449
453
 
450
454
  def test_my_default
451
455
  get '/'
452
- assert_equal 'Hello World!', @response.body
456
+ assert_equal 'Hello World!', last_response.body
453
457
  end
454
458
 
455
459
  def test_with_params
456
- get '/meet', {:name => 'Frank'}
457
- assert_equal 'Hello Frank!', @response.body
460
+ get '/meet', :name => 'Frank'
461
+ assert_equal 'Hello Frank!', last_response.body
458
462
  end
459
463
 
460
464
  def test_with_rack_env
461
- get '/', {}, :agent => 'Songbird'
462
- assert_equal "You're using Songbird!", @response.body
465
+ get '/', {}, 'HTTP_USER_AGENT' => 'Songbird'
466
+ assert_equal "You're using Songbird!", last_response.body
463
467
  end
464
468
  end
465
469
 
466
- See http://www.sinatrarb.com/testing.html for more on Sinatra::Test and using it
467
- with other test frameworks such as RSpec, Bacon, and test/spec.
470
+ NOTE: The built-in Sinatra::Test module and Sinatra::TestHarness class
471
+ are deprecated as of the 0.9.2 release.
468
472
 
469
473
  == Command line
470
474
 
@@ -490,7 +494,7 @@ clone and run your app with the <tt>sinatra/lib</tt> directory on the
490
494
  git clone git://github.com/sinatra/sinatra.git
491
495
  ruby -Isinatra/lib myapp.rb
492
496
 
493
- Alternatively, you can add the <tt>sinatra/lib<tt> directory to the
497
+ Alternatively, you can add the <tt>sinatra/lib</tt> directory to the
494
498
  <tt>LOAD_PATH</tt> in your application:
495
499
 
496
500
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/sinatra/lib'
data/Rakefile CHANGED
@@ -7,6 +7,8 @@ task :spec => :test
7
7
 
8
8
  # SPECS ===============================================================
9
9
 
10
+ task(:test) { puts "==> Running main test suite" }
11
+
10
12
  Rake::TestTask.new(:test) do |t|
11
13
  t.test_files = FileList['test/*_test.rb']
12
14
  t.ruby_opts = ['-rubygems'] if defined? Gem
@@ -16,18 +18,17 @@ desc "Run < 0.9.x compatibility specs"
16
18
  task :compat do
17
19
  begin
18
20
  require 'mocha'
19
- rescue LoadError
20
- puts 'WARN: skipping compat tests. mocha gem required.'
21
- next
22
- end
21
+ require 'test/spec'
22
+ at_exit { exit 0 } # disable test-spec at_exit runner
23
23
 
24
- if ! system('specrb --help &>/dev/null')
25
- puts 'WARN: skipping compat tests. test-spec gem required.'
26
- next
24
+ puts "==> Running compat test suite"
25
+ Rake::TestTask.new(:compat) do |t|
26
+ t.test_files = FileList['compat/*_test.rb']
27
+ t.ruby_opts = ['-rubygems'] if defined? Gem
28
+ end
29
+ rescue LoadError
30
+ warn 'Skipping compat tests. mocha and/or test-spec gems not installed.'
27
31
  end
28
-
29
- pattern = ENV['TEST'] || '.*'
30
- sh "specrb --testcase '#{pattern}' -Ilib:test compat/*_test.rb"
31
32
  end
32
33
 
33
34
  # PACKAGING ============================================================
data/compat/helper.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'mocha'
3
3
 
4
- require 'haml'
5
- require 'sass'
6
- require 'builder'
7
-
8
4
  # disable warnings in compat specs.
9
5
  $VERBOSE = nil
10
6
 
@@ -28,6 +24,9 @@ end
28
24
 
29
25
  class Test::Unit::TestCase
30
26
  include Sinatra::Test
27
+
28
+ PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS)
29
+
31
30
  def setup
32
31
  @app = lambda { |env| Sinatra::Application.call(env) }
33
32
  end
data/lib/sinatra/base.rb CHANGED
@@ -6,7 +6,7 @@ require 'rack/builder'
6
6
  require 'sinatra/showexceptions'
7
7
 
8
8
  module Sinatra
9
- VERSION = '0.9.1.3'
9
+ VERSION = '0.9.2'
10
10
 
11
11
  # The request object. See Rack::Request for more info:
12
12
  # http://rack.rubyforge.org/doc/classes/Rack/Request.html
@@ -223,19 +223,27 @@ module Sinatra
223
223
  # in the template
224
224
  module Templates
225
225
  def erb(template, options={}, locals={})
226
+ require_warn('ERB') unless defined?(::ERB)
227
+
226
228
  render :erb, template, options, locals
227
229
  end
228
230
 
229
231
  def haml(template, options={}, locals={})
232
+ require_warn('Haml') unless defined?(::Haml::Engine)
233
+
230
234
  render :haml, template, options, locals
231
235
  end
232
236
 
233
237
  def sass(template, options={}, locals={})
238
+ require_warn('Sass') unless defined?(::Sass::Engine)
239
+
234
240
  options[:layout] = false
235
241
  render :sass, template, options, locals
236
242
  end
237
243
 
238
244
  def builder(template=nil, options={}, locals={}, &block)
245
+ require_warn('Builder') unless defined?(::Builder)
246
+
239
247
  options, template = template, nil if template.is_a?(Hash)
240
248
  template = lambda { block } if template.nil?
241
249
  render :builder, template, options, locals
@@ -294,7 +302,7 @@ module Sinatra
294
302
  end
295
303
 
296
304
  def render_erb(template, data, options, locals, &block)
297
- original_out_buf = @_out_buf
305
+ original_out_buf = defined?(@_out_buf) && @_out_buf
298
306
  data = data.call if data.kind_of? Proc
299
307
 
300
308
  instance = ::ERB.new(data, nil, nil, '@_out_buf')
@@ -331,6 +339,11 @@ module Sinatra
331
339
  end
332
340
  xml.target!
333
341
  end
342
+
343
+ def require_warn(engine)
344
+ warn "Auto-require of #{engine} is deprecated; add require '#{engine}' to your app."
345
+ require engine.downcase
346
+ end
334
347
  end
335
348
 
336
349
  # Base class for all Sinatra applications and middleware.
@@ -716,8 +729,9 @@ module Sinatra
716
729
  end
717
730
  }
718
731
  end
732
+ alias_method :agent, :user_agent
719
733
 
720
- def accept_mime_types(types)
734
+ def provides(*types)
721
735
  types = [types] unless types.kind_of? Array
722
736
  types.map!{|t| media_type(t)}
723
737
 
@@ -749,10 +763,11 @@ module Sinatra
749
763
  def head(path, opts={}, &bk); route 'HEAD', path, opts, &bk end
750
764
 
751
765
  private
752
- def route(verb, path, opts={}, &block)
753
- host_name opts[:host] if opts.key?(:host)
754
- user_agent opts[:agent] if opts.key?(:agent)
755
- accept_mime_types opts[:provides] if opts.key?(:provides)
766
+ def route(verb, path, options={}, &block)
767
+ # Because of self.options.host
768
+ host_name(options.delete(:host)) if options.key?(:host)
769
+
770
+ options.each {|option, args| send(option, *args)}
756
771
 
757
772
  pattern, keys = compile(path)
758
773
  conditions, @conditions = @conditions, []
@@ -781,7 +796,7 @@ module Sinatra
781
796
  if path.respond_to? :to_str
782
797
  special_chars = %w{. + ( )}
783
798
  pattern =
784
- path.gsub(/((:\w+)|[\*#{special_chars.join}])/) do |match|
799
+ path.to_str.gsub(/((:\w+)|[\*#{special_chars.join}])/) do |match|
785
800
  case match
786
801
  when "*"
787
802
  keys << 'splat'
@@ -794,6 +809,8 @@ module Sinatra
794
809
  end
795
810
  end
796
811
  [/^#{pattern}$/, keys]
812
+ elsif path.respond_to?(:keys) && path.respond_to?(:match)
813
+ [path, path.keys]
797
814
  elsif path.respond_to? :match
798
815
  [path, keys]
799
816
  else
@@ -806,7 +823,7 @@ module Sinatra
806
823
  # in `extensions` available to the handlers and templates
807
824
  def helpers(*extensions, &block)
808
825
  class_eval(&block) if block_given?
809
- include *extensions if extensions.any?
826
+ include(*extensions) if extensions.any?
810
827
  end
811
828
 
812
829
  def extensions
@@ -940,6 +957,9 @@ module Sinatra
940
957
  /active_support/, # active_support require hacks
941
958
  ] unless self.const_defined?('CALLERS_TO_IGNORE')
942
959
 
960
+ # add rubinius (and hopefully other VM impls) ignore patterns ...
961
+ CALLERS_TO_IGNORE.concat(RUBY_IGNORE_CALLERS) if defined?(RUBY_IGNORE_CALLERS)
962
+
943
963
  # Like Kernel#caller but excluding certain magic entries and without
944
964
  # line / method information; the resulting array contains filenames only.
945
965
  def caller_files
@@ -1037,7 +1057,7 @@ module Sinatra
1037
1057
 
1038
1058
  def self.register(*extensions, &block) #:nodoc:
1039
1059
  added_methods = extensions.map {|m| m.public_instance_methods }.flatten
1040
- Delegator.delegate *added_methods
1060
+ Delegator.delegate(*added_methods)
1041
1061
  super(*extensions, &block)
1042
1062
  end
1043
1063
  end
data/lib/sinatra/test.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'sinatra/base'
2
2
 
3
+ warn 'Sinatra::Test is deprecated; use Rack::Test instead.'
4
+
3
5
  module Sinatra
4
6
  module Test
5
7
  include Rack::Utils
data/sinatra.gemspec CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'sinatra'
6
- s.version = '0.9.1.3'
7
- s.date = '2009-04-25'
6
+ s.version = '0.9.2'
7
+ s.date = '2009-05-18'
8
8
 
9
9
  s.description = "Classy web-development dressed in a DSL"
10
10
  s.summary = "Classy web-development dressed in a DSL"
@@ -113,6 +113,7 @@ Gem::Specification.new do |s|
113
113
  s.extra_rdoc_files = %w[README.rdoc LICENSE]
114
114
  s.add_dependency 'rack', '>= 0.9.1'
115
115
  s.add_development_dependency 'shotgun', '>= 0.2', '< 1.0'
116
+ s.add_development_dependency 'rack-test', '>= 0.3.0'
116
117
 
117
118
  s.has_rdoc = true
118
119
  s.homepage = "http://sinatra.rubyforge.org"
data/test/base_test.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class BaseTest < Test::Unit::TestCase
4
+ def test_default
5
+ assert true
6
+ end
7
+
4
8
  describe 'Sinatra::Base subclasses' do
5
9
  class TestApp < Sinatra::Base
6
10
  get '/' do
@@ -23,6 +27,7 @@ class BaseTest < Test::Unit::TestCase
23
27
 
24
28
  class TestApp < Sinatra::Base
25
29
  get '/state' do
30
+ @foo ||= "new"
26
31
  body = "Foo: #{@foo}"
27
32
  @foo = 'discard'
28
33
  body
@@ -34,7 +39,7 @@ class BaseTest < Test::Unit::TestCase
34
39
  2.times do
35
40
  response = request.get('/state')
36
41
  assert response.ok?
37
- assert_equal 'Foo: ', response.body
42
+ assert_equal 'Foo: new', response.body
38
43
  end
39
44
  end
40
45
 
data/test/builder_test.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
+ require 'builder'
2
3
 
3
4
  class BuilderTest < Test::Unit::TestCase
4
5
  def builder_app(&block)
data/test/contest.rb CHANGED
@@ -6,8 +6,10 @@ require "test/unit"
6
6
  # allow them. Having a failure when no tests have been defined seems
7
7
  # counter-intuitive.
8
8
  class Test::Unit::TestSuite
9
- def empty?
10
- false
9
+ unless method_defined?(:empty?)
10
+ def empty?
11
+ false
12
+ end
11
13
  end
12
14
  end
13
15
 
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
1
3
  begin
2
4
  require 'rack'
3
5
  rescue LoadError
@@ -12,11 +14,8 @@ libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
12
14
  $LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
13
15
 
14
16
  require 'contest'
15
- require 'sinatra/test'
16
-
17
- require 'haml'
18
- require 'sass'
19
- require 'builder'
17
+ require 'rack/test'
18
+ require 'sinatra/base'
20
19
 
21
20
  class Sinatra::Base
22
21
  # Allow assertions in request context
@@ -26,24 +25,52 @@ end
26
25
  Sinatra::Base.set :environment, :test
27
26
 
28
27
  class Test::Unit::TestCase
29
- include Sinatra::Test
28
+ include Rack::Test::Methods
30
29
 
31
30
  class << self
32
31
  alias_method :it, :test
33
32
  end
34
33
 
34
+ alias_method :response, :last_response
35
+
36
+ setup do
37
+ Sinatra::Base.set :environment, :test
38
+ end
39
+
35
40
  # Sets up a Sinatra::Base subclass defined with the block
36
41
  # given. Used in setup or individual spec methods to establish
37
42
  # the application.
38
43
  def mock_app(base=Sinatra::Base, &block)
39
44
  @app = Sinatra.new(base, &block)
40
45
  end
41
- end
42
46
 
43
- # Do not output warnings for the duration of the block.
44
- def silence_warnings
45
- $VERBOSE, v = nil, $VERBOSE
46
- yield
47
- ensure
48
- $VERBOSE = v
47
+ def app
48
+ Rack::Lint.new(@app)
49
+ end
50
+
51
+ def body
52
+ response.body.to_s
53
+ end
54
+
55
+ # Delegate other missing methods to response.
56
+ def method_missing(name, *args, &block)
57
+ if response && response.respond_to?(name)
58
+ response.send(name, *args, &block)
59
+ else
60
+ super
61
+ end
62
+ end
63
+
64
+ # Also check response since we delegate there.
65
+ def respond_to?(symbol, include_private=false)
66
+ super || (response && response.respond_to?(symbol, include_private))
67
+ end
68
+
69
+ # Do not output warnings for the duration of the block.
70
+ def silence_warnings
71
+ $VERBOSE, v = nil, $VERBOSE
72
+ yield
73
+ ensure
74
+ $VERBOSE = v
75
+ end
49
76
  end
data/test/helpers_test.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class HelpersTest < Test::Unit::TestCase
4
+ def test_default
5
+ assert true
6
+ end
7
+
4
8
  describe 'status' do
5
9
  setup do
6
10
  mock_app {
@@ -178,7 +182,7 @@ class HelpersTest < Test::Unit::TestCase
178
182
  end
179
183
  }
180
184
 
181
- get '/', :env => { 'rack.session' => { :foo => 'bar' } }
185
+ get '/', {}, { 'rack.session' => { :foo => 'bar' } }
182
186
  assert_equal 'bar', body
183
187
  end
184
188
 
@@ -373,7 +377,7 @@ class HelpersTest < Test::Unit::TestCase
373
377
  end
374
378
 
375
379
  it 'halts when a conditional GET matches' do
376
- get '/', :env => { 'HTTP_IF_MODIFIED_SINCE' => @now.httpdate }
380
+ get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @now.httpdate }
377
381
  assert_equal 304, status
378
382
  assert_equal '', body
379
383
  end
@@ -402,13 +406,13 @@ class HelpersTest < Test::Unit::TestCase
402
406
  end
403
407
 
404
408
  it 'halts when a conditional GET matches' do
405
- get '/', :env => { 'HTTP_IF_NONE_MATCH' => '"FOO"' }
409
+ get '/', {}, { 'HTTP_IF_NONE_MATCH' => '"FOO"' }
406
410
  assert_equal 304, status
407
411
  assert_equal '', body
408
412
  end
409
413
 
410
414
  it 'should handle multiple ETag values in If-None-Match header' do
411
- get '/', :env => { 'HTTP_IF_NONE_MATCH' => '"BAR", *' }
415
+ get '/', {}, { 'HTTP_IF_NONE_MATCH' => '"BAR", *' }
412
416
  assert_equal 304, status
413
417
  assert_equal '', body
414
418
  end
@@ -7,6 +7,10 @@ class FooNotFound < Sinatra::NotFound
7
7
  end
8
8
 
9
9
  class MappedErrorTest < Test::Unit::TestCase
10
+ def test_default
11
+ assert true
12
+ end
13
+
10
14
  describe 'Exception Mappings' do
11
15
  it 'invokes handlers registered with ::error when raised' do
12
16
  mock_app {
@@ -51,18 +55,6 @@ class MappedErrorTest < Test::Unit::TestCase
51
55
  assert_equal 'looks good', body
52
56
  end
53
57
 
54
- it 'dumps errors to rack.errors when dump_errors is enabled' do
55
- mock_app {
56
- set :raise_errors, false
57
- set :dump_errors, true
58
- get('/') { raise FooError, 'BOOM!' }
59
- }
60
-
61
- get '/'
62
- assert_equal 500, status
63
- assert @response.errors =~ /FooError - BOOM!:/
64
- end
65
-
66
58
  it "raises without calling the handler when the raise_errors options is set" do
67
59
  mock_app {
68
60
  set :raise_errors, true
data/test/routing_test.rb CHANGED
@@ -5,6 +5,22 @@ def route_def(pattern)
5
5
  mock_app { get(pattern) { } }
6
6
  end
7
7
 
8
+ class RegexpLookAlike
9
+ class MatchData
10
+ def captures
11
+ ["this", "is", "a", "test"]
12
+ end
13
+ end
14
+
15
+ def match(string)
16
+ ::RegexpLookAlike::MatchData.new if string == "/this/is/a/test/"
17
+ end
18
+
19
+ def keys
20
+ ["one", "two", "three", "four"]
21
+ end
22
+ end
23
+
8
24
  class RoutingTest < Test::Unit::TestCase
9
25
  %w[get put post delete].each do |verb|
10
26
  it "defines #{verb.upcase} request handlers with #{verb}" do
@@ -44,15 +60,19 @@ class RoutingTest < Test::Unit::TestCase
44
60
  assert_equal 404, status
45
61
  end
46
62
 
47
- it "sets the content-type to text/html in the default 404 handler" do
63
+ it "overrides the content-type in error handlers" do
48
64
  mock_app {
49
65
  before { content_type 'text/plain' }
66
+ error Sinatra::NotFound do
67
+ content_type "text/html"
68
+ "<h1>Not Found</h1>"
69
+ end
50
70
  }
51
71
 
52
72
  get '/foo'
53
73
  assert_equal 404, status
54
74
  assert_equal 'text/html', response["Content-Type"]
55
- assert body.include?("Sinatra doesn't know this ditty")
75
+ assert_equal "<h1>Not Found</h1>", response.body
56
76
  end
57
77
 
58
78
  it 'takes multiple definitions of a route' do
@@ -254,17 +274,7 @@ class RoutingTest < Test::Unit::TestCase
254
274
  end
255
275
 
256
276
  it "supports deeply nested params" do
257
- input = {
258
- 'browser[chrome][engine][name]' => 'V8',
259
- 'browser[chrome][engine][version]' => '1.0',
260
- 'browser[firefox][engine][name]' => 'spidermonkey',
261
- 'browser[firefox][engine][version]' => '1.7.0',
262
- 'emacs[map][goto-line]' => 'M-g g',
263
- 'emacs[version]' => '22.3.1',
264
- 'paste[name]' => 'hello world',
265
- 'paste[syntax]' => 'ruby'
266
- }
267
- expected = {
277
+ expected_params = {
268
278
  "emacs" => {
269
279
  "map" => { "goto-line" => "M-g g" },
270
280
  "version" => "22.3.1"
@@ -277,11 +287,11 @@ class RoutingTest < Test::Unit::TestCase
277
287
  }
278
288
  mock_app {
279
289
  get '/foo' do
280
- assert_equal expected, params
290
+ assert_equal expected_params, params
281
291
  'looks good'
282
292
  end
283
293
  }
284
- get "/foo?#{build_query(input)}"
294
+ get '/foo', expected_params
285
295
  assert ok?
286
296
  assert_equal 'looks good', body
287
297
  end
@@ -363,9 +373,26 @@ class RoutingTest < Test::Unit::TestCase
363
373
  assert_equal 'right on', body
364
374
  end
365
375
 
376
+ it 'supports regular expression look-alike routes' do
377
+ mock_app {
378
+ get(RegexpLookAlike.new) do
379
+ assert_equal 'this', params[:one]
380
+ assert_equal 'is', params[:two]
381
+ assert_equal 'a', params[:three]
382
+ assert_equal 'test', params[:four]
383
+ 'right on'
384
+ end
385
+ }
386
+
387
+ get '/this/is/a/test/'
388
+ assert ok?
389
+ assert_equal 'right on', body
390
+ end
391
+
366
392
  it 'raises a TypeError when pattern is not a String or Regexp' do
367
- @app = mock_app
368
- assert_raise(TypeError) { @app.get(42){} }
393
+ assert_raise(TypeError) {
394
+ mock_app { get(42){} }
395
+ }
369
396
  end
370
397
 
371
398
  it "returns response immediately on halt" do
@@ -490,7 +517,7 @@ class RoutingTest < Test::Unit::TestCase
490
517
  get '/foo'
491
518
  assert not_found?
492
519
 
493
- get '/foo', :env => { 'HTTP_HOST' => 'example.com' }
520
+ get '/foo', {}, { 'HTTP_HOST' => 'example.com' }
494
521
  assert_equal 200, status
495
522
  assert_equal 'Hello World', body
496
523
  end
@@ -505,7 +532,7 @@ class RoutingTest < Test::Unit::TestCase
505
532
  get '/foo'
506
533
  assert not_found?
507
534
 
508
- get '/foo', :env => { 'HTTP_USER_AGENT' => 'Foo Bar' }
535
+ get '/foo', {}, { 'HTTP_USER_AGENT' => 'Foo Bar' }
509
536
  assert_equal 200, status
510
537
  assert_equal 'Hello World', body
511
538
  end
@@ -517,7 +544,7 @@ class RoutingTest < Test::Unit::TestCase
517
544
  'Hello ' + params[:agent].first
518
545
  end
519
546
  }
520
- get '/foo', :env => { 'HTTP_USER_AGENT' => 'Foo Bar' }
547
+ get '/foo', {}, { 'HTTP_USER_AGENT' => 'Foo Bar' }
521
548
  assert_equal 200, status
522
549
  assert_equal 'Hello Bar', body
523
550
  end
@@ -529,12 +556,12 @@ class RoutingTest < Test::Unit::TestCase
529
556
  end
530
557
  }
531
558
 
532
- get '/', :env => { :accept => 'application/xml' }
559
+ get '/', {}, { 'HTTP_ACCEPT' => 'application/xml' }
533
560
  assert ok?
534
561
  assert_equal 'application/xml', body
535
562
  assert_equal 'application/xml', response.headers['Content-Type']
536
563
 
537
- get '/', :env => { :accept => 'text/html' }
564
+ get '/', {}, { :accept => 'text/html' }
538
565
  assert !ok?
539
566
  end
540
567
 
@@ -548,7 +575,7 @@ class RoutingTest < Test::Unit::TestCase
548
575
  }
549
576
 
550
577
  types.each do |type|
551
- get '/', :env => { :accept => type }
578
+ get '/', {}, { 'HTTP_ACCEPT' => type }
552
579
  assert ok?
553
580
  assert_equal type, body
554
581
  assert_equal type, response.headers['Content-Type']
@@ -666,6 +693,40 @@ class RoutingTest < Test::Unit::TestCase
666
693
  assert_equal 'ab', body
667
694
  end
668
695
 
696
+ it 'allows custom route-conditions to be set via route options' do
697
+ protector = Module.new {
698
+ def protect(*args)
699
+ condition {
700
+ unless authorize(params["user"], params["password"])
701
+ halt 403, "go away"
702
+ end
703
+ }
704
+ end
705
+ }
706
+
707
+ mock_app {
708
+ register protector
709
+
710
+ helpers do
711
+ def authorize(username, password)
712
+ username == "foo" && password == "bar"
713
+ end
714
+ end
715
+
716
+ get "/", :protect => true do
717
+ "hey"
718
+ end
719
+ }
720
+
721
+ get "/"
722
+ assert forbidden?
723
+ assert_equal "go away", body
724
+
725
+ get "/", :user => "foo", :password => "bar"
726
+ assert ok?
727
+ assert_equal "hey", body
728
+ end
729
+
669
730
  # NOTE Block params behaves differently under 1.8 and 1.9. Under 1.8, block
670
731
  # param arity is lax: declaring a mismatched number of block params results
671
732
  # in a warning. Under 1.9, block param arity is strict: mismatched block
data/test/sass_test.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
+ require 'sass'
2
3
 
3
4
  class SassTest < Test::Unit::TestCase
4
5
  def sass_app(&block)
data/test/test_test.rb CHANGED
@@ -1,7 +1,15 @@
1
- require 'yaml'
2
1
  require File.dirname(__FILE__) + '/helper'
3
2
 
3
+ require 'yaml'
4
+
5
+ # silence deprecation warning when requiring sinatra/test
6
+ $VERBOSE, v = nil, $VERBOSE
7
+ require 'sinatra/test'
8
+ $VERBOSE = v
9
+
4
10
  class TestTest < Test::Unit::TestCase
11
+ include Sinatra::Test
12
+
5
13
  def request
6
14
  YAML.load(body)
7
15
  end
@@ -45,8 +53,8 @@ class TestTest < Test::Unit::TestCase
45
53
  assert_equal('DELETE', request['REQUEST_METHOD'])
46
54
 
47
55
  head '/'
48
- assert_equal('', response.body)
49
56
  assert response.headers['Content-Length'].to_i > 0
57
+ assert_equal('', body)
50
58
  end
51
59
 
52
60
  it 'allows to specify a body' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1.3
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-25 00:00:00 -07:00
12
+ date: 2009-05-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,6 +35,16 @@ dependencies:
35
35
  - !ruby/object:Gem::Version
36
36
  version: "1.0"
37
37
  version:
38
+ - !ruby/object:Gem::Dependency
39
+ name: rack-test
40
+ type: :development
41
+ version_requirement:
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.0
47
+ version:
38
48
  description: Classy web-development dressed in a DSL
39
49
  email: sinatrarb@googlegroups.com
40
50
  executables: []