sinatra 1.4.8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -47
  3. data/CONTRIBUTING.md +1 -1
  4. data/Gemfile +41 -49
  5. data/LICENSE +4 -1
  6. data/MAINTENANCE.md +42 -0
  7. data/README.de.md +644 -436
  8. data/README.es.md +6 -6
  9. data/README.fr.md +9 -9
  10. data/README.hu.md +37 -3
  11. data/README.ja.md +103 -45
  12. data/README.ko.md +8 -8
  13. data/README.md +471 -363
  14. data/README.pt-br.md +3 -3
  15. data/README.pt-pt.md +2 -2
  16. data/README.ru.md +42 -64
  17. data/README.zh.md +8 -8
  18. data/Rakefile +72 -49
  19. data/SECURITY.md +35 -0
  20. data/lib/sinatra/base.rb +137 -195
  21. data/lib/sinatra/indifferent_hash.rb +150 -0
  22. data/lib/sinatra/main.rb +1 -0
  23. data/lib/sinatra/show_exceptions.rb +63 -55
  24. data/lib/sinatra/version.rb +1 -1
  25. data/sinatra.gemspec +19 -7
  26. metadata +30 -164
  27. data/lib/sinatra/ext.rb +0 -17
  28. data/test/asciidoctor_test.rb +0 -72
  29. data/test/base_test.rb +0 -167
  30. data/test/builder_test.rb +0 -91
  31. data/test/coffee_test.rb +0 -96
  32. data/test/compile_test.rb +0 -183
  33. data/test/contest.rb +0 -91
  34. data/test/creole_test.rb +0 -65
  35. data/test/delegator_test.rb +0 -160
  36. data/test/encoding_test.rb +0 -20
  37. data/test/erb_test.rb +0 -116
  38. data/test/extensions_test.rb +0 -98
  39. data/test/filter_test.rb +0 -487
  40. data/test/haml_test.rb +0 -109
  41. data/test/helper.rb +0 -132
  42. data/test/helpers_test.rb +0 -1917
  43. data/test/integration/app.rb +0 -79
  44. data/test/integration_helper.rb +0 -236
  45. data/test/integration_test.rb +0 -104
  46. data/test/less_test.rb +0 -69
  47. data/test/liquid_test.rb +0 -77
  48. data/test/mapped_error_test.rb +0 -285
  49. data/test/markaby_test.rb +0 -80
  50. data/test/markdown_test.rb +0 -85
  51. data/test/mediawiki_test.rb +0 -68
  52. data/test/middleware_test.rb +0 -68
  53. data/test/nokogiri_test.rb +0 -67
  54. data/test/public/favicon.ico +0 -0
  55. data/test/public/hello+world.txt +0 -1
  56. data/test/rabl_test.rb +0 -89
  57. data/test/rack_test.rb +0 -45
  58. data/test/radius_test.rb +0 -59
  59. data/test/rdoc_test.rb +0 -66
  60. data/test/readme_test.rb +0 -130
  61. data/test/request_test.rb +0 -100
  62. data/test/response_test.rb +0 -63
  63. data/test/result_test.rb +0 -76
  64. data/test/route_added_hook_test.rb +0 -59
  65. data/test/routing_test.rb +0 -1456
  66. data/test/sass_test.rb +0 -115
  67. data/test/scss_test.rb +0 -88
  68. data/test/server_test.rb +0 -56
  69. data/test/settings_test.rb +0 -582
  70. data/test/sinatra_test.rb +0 -12
  71. data/test/slim_test.rb +0 -102
  72. data/test/static_test.rb +0 -266
  73. data/test/streaming_test.rb +0 -149
  74. data/test/stylus_test.rb +0 -90
  75. data/test/templates_test.rb +0 -382
  76. data/test/textile_test.rb +0 -65
  77. data/test/views/a/in_a.str +0 -1
  78. data/test/views/ascii.erb +0 -2
  79. data/test/views/b/in_b.str +0 -1
  80. data/test/views/calc.html.erb +0 -1
  81. data/test/views/error.builder +0 -3
  82. data/test/views/error.erb +0 -3
  83. data/test/views/error.haml +0 -3
  84. data/test/views/error.sass +0 -2
  85. data/test/views/explicitly_nested.str +0 -1
  86. data/test/views/foo/hello.test +0 -1
  87. data/test/views/hello.asciidoc +0 -1
  88. data/test/views/hello.builder +0 -1
  89. data/test/views/hello.coffee +0 -1
  90. data/test/views/hello.creole +0 -1
  91. data/test/views/hello.erb +0 -1
  92. data/test/views/hello.haml +0 -1
  93. data/test/views/hello.less +0 -5
  94. data/test/views/hello.liquid +0 -1
  95. data/test/views/hello.mab +0 -1
  96. data/test/views/hello.md +0 -1
  97. data/test/views/hello.mediawiki +0 -1
  98. data/test/views/hello.nokogiri +0 -1
  99. data/test/views/hello.rabl +0 -2
  100. data/test/views/hello.radius +0 -1
  101. data/test/views/hello.rdoc +0 -1
  102. data/test/views/hello.sass +0 -2
  103. data/test/views/hello.scss +0 -3
  104. data/test/views/hello.slim +0 -1
  105. data/test/views/hello.str +0 -1
  106. data/test/views/hello.styl +0 -2
  107. data/test/views/hello.test +0 -1
  108. data/test/views/hello.textile +0 -1
  109. data/test/views/hello.wlang +0 -1
  110. data/test/views/hello.yajl +0 -1
  111. data/test/views/layout2.builder +0 -3
  112. data/test/views/layout2.erb +0 -2
  113. data/test/views/layout2.haml +0 -2
  114. data/test/views/layout2.liquid +0 -2
  115. data/test/views/layout2.mab +0 -2
  116. data/test/views/layout2.nokogiri +0 -3
  117. data/test/views/layout2.rabl +0 -3
  118. data/test/views/layout2.radius +0 -2
  119. data/test/views/layout2.slim +0 -3
  120. data/test/views/layout2.str +0 -2
  121. data/test/views/layout2.test +0 -1
  122. data/test/views/layout2.wlang +0 -2
  123. data/test/views/nested.str +0 -1
  124. data/test/views/utf8.erb +0 -2
  125. data/test/wlang_test.rb +0 -87
  126. data/test/yajl_test.rb +0 -86
