rtomayko-sinatra 0.9.0 → 0.9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +40 -0
- data/CHANGES +189 -0
- data/README.rdoc +142 -95
- data/Rakefile +14 -49
- data/compat/events_test.rb +10 -7
- data/compat/helper.rb +13 -1
- data/lib/sinatra.rb +5 -0
- data/lib/sinatra/base.rb +138 -47
- data/lib/sinatra/compat.rb +142 -44
- data/lib/sinatra/test.rb +92 -91
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +9 -0
- data/lib/sinatra/test/spec.rb +7 -0
- data/lib/sinatra/test/unit.rb +2 -2
- data/sinatra.gemspec +8 -5
- data/test/base_test.rb +33 -14
- data/test/builder_test.rb +12 -16
- data/test/erb_test.rb +11 -16
- data/test/filter_test.rb +48 -12
- data/test/haml_test.rb +14 -18
- data/test/helper.rb +25 -0
- data/test/helpers_test.rb +55 -62
- data/test/mapped_error_test.rb +43 -24
- data/test/middleware_test.rb +8 -13
- data/test/options_test.rb +29 -35
- data/test/reload_test.rb +16 -20
- data/test/request_test.rb +12 -5
- data/test/result_test.rb +16 -20
- data/test/routing_test.rb +150 -64
- data/test/sass_test.rb +8 -12
- data/test/sinatra_test.rb +2 -4
- data/test/static_test.rb +16 -19
- data/test/templates_test.rb +23 -19
- metadata +8 -6
- data/ChangeLog +0 -96
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bacon'
|
2
|
+
require 'sinatra/test'
|
3
|
+
|
4
|
+
Sinatra::Default.set(
|
5
|
+
:environment => :test,
|
6
|
+
:run => false,
|
7
|
+
:raise_errors => true,
|
8
|
+
:logging => false
|
9
|
+
)
|
10
|
+
|
11
|
+
module Sinatra::Test
|
12
|
+
def should
|
13
|
+
@response.should
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Bacon::Context.send(:include, Sinatra::Test)
|
data/lib/sinatra/test/rspec.rb
CHANGED
data/lib/sinatra/test/spec.rb
CHANGED
data/lib/sinatra/test/unit.rb
CHANGED
data/sinatra.gemspec
CHANGED
@@ -3,17 +3,19 @@ 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.0'
|
7
|
-
s.date = '2009-01-
|
6
|
+
s.version = '0.9.0.2'
|
7
|
+
s.date = '2009-01-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"
|
11
11
|
|
12
12
|
s.authors = ["Blake Mizerany"]
|
13
|
+
s.email = "sinatrarb@googlegroups.com"
|
13
14
|
|
14
15
|
# = MANIFEST =
|
15
16
|
s.files = %w[
|
16
|
-
|
17
|
+
AUTHORS
|
18
|
+
CHANGES
|
17
19
|
LICENSE
|
18
20
|
README.rdoc
|
19
21
|
Rakefile
|
@@ -57,8 +59,8 @@ Gem::Specification.new do |s|
|
|
57
59
|
lib/sinatra/images/404.png
|
58
60
|
lib/sinatra/images/500.png
|
59
61
|
lib/sinatra/main.rb
|
60
|
-
lib/sinatra/rack/methodoverride.rb
|
61
62
|
lib/sinatra/test.rb
|
63
|
+
lib/sinatra/test/bacon.rb
|
62
64
|
lib/sinatra/test/rspec.rb
|
63
65
|
lib/sinatra/test/spec.rb
|
64
66
|
lib/sinatra/test/unit.rb
|
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
|
|
69
71
|
test/erb_test.rb
|
70
72
|
test/filter_test.rb
|
71
73
|
test/haml_test.rb
|
74
|
+
test/helper.rb
|
72
75
|
test/helpers_test.rb
|
73
76
|
test/mapped_error_test.rb
|
74
77
|
test/middleware_test.rb
|
@@ -96,7 +99,7 @@ Gem::Specification.new do |s|
|
|
96
99
|
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
97
100
|
|
98
101
|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
99
|
-
s.add_dependency 'rack', '>= 0.9.
|
102
|
+
s.add_dependency 'rack', '>= 0.9.1'
|
100
103
|
|
101
104
|
s.has_rdoc = true
|
102
105
|
s.homepage = "http://sinatra.rubyforge.org"
|
data/test/base_test.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe 'Sinatra::Base' do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
it 'includes Rack::Utils' do
|
9
|
-
Sinatra::Base.
|
5
|
+
assert Sinatra::Base.included_modules.include?(Rack::Utils)
|
10
6
|
end
|
11
7
|
|
12
8
|
it 'can be used as a Rack application' do
|
@@ -15,12 +11,12 @@ describe 'Sinatra::Base' do
|
|
15
11
|
'Hello World'
|
16
12
|
end
|
17
13
|
}
|
18
|
-
@app.
|
14
|
+
assert @app.respond_to?(:call)
|
19
15
|
|
20
16
|
request = Rack::MockRequest.new(@app)
|
21
17
|
response = request.get('/')
|
22
|
-
response.
|
23
|
-
|
18
|
+
assert response.ok?
|
19
|
+
assert_equal 'Hello World', response.body
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'can be used as Rack middleware' do
|
@@ -35,15 +31,38 @@ describe 'Sinatra::Base' do
|
|
35
31
|
end
|
36
32
|
}
|
37
33
|
middleware = mock_middleware.new(app)
|
38
|
-
middleware.app
|
34
|
+
assert_same app, middleware.app
|
39
35
|
|
40
36
|
request = Rack::MockRequest.new(middleware)
|
41
37
|
response = request.get('/')
|
42
|
-
response.
|
43
|
-
|
38
|
+
assert response.ok?
|
39
|
+
assert_equal 'Hello World', response.body
|
44
40
|
|
45
41
|
response = request.get('/goodbye')
|
46
|
-
response.
|
47
|
-
|
42
|
+
assert response.ok?
|
43
|
+
assert_equal 'Goodbye World', response.body
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can take multiple definitions of a route' do
|
47
|
+
app = mock_app {
|
48
|
+
user_agent(/Foo/)
|
49
|
+
get '/foo' do
|
50
|
+
'foo'
|
51
|
+
end
|
52
|
+
|
53
|
+
get '/foo' do
|
54
|
+
'not foo'
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
request = Rack::MockRequest.new(app)
|
59
|
+
response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
|
60
|
+
assert response.ok?
|
61
|
+
assert_equal 'foo', response.body
|
62
|
+
|
63
|
+
request = Rack::MockRequest.new(app)
|
64
|
+
response = request.get('/foo')
|
65
|
+
assert response.ok?
|
66
|
+
assert_equal 'not foo', response.body
|
48
67
|
end
|
49
68
|
end
|
data/test/builder_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "Builder Templates" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
def builder_app(&block)
|
9
5
|
mock_app {
|
10
6
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -15,8 +11,8 @@ describe "Builder Templates" do
|
|
15
11
|
|
16
12
|
it 'renders inline Builder strings' do
|
17
13
|
builder_app { builder 'xml.instruct!' }
|
18
|
-
|
19
|
-
|
14
|
+
assert ok?
|
15
|
+
assert_equal %{<?xml version="1.0" encoding="UTF-8"?>\n}, body
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'renders inline blocks' do
|
@@ -26,8 +22,8 @@ describe "Builder Templates" do
|
|
26
22
|
xml.couple @name
|
27
23
|
end
|
28
24
|
}
|
29
|
-
|
30
|
-
|
25
|
+
assert ok?
|
26
|
+
assert_equal "<couple>Frank & Mary</couple>\n", body
|
31
27
|
end
|
32
28
|
|
33
29
|
it 'renders .builder files in views path' do
|
@@ -35,8 +31,8 @@ describe "Builder Templates" do
|
|
35
31
|
@name = "Blue"
|
36
32
|
builder :hello
|
37
33
|
}
|
38
|
-
|
39
|
-
|
34
|
+
assert ok?
|
35
|
+
assert_equal %(<exclaim>You're my boy, Blue!</exclaim>\n), body
|
40
36
|
end
|
41
37
|
|
42
38
|
it "renders with inline layouts" do
|
@@ -47,22 +43,22 @@ describe "Builder Templates" do
|
|
47
43
|
get('/') { builder %(xml.em 'Hello World') }
|
48
44
|
}
|
49
45
|
get '/'
|
50
|
-
|
51
|
-
|
46
|
+
assert ok?
|
47
|
+
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
52
48
|
end
|
53
49
|
|
54
50
|
it "renders with file layouts" do
|
55
51
|
builder_app {
|
56
52
|
builder %(xml.em 'Hello World'), :layout => :layout2
|
57
53
|
}
|
58
|
-
|
59
|
-
|
54
|
+
assert ok?
|
55
|
+
assert_equal "<layout>\n<em>Hello World</em>\n</layout>\n", body
|
60
56
|
end
|
61
57
|
|
62
58
|
it "raises error if template not found" do
|
63
59
|
mock_app {
|
64
60
|
get('/') { builder :no_such_template }
|
65
61
|
}
|
66
|
-
|
62
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
67
63
|
end
|
68
64
|
end
|
data/test/erb_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "ERB Templates" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
def erb_app(&block)
|
9
5
|
mock_app {
|
10
6
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -15,14 +11,14 @@ describe "ERB Templates" do
|
|
15
11
|
|
16
12
|
it 'renders inline ERB strings' do
|
17
13
|
erb_app { erb '<%= 1 + 1 %>' }
|
18
|
-
|
19
|
-
|
14
|
+
assert ok?
|
15
|
+
assert_equal '2', body
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'renders .erb files in views path' do
|
23
19
|
erb_app { erb :hello }
|
24
|
-
|
25
|
-
|
20
|
+
assert ok?
|
21
|
+
assert_equal "Hello World\n", body
|
26
22
|
end
|
27
23
|
|
28
24
|
it 'takes a :locals option' do
|
@@ -30,8 +26,8 @@ describe "ERB Templates" do
|
|
30
26
|
locals = {:foo => 'Bar'}
|
31
27
|
erb '<%= foo %>', :locals => locals
|
32
28
|
}
|
33
|
-
|
34
|
-
|
29
|
+
assert ok?
|
30
|
+
assert_equal 'Bar', body
|
35
31
|
end
|
36
32
|
|
37
33
|
it "renders with inline layouts" do
|
@@ -40,16 +36,15 @@ describe "ERB Templates" do
|
|
40
36
|
get('/') { erb 'Sparta' }
|
41
37
|
}
|
42
38
|
get '/'
|
43
|
-
|
44
|
-
|
39
|
+
assert ok?
|
40
|
+
assert_equal 'THIS. IS. SPARTA!', body
|
45
41
|
end
|
46
42
|
|
47
43
|
it "renders with file layouts" do
|
48
44
|
erb_app {
|
49
45
|
erb 'Hello World', :layout => :layout2
|
50
46
|
}
|
51
|
-
|
52
|
-
|
47
|
+
assert ok?
|
48
|
+
assert_equal "ERB Layout!\nHello World\n", body
|
53
49
|
end
|
54
|
-
|
55
50
|
end
|
data/test/filter_test.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "Filters" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
it "executes filters in the order defined" do
|
9
5
|
count = 0
|
10
6
|
mock_app do
|
11
7
|
get('/') { 'Hello World' }
|
12
8
|
before {
|
13
|
-
|
9
|
+
assert_equal 0, count
|
14
10
|
count = 1
|
15
11
|
}
|
16
12
|
before {
|
17
|
-
|
13
|
+
assert_equal 1, count
|
18
14
|
count = 2
|
19
15
|
}
|
20
16
|
end
|
21
17
|
|
22
18
|
get '/'
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
assert ok?
|
20
|
+
assert_equal 2, count
|
21
|
+
assert_equal 'Hello World', body
|
26
22
|
end
|
27
23
|
|
28
24
|
it "allows filters to modify the request" do
|
@@ -33,7 +29,47 @@ describe "Filters" do
|
|
33
29
|
}
|
34
30
|
|
35
31
|
get '/foo'
|
36
|
-
|
37
|
-
|
32
|
+
assert ok?
|
33
|
+
assert_equal 'bar', body
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can modify instance variables available to routes" do
|
37
|
+
mock_app {
|
38
|
+
before { @foo = 'bar' }
|
39
|
+
get('/foo') { @foo }
|
40
|
+
}
|
41
|
+
|
42
|
+
get '/foo'
|
43
|
+
assert ok?
|
44
|
+
assert_equal 'bar', body
|
45
|
+
end
|
46
|
+
|
47
|
+
it "allows redirects in filters" do
|
48
|
+
mock_app {
|
49
|
+
before { redirect '/bar' }
|
50
|
+
get('/foo') do
|
51
|
+
fail 'before block should have halted processing'
|
52
|
+
'ORLY?!'
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
get '/foo'
|
57
|
+
assert redirect?
|
58
|
+
assert_equal '/bar', response['Location']
|
59
|
+
assert_equal '', body
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does not modify the response with its return value" do
|
63
|
+
mock_app {
|
64
|
+
before { 'Hello World!' }
|
65
|
+
get '/foo' do
|
66
|
+
assert_equal [], response.body
|
67
|
+
'cool'
|
68
|
+
end
|
69
|
+
}
|
70
|
+
|
71
|
+
get '/foo'
|
72
|
+
assert ok?
|
73
|
+
assert_equal 'cool', body
|
38
74
|
end
|
39
75
|
end
|
data/test/haml_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "HAML Templates" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
def haml_app(&block)
|
9
5
|
mock_app {
|
10
6
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -15,14 +11,14 @@ describe "HAML Templates" do
|
|
15
11
|
|
16
12
|
it 'renders inline HAML strings' do
|
17
13
|
haml_app { haml '%h1 Hiya' }
|
18
|
-
|
19
|
-
|
14
|
+
assert ok?
|
15
|
+
assert_equal "<h1>Hiya</h1>\n", body
|
20
16
|
end
|
21
17
|
|
22
18
|
it 'renders .haml files in views path' do
|
23
19
|
haml_app { haml :hello }
|
24
|
-
|
25
|
-
|
20
|
+
assert ok?
|
21
|
+
assert_equal "<h1>Hello From Haml</h1>\n", body
|
26
22
|
end
|
27
23
|
|
28
24
|
it "renders with inline layouts" do
|
@@ -31,31 +27,31 @@ describe "HAML Templates" do
|
|
31
27
|
get('/') { haml '%em Sparta' }
|
32
28
|
}
|
33
29
|
get '/'
|
34
|
-
|
35
|
-
|
30
|
+
assert ok?
|
31
|
+
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
|
36
32
|
end
|
37
33
|
|
38
34
|
it "renders with file layouts" do
|
39
35
|
haml_app {
|
40
36
|
haml 'Hello World', :layout => :layout2
|
41
37
|
}
|
42
|
-
|
43
|
-
|
38
|
+
assert ok?
|
39
|
+
assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
|
44
40
|
end
|
45
41
|
|
46
42
|
it "raises error if template not found" do
|
47
43
|
mock_app {
|
48
44
|
get('/') { haml :no_such_template }
|
49
45
|
}
|
50
|
-
|
46
|
+
assert_raise(Errno::ENOENT) { get('/') }
|
51
47
|
end
|
52
48
|
|
53
49
|
it "passes HAML options to the Haml engine" do
|
54
50
|
haml_app {
|
55
51
|
haml "!!!\n%h1 Hello World", :options => {:format => :html5}
|
56
52
|
}
|
57
|
-
|
58
|
-
|
53
|
+
assert ok?
|
54
|
+
assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
|
59
55
|
end
|
60
56
|
|
61
57
|
it "passes default HAML options to the Haml engine" do
|
@@ -66,7 +62,7 @@ describe "HAML Templates" do
|
|
66
62
|
end
|
67
63
|
}
|
68
64
|
get '/'
|
69
|
-
|
70
|
-
|
65
|
+
assert ok?
|
66
|
+
assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
|
71
67
|
end
|
72
68
|
end
|