bmizerany-sinatra 0.3.2 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +40 -0
- data/CHANGES +174 -0
- data/README.rdoc +138 -116
- data/Rakefile +27 -9
- data/{test → compat}/app_test.rb +11 -10
- data/{test → compat}/application_test.rb +21 -5
- data/compat/builder_test.rb +101 -0
- data/{test → compat}/custom_error_test.rb +0 -0
- data/compat/erb_test.rb +136 -0
- data/{test → compat}/events_test.rb +16 -3
- data/compat/filter_test.rb +30 -0
- data/compat/haml_test.rb +233 -0
- data/compat/helper.rb +30 -0
- data/compat/mapped_error_test.rb +72 -0
- data/{test → compat}/pipeline_test.rb +9 -4
- data/{test → compat}/public/foo.xml +0 -0
- data/compat/sass_test.rb +57 -0
- data/{test → compat}/sessions_test.rb +0 -0
- data/{test → compat}/streaming_test.rb +4 -1
- data/{test → compat}/sym_params_test.rb +0 -0
- data/{test → compat}/template_test.rb +0 -0
- data/{test → compat}/use_in_file_templates_test.rb +0 -0
- data/{test → compat}/views/foo.builder +0 -0
- data/{test → compat}/views/foo.erb +0 -0
- data/{test → compat}/views/foo.haml +0 -0
- data/{test → compat}/views/foo.sass +0 -0
- data/{test → compat}/views/foo_layout.erb +0 -0
- data/{test → compat}/views/foo_layout.haml +0 -0
- data/{test → compat}/views/layout_test/foo.builder +0 -0
- data/{test → compat}/views/layout_test/foo.erb +0 -0
- data/{test → compat}/views/layout_test/foo.haml +0 -0
- data/{test → compat}/views/layout_test/foo.sass +0 -0
- data/{test → compat}/views/layout_test/layout.builder +0 -0
- data/{test → compat}/views/layout_test/layout.erb +0 -0
- data/{test → compat}/views/layout_test/layout.haml +0 -0
- data/{test → compat}/views/layout_test/layout.sass +0 -0
- data/{test → compat}/views/no_layout/no_layout.builder +0 -0
- data/{test → compat}/views/no_layout/no_layout.haml +0 -0
- data/lib/sinatra/base.rb +818 -0
- data/lib/sinatra/compat.rb +239 -0
- data/{images → lib/sinatra/images}/404.png +0 -0
- data/{images → lib/sinatra/images}/500.png +0 -0
- data/lib/sinatra/main.rb +48 -0
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +7 -8
- data/lib/sinatra/test/spec.rb +3 -4
- data/lib/sinatra/test/unit.rb +3 -5
- data/lib/sinatra/test.rb +109 -0
- data/lib/sinatra.rb +4 -1466
- data/sinatra.gemspec +67 -35
- data/test/base_test.rb +68 -0
- data/test/builder_test.rb +50 -87
- data/test/data/reload_app_file.rb +3 -0
- data/test/erb_test.rb +38 -124
- data/test/filter_test.rb +27 -22
- data/test/haml_test.rb +51 -216
- data/test/helper.rb +18 -5
- data/test/helpers_test.rb +361 -0
- data/test/mapped_error_test.rb +137 -49
- data/test/middleware_test.rb +58 -0
- data/test/options_test.rb +97 -0
- data/test/reload_test.rb +61 -0
- data/test/request_test.rb +9 -0
- data/test/result_test.rb +88 -0
- data/test/routing_test.rb +334 -0
- data/test/sass_test.rb +27 -48
- data/test/sinatra_test.rb +13 -0
- data/test/static_test.rb +57 -0
- data/test/templates_test.rb +88 -0
- data/test/views/hello.builder +1 -0
- data/test/views/hello.erb +1 -0
- data/test/views/hello.haml +1 -0
- data/test/views/hello.sass +2 -0
- data/test/views/hello.test +1 -0
- data/test/views/layout2.builder +3 -0
- data/test/views/layout2.erb +2 -0
- data/test/views/layout2.haml +2 -0
- data/test/views/layout2.test +1 -0
- metadata +78 -46
- data/ChangeLog +0 -78
- data/lib/sinatra/test/methods.rb +0 -76
- data/test/event_context_test.rb +0 -15
data/Rakefile
CHANGED
@@ -8,13 +8,19 @@ task :default => :test
|
|
8
8
|
|
9
9
|
desc 'Run specs with story style output'
|
10
10
|
task :spec do
|
11
|
-
|
11
|
+
pattern = ENV['TEST'] || '.*'
|
12
|
+
sh "specrb --testcase '#{pattern}' --specdox -Ilib:test test/*_test.rb"
|
12
13
|
end
|
13
14
|
|
14
15
|
desc 'Run specs with unit test style output'
|
15
|
-
task :test
|
16
|
-
|
17
|
-
|
16
|
+
task :test do |t|
|
17
|
+
sh "specrb -Ilib:test test/*_test.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Run compatibility specs'
|
21
|
+
task :compat do |t|
|
22
|
+
pattern = ENV['TEST'] || '.*'
|
23
|
+
sh "specrb --testcase '#{pattern}' -Ilib:test compat/*_test.rb"
|
18
24
|
end
|
19
25
|
|
20
26
|
# PACKAGING ============================================================
|
@@ -141,11 +147,23 @@ task 'doc:book' => ['book/output/sinatra-book.html']
|
|
141
147
|
|
142
148
|
# Gemspec Helpers ====================================================
|
143
149
|
|
144
|
-
|
150
|
+
def source_version
|
151
|
+
line = File.read('lib/sinatra/base.rb')[/^\s*VERSION = .*/]
|
152
|
+
line.match(/.*VERSION = '(.*)'/)[1]
|
153
|
+
end
|
154
|
+
|
155
|
+
project_files =
|
156
|
+
FileList[
|
157
|
+
'{lib,test,compat,images}/**',
|
158
|
+
'Rakefile', 'CHANGES', 'README.rdoc'
|
159
|
+
]
|
160
|
+
file 'sinatra.gemspec' => project_files do |f|
|
145
161
|
# read spec file and split out manifest section
|
146
162
|
spec = File.read(f.name)
|
147
|
-
|
148
|
-
|
163
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
164
|
+
# replace version and date
|
165
|
+
head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
|
166
|
+
head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
|
149
167
|
# determine file list from git ls-files
|
150
168
|
files = `git ls-files`.
|
151
169
|
split("\n").
|
@@ -155,8 +173,8 @@ file 'sinatra.gemspec' => FileList['{lib,test,images}/**','Rakefile'] do |f|
|
|
155
173
|
map{ |file| " #{file}" }.
|
156
174
|
join("\n")
|
157
175
|
# piece file back together and write...
|
158
|
-
|
159
|
-
spec =
|
176
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
177
|
+
spec = [head,manifest,tail].join(" # = MANIFEST =\n")
|
160
178
|
File.open(f.name, 'w') { |io| io.write(spec) }
|
161
179
|
puts "updated #{f.name}"
|
162
180
|
end
|
data/{test → compat}/app_test.rb
RENAMED
@@ -108,7 +108,9 @@ context "Sinatra" do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
specify "renders a body with a redirect" do
|
111
|
-
|
111
|
+
helpers do
|
112
|
+
def foo ; 'blah' ; end
|
113
|
+
end
|
112
114
|
get "/" do
|
113
115
|
redirect 'foo', :foo
|
114
116
|
end
|
@@ -130,13 +132,10 @@ context "Sinatra" do
|
|
130
132
|
end
|
131
133
|
|
132
134
|
specify "stop sets content and ends event" do
|
133
|
-
|
134
|
-
Sinatra::EventContext.any_instance.expects(:foo).never
|
135
|
-
|
136
135
|
get '/set_body' do
|
137
136
|
stop 'Hello!'
|
138
137
|
stop 'World!'
|
139
|
-
|
138
|
+
fail 'stop should have halted'
|
140
139
|
end
|
141
140
|
|
142
141
|
get_it '/set_body'
|
@@ -146,8 +145,13 @@ context "Sinatra" do
|
|
146
145
|
|
147
146
|
end
|
148
147
|
|
149
|
-
|
150
|
-
|
148
|
+
# Deprecated. WTF was going on here? What's the 1 in [:foo, 1] do?
|
149
|
+
xspecify "should set status then call helper with a var" do
|
150
|
+
helpers do
|
151
|
+
def foo
|
152
|
+
'bah!'
|
153
|
+
end
|
154
|
+
end
|
151
155
|
|
152
156
|
get '/set_body' do
|
153
157
|
stop [404, [:foo, 1]]
|
@@ -252,8 +256,6 @@ context "Sinatra" do
|
|
252
256
|
assert_equal 'puted', body
|
253
257
|
end
|
254
258
|
|
255
|
-
# Some Ajax libraries downcase the _method parameter value. Make
|
256
|
-
# sure we can handle that.
|
257
259
|
specify "rewrites POSTs with lowercase _method param to PUT" do
|
258
260
|
put '/' do
|
259
261
|
'puted'
|
@@ -262,7 +264,6 @@ context "Sinatra" do
|
|
262
264
|
body.should.equal 'puted'
|
263
265
|
end
|
264
266
|
|
265
|
-
# Ignore any _method parameters specified in GET requests or on the query string in POST requests.
|
266
267
|
specify "does not rewrite GETs with _method param to PUT" do
|
267
268
|
get '/' do
|
268
269
|
'getted'
|
@@ -16,7 +16,8 @@ context "Looking up a request" do
|
|
16
16
|
Sinatra.application = nil
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
# Deprecated. The lookup method is no longer used.
|
20
|
+
xspecify "returns what's at the end" do
|
20
21
|
block = Proc.new { 'Hello' }
|
21
22
|
get '/', &block
|
22
23
|
|
@@ -31,7 +32,8 @@ context "Looking up a request" do
|
|
31
32
|
result.block.should.be block
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
# Deprecated. The lookup method is no longer used.
|
36
|
+
xspecify "takes params in path" do
|
35
37
|
block = Proc.new { 'Hello' }
|
36
38
|
get '/:foo', &block
|
37
39
|
|
@@ -83,7 +85,8 @@ context "An app returns" do
|
|
83
85
|
|
84
86
|
end
|
85
87
|
|
86
|
-
|
88
|
+
# Deprecated. The body method no longer halts.
|
89
|
+
xspecify "the body set if set before the last" do
|
87
90
|
|
88
91
|
get '/' do
|
89
92
|
body 'Blake'
|
@@ -96,6 +99,17 @@ context "An app returns" do
|
|
96
99
|
|
97
100
|
end
|
98
101
|
|
102
|
+
specify "404 if NotFound is raised" do
|
103
|
+
|
104
|
+
get '/' do
|
105
|
+
raise Sinatra::NotFound
|
106
|
+
end
|
107
|
+
|
108
|
+
get_it '/'
|
109
|
+
should.be.not_found
|
110
|
+
|
111
|
+
end
|
112
|
+
|
99
113
|
end
|
100
114
|
|
101
115
|
context "Application#configure blocks" do
|
@@ -131,14 +145,16 @@ end
|
|
131
145
|
|
132
146
|
context "Default Application Configuration" do
|
133
147
|
|
134
|
-
|
148
|
+
# Sinatra::ServerError is no longer used
|
149
|
+
xspecify "includes 404 and 500 error handlers" do
|
135
150
|
Sinatra.application.errors.should.include(Sinatra::ServerError)
|
136
151
|
Sinatra.application.errors[Sinatra::ServerError].should.not.be.nil
|
137
152
|
Sinatra.application.errors.should.include(Sinatra::NotFound)
|
138
153
|
Sinatra.application.errors[Sinatra::NotFound].should.not.be.nil
|
139
154
|
end
|
140
155
|
|
141
|
-
|
156
|
+
# Deprecated. No such thing as a Static event anymore.
|
157
|
+
xspecify "includes Static event" do
|
142
158
|
assert Sinatra.application.events[:get].any? { |e| Sinatra::Static === e }
|
143
159
|
end
|
144
160
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "Builder" 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
|
+
builder 'xml.instruct!'
|
19
|
+
end
|
20
|
+
|
21
|
+
get_it '/no_layout'
|
22
|
+
should.be.ok
|
23
|
+
body.should == %(<?xml version="1.0" encoding="UTF-8"?>\n)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should render inline block" do
|
28
|
+
|
29
|
+
get '/no_layout_and_inlined' do
|
30
|
+
@name = "Frank & Mary"
|
31
|
+
builder do |xml|
|
32
|
+
xml.couple @name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
get_it '/no_layout_and_inlined'
|
37
|
+
should.be.ok
|
38
|
+
body.should == %(<couple>Frank & Mary</couple>\n)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
context "Templates (in general)" do
|
47
|
+
|
48
|
+
setup do
|
49
|
+
Sinatra.application = nil
|
50
|
+
end
|
51
|
+
|
52
|
+
specify "are read from files if Symbols" do
|
53
|
+
|
54
|
+
get '/from_file' do
|
55
|
+
@name = 'Blue'
|
56
|
+
builder :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
57
|
+
end
|
58
|
+
|
59
|
+
get_it '/from_file'
|
60
|
+
should.be.ok
|
61
|
+
body.should.equal %(<exclaim>You rock Blue!</exclaim>\n)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
specify "use layout.ext by default if available" do
|
66
|
+
|
67
|
+
get '/' do
|
68
|
+
builder :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
69
|
+
end
|
70
|
+
|
71
|
+
get_it '/'
|
72
|
+
should.be.ok
|
73
|
+
body.should.equal "<layout>\n<this>is foo!</this>\n</layout>\n"
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
specify "renders without layout" do
|
78
|
+
|
79
|
+
get '/' do
|
80
|
+
builder :no_layout, :views_directory => File.dirname(__FILE__) + "/views/no_layout"
|
81
|
+
end
|
82
|
+
|
83
|
+
get_it '/'
|
84
|
+
should.be.ok
|
85
|
+
body.should.equal "<foo>No Layout!</foo>\n"
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
specify "raises error if template not found" do
|
90
|
+
|
91
|
+
get '/' do
|
92
|
+
builder :not_found
|
93
|
+
end
|
94
|
+
|
95
|
+
lambda { get_it '/' }.should.raise(Errno::ENOENT)
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
File without changes
|
data/compat/erb_test.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "Erb" 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
|
+
erb '<%= 1 + 1 %>'
|
19
|
+
end
|
20
|
+
|
21
|
+
get_it '/no_layout'
|
22
|
+
should.be.ok
|
23
|
+
body.should == '2'
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "should take an options hash with :locals set with a string" do
|
28
|
+
get '/locals' do
|
29
|
+
erb '<%= foo %>', :locals => {:foo => "Bar"}
|
30
|
+
end
|
31
|
+
|
32
|
+
get_it '/locals'
|
33
|
+
should.be.ok
|
34
|
+
body.should == 'Bar'
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "should take an options hash with :locals set with a complex object" do
|
38
|
+
get '/locals-complex' do
|
39
|
+
erb '<%= foo[0] %>', :locals => {:foo => ["foo", "bar", "baz"]}
|
40
|
+
end
|
41
|
+
|
42
|
+
get_it '/locals-complex'
|
43
|
+
should.be.ok
|
44
|
+
body.should == 'foo'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with layouts" do
|
49
|
+
|
50
|
+
setup do
|
51
|
+
Sinatra.application = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
specify "can be inline" do
|
55
|
+
|
56
|
+
layout do
|
57
|
+
%Q{This is <%= yield %>!}
|
58
|
+
end
|
59
|
+
|
60
|
+
get '/lay' do
|
61
|
+
erb 'Blake'
|
62
|
+
end
|
63
|
+
|
64
|
+
get_it '/lay'
|
65
|
+
should.be.ok
|
66
|
+
body.should.equal 'This is Blake!'
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
specify "can use named layouts" do
|
71
|
+
|
72
|
+
layout :pretty do
|
73
|
+
%Q{<h1><%= yield %></h1>}
|
74
|
+
end
|
75
|
+
|
76
|
+
get '/pretty' do
|
77
|
+
erb 'Foo', :layout => :pretty
|
78
|
+
end
|
79
|
+
|
80
|
+
get '/not_pretty' do
|
81
|
+
erb 'Bar'
|
82
|
+
end
|
83
|
+
|
84
|
+
get_it '/pretty'
|
85
|
+
body.should.equal '<h1>Foo</h1>'
|
86
|
+
|
87
|
+
get_it '/not_pretty'
|
88
|
+
body.should.equal 'Bar'
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
specify "can be read from a file if they're not inlined" do
|
93
|
+
|
94
|
+
get '/foo' do
|
95
|
+
@title = 'Welcome to the Hello Program'
|
96
|
+
erb 'Blake', :layout => :foo_layout,
|
97
|
+
:views_directory => File.dirname(__FILE__) + "/views"
|
98
|
+
end
|
99
|
+
|
100
|
+
get_it '/foo'
|
101
|
+
body.should.equal "Welcome to the Hello Program\nHi Blake\n"
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
context "Templates (in general)" do
|
108
|
+
|
109
|
+
specify "are read from files if Symbols" do
|
110
|
+
|
111
|
+
get '/from_file' do
|
112
|
+
@name = 'Alena'
|
113
|
+
erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
114
|
+
end
|
115
|
+
|
116
|
+
get_it '/from_file'
|
117
|
+
|
118
|
+
body.should.equal 'You rock Alena!'
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
specify "use layout.ext by default if available" do
|
123
|
+
|
124
|
+
get '/layout_from_file' do
|
125
|
+
erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
126
|
+
end
|
127
|
+
|
128
|
+
get_it '/layout_from_file'
|
129
|
+
should.be.ok
|
130
|
+
body.should.equal "x This is foo! x \n"
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
3
|
context "Simple Events" do
|
4
|
-
|
5
4
|
def simple_request_hash(method, path)
|
6
5
|
Rack::Request.new({
|
7
6
|
'REQUEST_METHOD' => method.to_s.upcase,
|
@@ -9,11 +8,21 @@ context "Simple Events" do
|
|
9
8
|
})
|
10
9
|
end
|
11
10
|
|
11
|
+
class MockResult < Struct.new(:block, :params)
|
12
|
+
end
|
13
|
+
|
12
14
|
def invoke_simple(path, request_path, &b)
|
13
|
-
|
14
|
-
|
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)
|
15
22
|
end
|
16
23
|
|
24
|
+
setup { Sinatra.application = nil }
|
25
|
+
|
17
26
|
specify "return last value" do
|
18
27
|
block = Proc.new { 'Simple' }
|
19
28
|
result = invoke_simple('/', '/', &block)
|
@@ -28,6 +37,7 @@ context "Simple Events" do
|
|
28
37
|
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
29
38
|
|
30
39
|
# unscapes
|
40
|
+
Sinatra.application = nil
|
31
41
|
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
|
32
42
|
result.should.not.be.nil
|
33
43
|
result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
|
@@ -38,14 +48,17 @@ context "Simple Events" do
|
|
38
48
|
result.should.not.be.nil
|
39
49
|
result.params.should.equal "foo" => 'a', "bar" => 'b'
|
40
50
|
|
51
|
+
Sinatra.application = nil
|
41
52
|
result = invoke_simple('/?:foo?/?:bar?', '/a/')
|
42
53
|
result.should.not.be.nil
|
43
54
|
result.params.should.equal "foo" => 'a', "bar" => nil
|
44
55
|
|
56
|
+
Sinatra.application = nil
|
45
57
|
result = invoke_simple('/?:foo?/?:bar?', '/a')
|
46
58
|
result.should.not.be.nil
|
47
59
|
result.params.should.equal "foo" => 'a', "bar" => nil
|
48
60
|
|
61
|
+
Sinatra.application = nil
|
49
62
|
result = invoke_simple('/:foo?/?:bar?', '/')
|
50
63
|
result.should.not.be.nil
|
51
64
|
result.params.should.equal "foo" => nil, "bar" => nil
|