sinatra-sinatra 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGES +1 -1
  2. data/README.rdoc +1 -1
  3. data/Rakefile +1 -20
  4. data/lib/sinatra.rb +0 -1
  5. data/lib/sinatra/base.rb +4 -27
  6. data/sinatra.gemspec +4 -45
  7. data/test/server_test.rb +14 -10
  8. data/test/templates_test.rb +22 -0
  9. data/test/views/foo/hello.test +1 -0
  10. metadata +4 -46
  11. data/compat/app_test.rb +0 -282
  12. data/compat/application_test.rb +0 -262
  13. data/compat/builder_test.rb +0 -101
  14. data/compat/compat_test.rb +0 -12
  15. data/compat/custom_error_test.rb +0 -62
  16. data/compat/erb_test.rb +0 -136
  17. data/compat/events_test.rb +0 -78
  18. data/compat/filter_test.rb +0 -30
  19. data/compat/haml_test.rb +0 -236
  20. data/compat/helper.rb +0 -33
  21. data/compat/mapped_error_test.rb +0 -72
  22. data/compat/pipeline_test.rb +0 -45
  23. data/compat/public/foo.xml +0 -1
  24. data/compat/sass_test.rb +0 -67
  25. data/compat/sessions_test.rb +0 -42
  26. data/compat/streaming_test.rb +0 -133
  27. data/compat/sym_params_test.rb +0 -19
  28. data/compat/template_test.rb +0 -30
  29. data/compat/use_in_file_templates_test.rb +0 -47
  30. data/compat/views/foo.builder +0 -1
  31. data/compat/views/foo.erb +0 -1
  32. data/compat/views/foo.haml +0 -1
  33. data/compat/views/foo.sass +0 -2
  34. data/compat/views/foo_layout.erb +0 -2
  35. data/compat/views/foo_layout.haml +0 -2
  36. data/compat/views/layout_test/foo.builder +0 -1
  37. data/compat/views/layout_test/foo.erb +0 -1
  38. data/compat/views/layout_test/foo.haml +0 -1
  39. data/compat/views/layout_test/foo.sass +0 -2
  40. data/compat/views/layout_test/layout.builder +0 -3
  41. data/compat/views/layout_test/layout.erb +0 -1
  42. data/compat/views/layout_test/layout.haml +0 -1
  43. data/compat/views/layout_test/layout.sass +0 -2
  44. data/compat/views/no_layout/no_layout.builder +0 -1
  45. data/compat/views/no_layout/no_layout.haml +0 -1
  46. data/lib/sinatra/compat.rb +0 -266
  47. data/lib/sinatra/test.rb +0 -128
  48. data/lib/sinatra/test/bacon.rb +0 -19
  49. data/lib/sinatra/test/rspec.rb +0 -13
  50. data/lib/sinatra/test/spec.rb +0 -11
  51. data/lib/sinatra/test/unit.rb +0 -13
  52. data/test/test_test.rb +0 -152