data/test/rabl_test.rb DELETED
@@ -1,89 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'rabl'
5
- require 'ostruct'
6
- require 'json'
7
- require 'active_support/core_ext/hash/conversions'
8
-
9
- class RablTest < Minitest::Test
10
- def rabl_app(&block)
11
- mock_app {
12
- set :views, File.dirname(__FILE__) + '/views'
13
- get '/', &block
14
- }
15
- get '/'
16
- end
17
-
18
- it 'renders inline rabl strings' do
19
- rabl_app do
20
- @foo = OpenStruct.new(:baz => 'w00t')
21
- rabl %q{
22
- object @foo
23
- attributes :baz
24
- }
25
- end
26
- assert ok?
27
- assert_equal '{"openstruct":{"baz":"w00t"}}', body
28
- end
29
- it 'renders .rabl files in views path' do
30
- rabl_app do
31
- @foo = OpenStruct.new(:bar => 'baz')
32
- rabl :hello
33
- end
34
- assert ok?
35
- assert_equal '{"openstruct":{"bar":"baz"}}', body
36
- end
37
-
38
- it "renders with file layouts" do
39
- rabl_app {
40
- @foo = OpenStruct.new(:bar => 'baz')
41
- rabl :hello, :layout => :layout2
42
- }
43
- assert ok?
44
- assert_equal '{"qux":{"openstruct":{"bar":"baz"}}}', body
45
- end
46
-
47
- it "raises error if template not found" do
48
- mock_app {
49
- get('/') { rabl :no_such_template }
50
- }
51
- assert_raises(Errno::ENOENT) { get('/') }
52
- end
53
-
54
- it "passes rabl options to the rabl engine" do
55
- mock_app do
56
- get('/') do
57
- @foo = OpenStruct.new(:bar => 'baz')
58
- rabl %q{
59
- object @foo
60
- attributes :bar
61
- }, :format => 'xml'
62
- end
63
- end
64
- get '/'
65
- assert ok?
66
- assert_body '<?xml version="1.0" encoding="UTF-8"?><openstruct><bar>baz</bar></openstruct>'
67
- end
68
-
69
- it "passes default rabl options to the rabl engine" do
70
- mock_app do
71
- set :rabl, :format => 'xml'
72
- get('/') do
73
- @foo = OpenStruct.new(:bar => 'baz')
74
- rabl %q{
75
- object @foo
76
- attributes :bar
77
- }
78
- end
79
- end
80
- get '/'
81
- assert ok?
82
- assert_body '<?xml version="1.0" encoding="UTF-8"?><openstruct><bar>baz</bar></openstruct>'
83
- end
84
-
85
- end
86
-
87
- rescue LoadError
88
- warn "#{$!.to_s}: skipping rabl tests"
89
- end
data/test/rack_test.rb DELETED
@@ -1,45 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
- require 'rack'
3
-
4
- class RackTest < Minitest::Test
5
- setup do
6
- @foo = Sinatra.new { get('/foo') { 'foo' }}
7
- @bar = Sinatra.new { get('/bar') { 'bar' }}
8
- end
9
-
10
- def build(*middleware)
11
- endpoint = middleware.pop
12
- @app = Rack::Builder.app do
13
- middleware.each { |m| use m }
14
- run endpoint
15
- end
16
- end
17
-
18
- def check(*middleware)
19
- build(*middleware)
20
- assert get('/foo').ok?
21
- assert_body 'foo'
22
- assert get('/bar').ok?
23
- assert_body 'bar'
24
- end
25
-
26
- it 'works as middleware in front of Rack::Lock, with lock enabled' do
27
- @foo.enable :lock
28
- check(@foo, Rack::Lock, @bar)
29
- end
30
-
31
- it 'works as middleware behind Rack::Lock, with lock enabled' do
32
- @foo.enable :lock
33
- check(Rack::Lock, @foo, @bar)
34
- end
35
-
36
- it 'works as middleware in front of Rack::Lock, with lock disabled' do
37
- @foo.disable :lock
38
- check(@foo, Rack::Lock, @bar)
39
- end
40
-
41
- it 'works as middleware behind Rack::Lock, with lock disabled' do
42
- @foo.disable :lock
43
- check(Rack::Lock, @foo, @bar)
44
- end
45
- end
data/test/radius_test.rb DELETED
@@ -1,59 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'radius'
5
-
6
- class RadiusTest < Minitest::Test
7
- def radius_app(&block)
8
- mock_app do
9
- set :views, File.dirname(__FILE__) + '/views'
10
- get('/', &block)
11
- end
12
- get '/'
13
- end
14
-
15
- it 'renders inline radius strings' do
16
- radius_app { radius '<h1>Hiya</h1>' }
17
- assert ok?
18
- assert_equal "<h1>Hiya</h1>", body
19
- end
20
-
21
- it 'renders .radius files in views path' do
22
- radius_app { radius :hello }
23
- assert ok?
24
- assert_equal "<h1>Hello From Radius</h1>\n", body
25
- end
26
-
27
- it "renders with inline layouts" do
28
- mock_app do
29
- layout { "<h1>THIS. IS. <r:yield /></h1>" }
30
- get('/') { radius '<EM>SPARTA</EM>' }
31
- end
32
- get '/'
33
- assert ok?
34
- assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
35
- end
36
-
37
- it "renders with file layouts" do
38
- radius_app { radius 'Hello World', :layout => :layout2 }
39
- assert ok?
40
- assert_equal "<h1>Radius Layout!</h1>\n<p>Hello World</p>\n", body
41
- end
42
-
43
- it "raises error if template not found" do
44
- mock_app { get('/') { radius :no_such_template } }
45
- assert_raises(Errno::ENOENT) { get('/') }
46
- end
47
-
48
- it "allows passing locals" do
49
- radius_app {
50
- radius '<r:value />', :locals => { :value => 'foo' }
51
- }
52
- assert ok?
53
- assert_equal 'foo', body
54
- end
55
- end
56
-
57
- rescue LoadError
58
- warn "#{$!.to_s}: skipping radius tests"
59
- end
data/test/rdoc_test.rb DELETED
@@ -1,66 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- begin
4
- require 'rdoc'
5
- require 'rdoc/markup/to_html'
6
-
7
- class RdocTest < Minitest::Test
8
- def rdoc_app(&block)
9
- mock_app do
10
- set :views, File.dirname(__FILE__) + '/views'
11
- get('/', &block)
12
- end
13
- get '/'
14
- end
15
-
16
- it 'renders inline rdoc strings' do
17
- rdoc_app { rdoc '= Hiya' }
18
- assert ok?
19
- assert_body(/<h1[^>]*>Hiya(<span><a href=\"#label-Hiya\">&para;<\/a> <a href=\"#(documentation|top)\">&uarr;<\/a><\/span>)?<\/h1>/)
20
- end
21
-
22
- it 'renders .rdoc files in views path' do
23
- rdoc_app { rdoc :hello }
24
- assert ok?
25
- assert_body(/<h1[^>]*>Hello From RDoc(<span><a href=\"#label-Hello\+From\+RDoc\">&para;<\/a> <a href=\"#(documentation|top)\">&uarr;<\/a><\/span>)?<\/h1>/)
26
- end
27
-
28
- it "raises error if template not found" do
29
- mock_app { get('/') { rdoc :no_such_template } }
30
- assert_raises(Errno::ENOENT) { get('/') }
31
- end
32
-
33
- it "renders with inline layouts" do
34
- mock_app do
35
- layout { 'THIS. IS. #{yield.upcase}!' }
36
- get('/') { rdoc 'Sparta', :layout_engine => :str }
37
- end
38
- get '/'
39
- assert ok?
40
- assert_like 'THIS. IS. <P>SPARTA</P>!', body
41
- end
42
-
43
- it "renders with file layouts" do
44
- rdoc_app {
45
- rdoc 'Hello World', :layout => :layout2, :layout_engine => :erb
46
- }
47
- assert ok?
48
- assert_body "ERB Layout!\n<p>Hello World</p>"
49
- end
50
-
51
- it "can be used in a nested fashion for partials and whatnot" do
52
- mock_app do
53
- template(:inner) { "hi" }
54
- template(:outer) { "<outer><%= rdoc :inner %></outer>" }
55
- get('/') { erb :outer }
56
- end
57
-
58
- get '/'
59
- assert ok?
60
- assert_like '<outer><p>hi</p></outer>', body
61
- end
62
- end
63
-
64
- rescue LoadError
65
- warn "#{$!.to_s}: skipping rdoc tests"
66
- end
data/test/readme_test.rb DELETED
@@ -1,130 +0,0 @@
1
- # Tests to check if all the README examples work.
2
- require File.expand_path('../helper', __FILE__)
3
-
4
- class ReadmeTest < Minitest::Test
5
- example do
6
- mock_app { get('/') { 'Hello world!' } }
7
- get '/'
8
- assert_body 'Hello world!'
9
- end
10
-
11
- section "Routes" do
12
- example do
13
- mock_app do
14
- get('/') { ".. show something .." }
15
-
16
- post('/') { ".. create something .." }
17
-
18
- put('/') { ".. replace something .." }
19
-
20
- patch('/') { ".. modify something .." }
21
-
22
- delete('/') { ".. annihilate something .." }
23
-
24
- options('/') { ".. appease something .." }
25
-
26
- link('/') { ".. affiliate something .." }
27
-
28
- unlink('/') { ".. separate something .." }
29
- end
30
-
31
- get '/'
32
- assert_body '.. show something ..'
33
-
34
- post '/'
35
- assert_body '.. create something ..'
36
-
37
- put '/'
38
- assert_body '.. replace something ..'
39
-
40
- patch '/'
41
- assert_body '.. modify something ..'
42
-
43
- delete '/'
44
- assert_body '.. annihilate something ..'
45
-
46
- options '/'
47
- assert_body '.. appease something ..'
48
-
49
- link '/'
50
- assert_body '.. affiliate something ..'
51
-
52
- unlink '/'
53
- assert_body '.. separate something ..'
54
- end
55
-
56
- example do
57
- mock_app do
58
- get('/hello/:name') do
59
- # matches "GET /hello/foo" and "GET /hello/bar"
60
- # params[:name] is 'foo' or 'bar'
61
- "Hello #{params[:name]}!"
62
- end
63
- end
64
-
65
- get '/hello/foo'
66
- assert_body 'Hello foo!'
67
-
68
- get '/hello/bar'
69
- assert_body 'Hello bar!'
70
- end
71
-
72
- example do
73
- mock_app { get('/hello/:name') { |n| "Hello #{n}!" } }
74
-
75
- get '/hello/foo'
76
- assert_body 'Hello foo!'
77
-
78
- get '/hello/bar'
79
- assert_body 'Hello bar!'
80
- end
81
-
82
- example do
83
- mock_app do
84
- get('/say/*/to/*') do
85
- # matches /say/hello/to/world
86
- params[:splat].inspect # => ["hello", "world"]
87
- end
88
-
89
- get('/download/*.*') do
90
- # matches /download/path/to/file.xml
91
- params[:splat].inspect # => ["path/to/file", "xml"]
92
- end
93
- end
94
-
95
- get "/say/hello/to/world"
96
- assert_body '["hello", "world"]'
97
-
98
- get "/download/path/to/file.xml"
99
- assert_body '["path/to/file", "xml"]'
100
- end
101
-
102
- example do
103
- mock_app do
104
- get(%r{/hello/([\w]+)}) {
105
- "Hello, #{params[:captures].first}!"
106
- }
107
- end
108
-
109
- get '/hello/foo'
110
- assert_body 'Hello, foo!'
111
-
112
- get '/hello/bar'
113
- assert_body 'Hello, bar!'
114
- end
115
-
116
- example do
117
- mock_app do
118
- get( %r{/hello/([\w]+)}) { |c|
119
- "Hello, #{c}!"
120
- }
121
- end
122
-
123
- get '/hello/foo'
124
- assert_body 'Hello, foo!'
125
-
126
- get '/hello/bar'
127
- assert_body 'Hello, bar!'
128
- end
129
- end
130
- end
data/test/request_test.rb DELETED
@@ -1,100 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
- require 'stringio'
3
-
4
- class RequestTest < Minitest::Test
5
- it 'responds to #user_agent' do
6
- request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'})
7
- assert request.respond_to?(:user_agent)
8
- assert_equal 'Test', request.user_agent
9
- end
10
-
11
- it 'parses POST params when Content-Type is form-dataish' do
12
- request = Sinatra::Request.new(
13
- 'REQUEST_METHOD' => 'PUT',
14
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
15
- 'rack.input' => StringIO.new('foo=bar')
16
- )
17
- assert_equal 'bar', request.params['foo']
18
- end
19
-
20
- it 'is secure when the url scheme is https' do
21
- request = Sinatra::Request.new('rack.url_scheme' => 'https')
22
- assert request.secure?
23
- end
24
-
25
- it 'is not secure when the url scheme is http' do
26
- request = Sinatra::Request.new('rack.url_scheme' => 'http')
27
- assert !request.secure?
28
- end
29
-
30
- it 'respects X-Forwarded-Proto header for proxied SSL' do
31
- request = Sinatra::Request.new('HTTP_X_FORWARDED_PROTO' => 'https')
32
- assert request.secure?
33
- end
34
-
35
- it 'is possible to marshal params' do
36
- request = Sinatra::Request.new(
37
- 'REQUEST_METHOD' => 'PUT',
38
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
39
- 'rack.input' => StringIO.new('foo=bar')
40
- )
41
- Sinatra::Base.new!.send(:indifferent_hash).replace(request.params)
42
- dumped = Marshal.dump(request.params)
43
- assert_equal 'bar', Marshal.load(dumped)['foo']
44
- end
45
-
46
- it "exposes the preferred type's parameters" do
47
- request = Sinatra::Request.new(
48
- 'HTTP_ACCEPT' => 'image/jpeg; compress=0.25'
49
- )
50
- assert_equal({ 'compress' => '0.25' }, request.preferred_type.params)
51
- end
52
-
53
- it "makes accept types behave like strings" do
54
- request = Sinatra::Request.new('HTTP_ACCEPT' => 'image/jpeg; compress=0.25')
55
- assert request.accept?('image/jpeg')
56
- assert_equal 'image/jpeg', request.preferred_type.to_s
57
- assert_equal 'image/jpeg; compress=0.25', request.preferred_type.to_s(true)
58
- assert_equal 'image/jpeg', request.preferred_type.to_str
59
- assert_equal 'image', request.preferred_type.split('/').first
60
-
61
- String.instance_methods.each do |method|
62
- next unless "".respond_to? method
63
- assert request.preferred_type.respond_to?(method), "responds to #{method}"
64
- end
65
- end
66
-
67
- it "accepts types when wildcards are requested" do
68
- request = Sinatra::Request.new('HTTP_ACCEPT' => 'image/*')
69
- assert request.accept?('image/jpeg')
70
- end
71
-
72
- it "properly decodes MIME type parameters" do
73
- request = Sinatra::Request.new(
74
- 'HTTP_ACCEPT' => 'image/jpeg;unquoted=0.25;quoted="0.25";chartest="\";,\x"'
75
- )
76
- expected = { 'unquoted' => '0.25', 'quoted' => '0.25', 'chartest' => '";,x' }
77
- assert_equal(expected, request.preferred_type.params)
78
- end
79
-
80
- it 'accepts */* when HTTP_ACCEPT is not present in the request' do
81
- request = Sinatra::Request.new Hash.new
82
- assert_equal 1, request.accept.size
83
- assert request.accept?('text/html')
84
- assert_equal '*/*', request.preferred_type.to_s
85
- assert_equal '*/*', request.preferred_type.to_s(true)
86
- end
87
-
88
- it 'accepts */* when HTTP_ACCEPT is blank in the request' do
89
- request = Sinatra::Request.new 'HTTP_ACCEPT' => ''
90
- assert_equal 1, request.accept.size
91
- assert request.accept?('text/html')
92
- assert_equal '*/*', request.preferred_type.to_s
93
- assert_equal '*/*', request.preferred_type.to_s(true)
94
- end
95
-
96
- it 'will not accept types not specified in HTTP_ACCEPT when HTTP_ACCEPT is provided' do
97
- request = Sinatra::Request.new 'HTTP_ACCEPT' => 'application/json'
98
- assert !request.accept?('text/html')
99
- end
100
- end
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path('../helper', __FILE__)
4
-
5
- class ResponseTest < Minitest::Test
6
- setup { @response = Sinatra::Response.new }
7
-
8
- def assert_same_body(a, b)
9
- assert_equal a.to_enum(:each).to_a, b.to_enum(:each).to_a
10
- end
11
-
12
- it "initializes with 200, text/html, and empty body" do
13
- assert_equal 200, @response.status
14
- assert_equal 'text/html', @response['Content-Type']
15
- assert_equal [], @response.body
16
- end
17
-
18
- it 'uses case insensitive headers' do
19
- @response['content-type'] = 'application/foo'
20
- assert_equal 'application/foo', @response['Content-Type']
21
- assert_equal 'application/foo', @response['CONTENT-TYPE']
22
- end
23
-
24
- it 'writes to body' do
25
- @response.body = 'Hello'
26
- @response.write ' World'
27
- assert_equal 'Hello World', @response.body.join
28
- end
29
-
30
- [204, 304].each do |status_code|
31
- it "removes the Content-Type header and body when response status is #{status_code}" do
32
- @response.status = status_code
33
- @response.body = ['Hello World']
34
- assert_equal [status_code, {}, []], @response.finish
35
- end
36
- end
37
-
38
- it 'Calculates the Content-Length using the bytesize of the body' do
39
- @response.body = ['Hello', 'World!', '✈']
40
- _, headers, body = @response.finish
41
- assert_equal '14', headers['Content-Length']
42
- assert_same_body @response.body, body
43
- end
44
-
45
- it 'does not call #to_ary or #inject on the body' do
46
- object = Object.new
47
- def object.inject(*) fail 'called' end
48
- def object.to_ary(*) fail 'called' end
49
- def object.each(*) end
50
- @response.body = object
51
- assert @response.finish
52
- end
53
-
54
- it 'does not nest a Sinatra::Response' do
55
- @response.body = Sinatra::Response.new ["foo"]
56
- assert_same_body @response.body, ["foo"]
57
- end
58
-
59
- it 'does not nest a Rack::Response' do
60
- @response.body = Rack::Response.new ["foo"]
61
- assert_same_body @response.body, ["foo"]
62
- end
63
- end
data/test/result_test.rb DELETED
@@ -1,76 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class ResultTest < Minitest::Test
4
- it "sets response.body when result is a String" do
5
- mock_app { get('/') { 'Hello World' } }
6
-
7
- get '/'
8
- assert ok?
9
- assert_equal 'Hello World', body
10
- end
11
-
12
- it "sets response.body when result is an Array of Strings" do
13
- mock_app { get('/') { ['Hello', 'World'] } }
14
-
15
- get '/'
16
- assert ok?
17
- assert_equal 'HelloWorld', body
18
- end
19
-
20
- it "sets response.body when result responds to #each" do
21
- mock_app do
22
- get('/') do
23
- res = lambda { 'Hello World' }
24
- def res.each ; yield call ; end
25
- return res
26
- end
27
- end
28
-
29
- get '/'
30
- assert ok?
31
- assert_equal 'Hello World', body
32
- end
33
-
34
- it "sets response.body to [] when result is nil" do
35
- mock_app { get( '/') { nil } }
36
-
37
- get '/'
38
- assert ok?
39
- assert_equal '', body
40
- end
41
-
42
- it "sets status, headers, and body when result is a Rack response tuple" do
43
- mock_app {
44
- get('/') { [203, {'Content-Type' => 'foo/bar'}, 'Hello World'] }
45
- }
46
-
47
- get '/'
48
- assert_equal 203, status
49
- assert_equal 'foo/bar', response['Content-Type']
50
- assert_equal 'Hello World', body
51
- end
52
-
53
- it "sets status and body when result is a two-tuple" do
54
- mock_app { get('/') { [409, 'formula of'] } }
55
-
56
- get '/'
57
- assert_equal 409, status
58
- assert_equal 'formula of', body
59
- end
60
-
61
- it "raises a ArgumentError when result is a non two or three tuple Array" do
62
- mock_app {
63
- get('/') { [409, 'formula of', 'something else', 'even more'] }
64
- }
65
-
66
- assert_raises(ArgumentError) { get '/' }
67
- end
68
-
69
- it "sets status when result is a Fixnum status code" do
70
- mock_app { get('/') { 205 } }
71
-
72
- get '/'
73
- assert_equal 205, status
74
- assert_equal '', body
75
- end
76
- end
@@ -1,59 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- module RouteAddedTest
4
- @routes, @procs = [], []
5
- def self.routes ; @routes ; end
6
- def self.procs ; @procs ; end
7
- def self.route_added(verb, path, proc)
8
- @routes << [verb, path]
9
- @procs << proc
10
- end
11
- end
12
-
13
- class RouteAddedHookTest < Minitest::Test
14
- setup do
15
- RouteAddedTest.routes.clear
16
- RouteAddedTest.procs.clear
17
- end
18
-
19
- it "should be notified of an added route" do
20
- mock_app(Class.new(Sinatra::Base)) do
21
- register RouteAddedTest
22
- get('/') {}
23
- end
24
-
25
- assert_equal [["GET", "/"], ["HEAD", "/"]],
26
- RouteAddedTest.routes
27
- end
28
-
29
- it "should include hooks from superclass" do
30
- a = Class.new(Class.new(Sinatra::Base))
31
- b = Class.new(a)
32
-
33
- a.register RouteAddedTest
34
- b.class_eval { post("/sub_app_route") {} }
35
-
36
- assert_equal [["POST", "/sub_app_route"]],
37
- RouteAddedTest.routes
38
- end
39
-
40
- it "should only run once per extension" do
41
- mock_app(Class.new(Sinatra::Base)) do
42
- register RouteAddedTest
43
- register RouteAddedTest
44
- get('/') {}
45
- end
46
-
47
- assert_equal [["GET", "/"], ["HEAD", "/"]],
48
- RouteAddedTest.routes
49
- end
50
-
51
- it "should pass route blocks as an argument" do
52
- mock_app(Class.new(Sinatra::Base)) do
53
- register RouteAddedTest
54
- get('/') {}
55
- end
56
-
57
- assert_kind_of Proc, RouteAddedTest.procs.first
58
- end
59
- end