@@ -1,78 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- context "Simple Events" do
4
- def simple_request_hash(method, path)
5
- Rack::Request.new({
6
- 'REQUEST_METHOD' => method.to_s.upcase,
7
- 'PATH_INFO' => path
8
- })
9
- end
10
-
11
- class MockResult < Struct.new(:block, :params)
12
- end
13
-
14
- def invoke_simple(path, request_path, &b)
15
- params = nil
16
- get path do
17
- params = self.params
18
- b.call if b
19
- end
20
- get_it request_path
21
- MockResult.new(b, params)
22
- end
23
-
24
- setup { Sinatra.application = nil }
25
-
26
- specify "return last value" do
27
- block = Proc.new { 'Simple' }
28
- result = invoke_simple('/', '/', &block)
29
- result.should.not.be.nil
30
- result.block.should.be block
31
- result.params.should.equal Hash.new
32
- end
33
-
34
- specify "takes params in path" do
35
- result = invoke_simple('/:foo/:bar', '/a/b')
36
- result.should.not.be.nil
37
- result.params.should.equal "foo" => 'a', "bar" => 'b'
38
-
39
- # unscapes
40
- Sinatra.application = nil
41
- result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
42
- result.should.not.be.nil
43
- result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
44
- end
45
-
46
- specify "takes optional params in path" do
47
- result = invoke_simple('/?:foo?/?:bar?', '/a/b')
48
- result.should.not.be.nil
49
- result.params.should.equal "foo" => 'a', "bar" => 'b'
50
-
51
- Sinatra.application = nil
52
- result = invoke_simple('/?:foo?/?:bar?', '/a/')
53
- result.should.not.be.nil
54
- result.params.should.equal "foo" => 'a', "bar" => nil
55
-
56
- Sinatra.application = nil
57
- result = invoke_simple('/?:foo?/?:bar?', '/a')
58
- result.should.not.be.nil
59
- result.params.should.equal "foo" => 'a', "bar" => nil
60
-
61
- Sinatra.application = nil
62
- result = invoke_simple('/:foo?/?:bar?', '/')
63
- result.should.not.be.nil
64
- result.params.should.equal "foo" => nil, "bar" => nil
65
- end
66
-
67
- specify "ignores to many /'s" do
68
- result = invoke_simple('/x/y', '/x//y')
69
- result.should.not.be.nil
70
- end
71
-
72
- specify "understands splat" do
73
- invoke_simple('/foo/*', '/foo/bar').should.not.be.nil
74
- invoke_simple('/foo/*', '/foo/bar/baz').should.not.be.nil
75
- invoke_simple('/foo/*', '/foo/baz').should.not.be.nil
76
- end
77
-
78
- end
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- context "before filters" do
4
-
5
- setup do
6
- Sinatra.application = nil
7
- @app = Sinatra.application
8
- end
9
-
10
- specify "should be executed in the order defined" do
11
- invoked = 0x0
12
- @app.before { invoked = 0x01 }
13
- @app.before { invoked |= 0x02 }
14
- @app.get('/') { 'Hello World' }
15
- get_it '/'
16
- should.be.ok
17
- body.should.be == 'Hello World'
18
- invoked.should.be == 0x03
19
- end
20
-
21
- specify "should be capable of modifying the request" do
22
- @app.get('/foo') { 'foo' }
23
- @app.get('/bar') { 'bar' }
24
- @app.before { request.path_info = '/bar' }
25
- get_it '/foo'
26
- should.be.ok
27
- body.should.be == 'bar'
28
- end
29
-
30
- end
data/compat/haml_test.rb DELETED
@@ -1,236 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- context "Haml" do
4
-
5
- setup do
6
- Sinatra.application = nil
7
- end
8
-
9
- context "without layouts" do
10
-
11
- setup do
12
- Sinatra.application = nil
13
- end
14
-
15
- specify "should render" do
16
-
17
- get '/no_layout' do
18
- haml '== #{1+1}'
19
- end
20
-
21
- get_it '/no_layout'
22
- should.be.ok
23
- body.should == "2\n"
24
-
25
- end
26
- end
27
-
28
- context "with layouts" do
29
-
30
- setup do
31
- Sinatra.application = nil
32
- end
33
-
34
- specify "can be inline" do
35
-
36
- layout do
37
- '== This is #{yield}!'
38
- end
39
-
40
- get '/lay' do
41
- haml 'Blake'
42
- end
43
-
44
- get_it '/lay'
45
- should.be.ok
46
- body.should.equal "This is Blake\n!\n"
47
-
48
- end
49
-
50
- specify "can use named layouts" do
51
-
52
- layout :pretty do
53
- '%h1== #{yield}'
54
- end
55
-
56
- get '/pretty' do
57
- haml 'Foo', :layout => :pretty
58
- end
59
-
60
- get '/not_pretty' do
61
- haml 'Bar'
62
- end
63
-
64
- get_it '/pretty'
65
- body.should.equal "<h1>Foo</h1>\n"
66
-
67
- get_it '/not_pretty'
68
- body.should.equal "Bar\n"
69
-
70
- end
71
-
72
- specify "can be read from a file if they're not inlined" do
73
-
74
- get '/foo' do
75
- @title = 'Welcome to the Hello Program'
76
- haml 'Blake', :layout => :foo_layout,
77
- :views_directory => File.dirname(__FILE__) + "/views"
78
- end
79
-
80
- get_it '/foo'
81
- body.should.equal "Welcome to the Hello Program\nHi Blake\n"
82
-
83
- end
84
-
85
- specify "can be read from file and layout from text" do
86
- get '/foo' do
87
- haml 'Test', :layout => '== Foo #{yield}'
88
- end
89
-
90
- get_it '/foo'
91
-
92
- body.should.equal "Foo Test\n"
93
- end
94
-
95
- end
96
-
97
- context "Templates (in general)" do
98
-
99
- setup do
100
- Sinatra.application = nil
101
- end
102
-
103
- specify "are read from files if Symbols" do
104
-
105
- get '/from_file' do
106
- @name = 'Alena'
107
- haml :foo, :views_directory => File.dirname(__FILE__) + "/views"
108
- end
109
-
110
- get_it '/from_file'
111
-
112
- body.should.equal "You rock Alena!\n"
113
-
114
- end
115
-
116
- specify "use layout.ext by default if available" do
117
-
118
- get '/' do
119
- haml :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
120
- end
121
-
122
- get_it '/'
123
- should.be.ok
124
- body.should.equal "x This is foo!\n x\n"
125
-
126
- end
127
-
128
- specify "renders without layout" do
129
-
130
- get '/' do
131
- haml :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
132
- end
133
-
134
- get_it '/'
135
- should.be.ok
136
- body.should.equal "<h1>No Layout!</h1>\n"
137
-
138
- end
139
-
140
- specify "can render with no layout" do
141
- layout do
142
- "X\n= yield\nX"
143
- end
144
-
145
- get '/' do
146
- haml 'blake', :layout => false
147
- end
148
-
149
- get_it '/'
150
-
151
- body.should.equal "blake\n"
152
- end
153
-
154
- specify "raises error if template not found" do
155
- get '/' do
156
- haml :not_found
157
- end
158
-
159
- lambda { get_it '/' }.should.raise(Errno::ENOENT)
160
- end
161
-
162
- specify "use layout.ext by default if available" do
163
-
164
- template :foo do
165
- 'asdf'
166
- end
167
-
168
- get '/' do
169
- haml :foo, :layout => false,
170
- :views_directory => File.dirname(__FILE__) + "/views/layout_test"
171
- end
172
-
173
- get_it '/'
174
- should.be.ok
175
- body.should.equal "asdf\n"
176
-
177
- end
178
-
179
- end
180
-
181
- describe 'Options passed to the HAML interpreter' do
182
- setup do
183
- Sinatra.application = nil
184
- end
185
-
186
- specify 'default to filename and line of caller' do
187
-
188
- get '/' do
189
- haml 'foo'
190
- end
191
-
192
- Haml::Engine.expects(:new).with('foo', {:filename => __FILE__,
193
- :line => (__LINE__-4)}).returns(stub(:render => 'foo'))
194
-
195
- get_it '/'
196
- should.be.ok
197
-
198
- end
199
-
200
- specify 'can be configured by passing :options to haml' do
201
-
202
- get '/' do
203
- haml 'foo', :options => {:format => :html4}
204
- end
205
-
206
- Haml::Engine.expects(:new).with('foo', {:filename => __FILE__,
207
- :line => (__LINE__-4), :format => :html4}).returns(stub(:render => 'foo'))
208
-
209
- get_it '/'
210
- should.be.ok
211
-
212
- end
213
-
214
- specify 'can be configured using set_option :haml' do
215
-
216
- configure do
217
- set_option :haml, :format => :html4,
218
- :escape_html => true
219
- end
220
-
221
- get '/' do
222
- haml 'foo'
223
- end
224
-
225
- Haml::Engine.expects(:new).with('foo', {:filename => __FILE__,
226
- :line => (__LINE__-4), :format => :html4,
227
- :escape_html => true}).returns(stub(:render => 'foo'))
228
-
229
- get_it '/'
230
- should.be.ok
231
-
232
- end
233
-
234
- end
235
-
236
- end
data/compat/helper.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'rubygems'
2
- require 'mocha'
3
-
4
- # disable warnings in compat specs.
5
- $VERBOSE = nil
6
-
7
- $:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
8
-
9
- ENV['RACK_ENV'] ||= 'test'
10
-
11
- require 'sinatra'
12
- require 'sinatra/test'
13
- require 'sinatra/test/unit'
14
- require 'sinatra/test/spec'
15
-
16
- module Sinatra::Test
17
- # we need to remove the new test helper methods since they conflict with
18
- # the top-level methods of the same name.
19
- %w(get head post put delete).each do |verb|
20
- remove_method verb
21
- end
22
- include Sinatra::Delegator
23
- end
24
-
25
- class Test::Unit::TestCase
26
- include Sinatra::Test
27
-
28
- PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS)
29
-
30
- def setup
31
- @app = lambda { |env| Sinatra::Application.call(env) }
32
- end
33
- end
@@ -1,72 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class FooError < RuntimeError; end
4
-
5
- context "Mapped errors" do
6
-
7
- setup do
8
- Sinatra.application = nil
9
- Sinatra.application.options.raise_errors = false
10
- end
11
-
12
- specify "are rescued and run in context" do
13
-
14
- error FooError do
15
- 'MAPPED ERROR!'
16
- end
17
-
18
- get '/' do
19
- raise FooError
20
- end
21
-
22
- get_it '/'
23
-
24
- should.be.server_error
25
- body.should.equal 'MAPPED ERROR!'
26
-
27
- end
28
-
29
- specify "renders empty if no each method on result" do
30
-
31
- error FooError do
32
- nil
33
- end
34
-
35
- get '/' do
36
- raise FooError
37
- end
38
-
39
- get_it '/'
40
-
41
- should.be.server_error
42
- body.should.be.empty
43
-
44
- end
45
-
46
- specify "doesn't override status if set" do
47
-
48
- error FooError do
49
- status(200)
50
- end
51
-
52
- get '/' do
53
- raise FooError
54
- end
55
-
56
- get_it '/'
57
-
58
- should.be.ok
59
-
60
- end
61
-
62
- specify "raises errors when the raise_errors option is set" do
63
- Sinatra.application.options.raise_errors = true
64
- error FooError do
65
- end
66
- get '/' do
67
- raise FooError
68
- end
69
- assert_raises(FooError) { get_it('/') }
70
- end
71
-
72
- end