rtomayko-sinatra 0.3.3 → 0.8.9

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.
Files changed (81) hide show
  1. data/AUTHORS +40 -0
  2. data/CHANGES +167 -0
  3. data/README.rdoc +104 -98
  4. data/Rakefile +27 -9
  5. data/{test → compat}/app_test.rb +11 -10
  6. data/{test → compat}/application_test.rb +10 -5
  7. data/compat/builder_test.rb +101 -0
  8. data/{test → compat}/custom_error_test.rb +0 -0
  9. data/compat/erb_test.rb +136 -0
  10. data/{test → compat}/events_test.rb +12 -2
  11. data/compat/filter_test.rb +30 -0
  12. data/compat/haml_test.rb +233 -0
  13. data/compat/helper.rb +21 -0
  14. data/compat/mapped_error_test.rb +72 -0
  15. data/{test → compat}/pipeline_test.rb +9 -4
  16. data/{test → compat}/public/foo.xml +0 -0
  17. data/compat/sass_test.rb +57 -0
  18. data/{test → compat}/sessions_test.rb +0 -0
  19. data/{test → compat}/streaming_test.rb +4 -1
  20. data/{test → compat}/sym_params_test.rb +0 -0
  21. data/{test → compat}/template_test.rb +0 -0
  22. data/{test → compat}/use_in_file_templates_test.rb +0 -0
  23. data/{test → compat}/views/foo.builder +0 -0
  24. data/{test → compat}/views/foo.erb +0 -0
  25. data/{test → compat}/views/foo.haml +0 -0
  26. data/{test → compat}/views/foo.sass +0 -0
  27. data/{test → compat}/views/foo_layout.erb +0 -0
  28. data/{test → compat}/views/foo_layout.haml +0 -0
  29. data/{test → compat}/views/layout_test/foo.builder +0 -0
  30. data/{test → compat}/views/layout_test/foo.erb +0 -0
  31. data/{test → compat}/views/layout_test/foo.haml +0 -0
  32. data/{test → compat}/views/layout_test/foo.sass +0 -0
  33. data/{test → compat}/views/layout_test/layout.builder +0 -0
  34. data/{test → compat}/views/layout_test/layout.erb +0 -0
  35. data/{test → compat}/views/layout_test/layout.haml +0 -0
  36. data/{test → compat}/views/layout_test/layout.sass +0 -0
  37. data/{test → compat}/views/no_layout/no_layout.builder +0 -0
  38. data/{test → compat}/views/no_layout/no_layout.haml +0 -0
  39. data/lib/sinatra/base.rb +818 -0
  40. data/lib/sinatra/compat.rb +239 -0
  41. data/{images → lib/sinatra/images}/404.png +0 -0
  42. data/{images → lib/sinatra/images}/500.png +0 -0
  43. data/lib/sinatra/main.rb +48 -0
  44. data/lib/sinatra/test/rspec.rb +1 -9
  45. data/lib/sinatra/test/spec.rb +1 -9
  46. data/lib/sinatra/test/unit.rb +3 -5
  47. data/lib/sinatra/test.rb +112 -0
  48. data/lib/sinatra.rb +3 -1486
  49. data/sinatra.gemspec +66 -36
  50. data/test/base_test.rb +72 -0
  51. data/test/builder_test.rb +56 -89
  52. data/test/data/reload_app_file.rb +3 -0
  53. data/test/erb_test.rb +44 -125
  54. data/test/filter_test.rb +29 -20
  55. data/test/haml_test.rb +57 -218
  56. data/test/helpers_test.rb +368 -0
  57. data/test/mapped_error_test.rb +141 -49
  58. data/test/middleware_test.rb +63 -0
  59. data/test/options_test.rb +103 -0
  60. data/test/reload_test.rb +65 -0
  61. data/test/request_test.rb +11 -0
  62. data/test/result_test.rb +92 -0
  63. data/test/routing_test.rb +338 -0
  64. data/test/sass_test.rb +33 -50
  65. data/test/sinatra_test.rb +15 -0
  66. data/test/static_test.rb +60 -0
  67. data/test/templates_test.rb +92 -0
  68. data/test/views/hello.builder +1 -0
  69. data/test/views/hello.erb +1 -0
  70. data/test/views/hello.haml +1 -0
  71. data/test/views/hello.sass +2 -0
  72. data/test/views/hello.test +1 -0
  73. data/test/views/layout2.builder +3 -0
  74. data/test/views/layout2.erb +2 -0
  75. data/test/views/layout2.haml +2 -0
  76. data/test/views/layout2.test +1 -0
  77. metadata +78 -48
  78. data/ChangeLog +0 -96
  79. data/lib/sinatra/test/methods.rb +0 -76
  80. data/test/event_context_test.rb +0 -15
  81. data/test/helper.rb +0 -9
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.3.3'
7
- s.date = "2008-11-02"
6
+ s.version = '0.8.9'
7
+ s.date = '2009-01-13'
8
8
 
9
9
  s.description = "Classy web-development dressed in a DSL"
10
10
  s.summary = "Classy web-development dressed in a DSL"
@@ -13,60 +13,90 @@ Gem::Specification.new do |s|
13
13
 
14
14
  # = MANIFEST =
15
15
  s.files = %w[
16
- ChangeLog
16
+ AUTHORS
17
+ CHANGES
17
18
  LICENSE
18
19
  README.rdoc
19
20
  Rakefile
20
- images/404.png
21
- images/500.png
21
+ compat/app_test.rb
22
+ compat/application_test.rb
23
+ compat/builder_test.rb
24
+ compat/custom_error_test.rb
25
+ compat/erb_test.rb
26
+ compat/events_test.rb
27
+ compat/filter_test.rb
28
+ compat/haml_test.rb
29
+ compat/helper.rb
30
+ compat/mapped_error_test.rb
31
+ compat/pipeline_test.rb
32
+ compat/public/foo.xml
33
+ compat/sass_test.rb
34
+ compat/sessions_test.rb
35
+ compat/streaming_test.rb
36
+ compat/sym_params_test.rb
37
+ compat/template_test.rb
38
+ compat/use_in_file_templates_test.rb
39
+ compat/views/foo.builder
40
+ compat/views/foo.erb
41
+ compat/views/foo.haml
42
+ compat/views/foo.sass
43
+ compat/views/foo_layout.erb
44
+ compat/views/foo_layout.haml
45
+ compat/views/layout_test/foo.builder
46
+ compat/views/layout_test/foo.erb
47
+ compat/views/layout_test/foo.haml
48
+ compat/views/layout_test/foo.sass
49
+ compat/views/layout_test/layout.builder
50
+ compat/views/layout_test/layout.erb
51
+ compat/views/layout_test/layout.haml
52
+ compat/views/layout_test/layout.sass
53
+ compat/views/no_layout/no_layout.builder
54
+ compat/views/no_layout/no_layout.haml
22
55
  lib/sinatra.rb
23
- lib/sinatra/test/methods.rb
56
+ lib/sinatra/base.rb
57
+ lib/sinatra/compat.rb
58
+ lib/sinatra/images/404.png
59
+ lib/sinatra/images/500.png
60
+ lib/sinatra/main.rb
61
+ lib/sinatra/test.rb
24
62
  lib/sinatra/test/rspec.rb
25
63
  lib/sinatra/test/spec.rb
26
64
  lib/sinatra/test/unit.rb
27
65
  sinatra.gemspec
28
- test/app_test.rb
29
- test/application_test.rb
66
+ test/base_test.rb
30
67
  test/builder_test.rb
31
- test/custom_error_test.rb
68
+ test/data/reload_app_file.rb
32
69
  test/erb_test.rb
33
- test/event_context_test.rb
34
- test/events_test.rb
35
70
  test/filter_test.rb
36
71
  test/haml_test.rb
37
- test/helper.rb
72
+ test/helpers_test.rb
38
73
  test/mapped_error_test.rb
39
- test/pipeline_test.rb
40
- test/public/foo.xml
74
+ test/middleware_test.rb
75
+ test/options_test.rb
76
+ test/reload_test.rb
77
+ test/request_test.rb
78
+ test/result_test.rb
79
+ test/routing_test.rb
41
80
  test/sass_test.rb
42
- test/sessions_test.rb
43
- test/streaming_test.rb
44
- test/sym_params_test.rb
45
- test/template_test.rb
46
- test/use_in_file_templates_test.rb
47
- test/views/foo.builder
48
- test/views/foo.erb
49
- test/views/foo.haml
50
- test/views/foo.sass
51
- test/views/foo_layout.erb
52
- test/views/foo_layout.haml
53
- test/views/layout_test/foo.builder
54
- test/views/layout_test/foo.erb
55
- test/views/layout_test/foo.haml
56
- test/views/layout_test/foo.sass
57
- test/views/layout_test/layout.builder
58
- test/views/layout_test/layout.erb
59
- test/views/layout_test/layout.haml
60
- test/views/layout_test/layout.sass
61
- test/views/no_layout/no_layout.builder
62
- test/views/no_layout/no_layout.haml
81
+ test/sinatra_test.rb
82
+ test/static_test.rb
83
+ test/templates_test.rb
84
+ test/views/hello.builder
85
+ test/views/hello.erb
86
+ test/views/hello.haml
87
+ test/views/hello.sass
88
+ test/views/hello.test
89
+ test/views/layout2.builder
90
+ test/views/layout2.erb
91
+ test/views/layout2.haml
92
+ test/views/layout2.test
63
93
  ]
64
94
  # = MANIFEST =
65
95
 
66
96
  s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
67
97
 
68
98
  s.extra_rdoc_files = %w[README.rdoc LICENSE]
69
- s.add_dependency 'rack', '~> 0.4.0'
99
+ s.add_dependency 'rack', '>= 0.9.0'
70
100
 
71
101
  s.has_rdoc = true
72
102
  s.homepage = "http://sinatra.rubyforge.org"
data/test/base_test.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
4
+
5
+ describe 'Sinatra::Base' do
6
+ include Sinatra::Test
7
+
8
+ it 'includes Rack::Utils' do
9
+ Sinatra::Base.should.include Rack::Utils
10
+ end
11
+
12
+ it 'can be used as a Rack application' do
13
+ mock_app {
14
+ get '/' do
15
+ 'Hello World'
16
+ end
17
+ }
18
+ @app.should.respond_to :call
19
+
20
+ request = Rack::MockRequest.new(@app)
21
+ response = request.get('/')
22
+ response.should.be.ok
23
+ response.body.should.equal 'Hello World'
24
+ end
25
+
26
+ it 'can be used as Rack middleware' do
27
+ app = lambda { |env| [200, {}, ['Goodbye World']] }
28
+ mock_middleware =
29
+ mock_app {
30
+ get '/' do
31
+ 'Hello World'
32
+ end
33
+ get '/goodbye' do
34
+ @app.call(request.env)
35
+ end
36
+ }
37
+ middleware = mock_middleware.new(app)
38
+ middleware.app.should.be app
39
+
40
+ request = Rack::MockRequest.new(middleware)
41
+ response = request.get('/')
42
+ response.should.be.ok
43
+ response.body.should.equal 'Hello World'
44
+
45
+ response = request.get('/goodbye')
46
+ response.should.be.ok
47
+ response.body.should.equal 'Goodbye World'
48
+ end
49
+
50
+ it 'can take multiple definitions of a route' do
51
+ app = mock_app {
52
+ user_agent(/Foo/)
53
+ get '/foo' do
54
+ 'foo'
55
+ end
56
+
57
+ get '/foo' do
58
+ 'not foo'
59
+ end
60
+ }
61
+
62
+ request = Rack::MockRequest.new(app)
63
+ response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
64
+ response.should.be.ok
65
+ response.body.should.equal 'foo'
66
+
67
+ request = Rack::MockRequest.new(app)
68
+ response = request.get('/foo')
69
+ response.should.be.ok
70
+ response.body.should.equal 'not foo'
71
+ end
72
+ end
data/test/builder_test.rb CHANGED
@@ -1,101 +1,68 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- context "Builder" do
4
-
5
- setup do
6
- Sinatra.application = nil
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
4
+
5
+ describe "Builder Templates" do
6
+ include Sinatra::Test
7
+
8
+ def builder_app(&block)
9
+ mock_app {
10
+ set :views, File.dirname(__FILE__) + '/views'
11
+ get '/', &block
12
+ }
13
+ get '/'
7
14
  end
8
15
 
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 &amp; Mary</couple>\n)
39
-
40
- end
41
-
16
+ it 'renders inline Builder strings' do
17
+ builder_app { builder 'xml.instruct!' }
18
+ should.be.ok
19
+ body.should.equal %{<?xml version="1.0" encoding="UTF-8"?>\n}
42
20
  end
43
21
 
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"
22
+ it 'renders inline blocks' do
23
+ builder_app {
24
+ @name = "Frank & Mary"
25
+ builder do |xml|
26
+ xml.couple @name
57
27
  end
28
+ }
29
+ should.be.ok
30
+ body.should.equal "<couple>Frank &amp; Mary</couple>\n"
31
+ end
58
32
 
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
33
+ it 'renders .builder files in views path' do
34
+ builder_app {
35
+ @name = "Blue"
36
+ builder :hello
37
+ }
38
+ should.be.ok
39
+ body.should.equal %(<exclaim>You're my boy, Blue!</exclaim>\n)
40
+ end
90
41
 
91
- get '/' do
92
- builder :not_found
42
+ it "renders with inline layouts" do
43
+ mock_app {
44
+ layout do
45
+ %(xml.layout { xml << yield })
93
46
  end
47
+ get('/') { builder %(xml.em 'Hello World') }
48
+ }
49
+ get '/'
50
+ should.be.ok
51
+ body.should.equal "<layout>\n<em>Hello World</em>\n</layout>\n"
52
+ end
94
53
 
95
- lambda { get_it '/' }.should.raise(Errno::ENOENT)
96
-
97
- end
98
-
54
+ it "renders with file layouts" do
55
+ builder_app {
56
+ builder %(xml.em 'Hello World'), :layout => :layout2
57
+ }
58
+ should.be.ok
59
+ body.should.equal "<layout>\n<em>Hello World</em>\n</layout>\n"
99
60
  end
100
61
 
62
+ it "raises error if template not found" do
63
+ mock_app {
64
+ get('/') { builder :no_such_template }
65
+ }
66
+ lambda { get('/') }.should.raise(Errno::ENOENT)
67
+ end
101
68
  end
@@ -0,0 +1,3 @@
1
+ $reload_count += 1
2
+
3
+ $reload_app.get('/') { 'Hello from reload file' }
data/test/erb_test.rb CHANGED
@@ -1,136 +1,55 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- context "Erb" do
4
-
5
- setup do
6
- Sinatra.application = nil
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
4
+
5
+ describe "ERB Templates" do
6
+ include Sinatra::Test
7
+
8
+ def erb_app(&block)
9
+ mock_app {
10
+ set :views, File.dirname(__FILE__) + '/views'
11
+ get '/', &block
12
+ }
13
+ get '/'
7
14
  end
8
15
 
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
16
+ it 'renders inline ERB strings' do
17
+ erb_app { erb '<%= 1 + 1 %>' }
18
+ should.be.ok
19
+ body.should.equal '2'
46
20
  end
47
21
 
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
-
22
+ it 'renders .erb files in views path' do
23
+ erb_app { erb :hello }
24
+ should.be.ok
25
+ body.should.equal "Hello World\n"
105
26
  end
106
27
 
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"
28
+ it 'takes a :locals option' do
29
+ erb_app {
30
+ locals = {:foo => 'Bar'}
31
+ erb '<%= foo %>', :locals => locals
32
+ }
33
+ should.be.ok
34
+ body.should.equal 'Bar'
35
+ end
131
36
 
132
- end
37
+ it "renders with inline layouts" do
38
+ mock_app {
39
+ layout { 'THIS. IS. <%= yield.upcase %>!' }
40
+ get('/') { erb 'Sparta' }
41
+ }
42
+ get '/'
43
+ should.be.ok
44
+ body.should.equal 'THIS. IS. SPARTA!'
45
+ end
133
46
 
47
+ it "renders with file layouts" do
48
+ erb_app {
49
+ erb 'Hello World', :layout => :layout2
50
+ }
51
+ should.be.ok
52
+ body.should.equal "ERB Layout!\nHello World\n"
134
53
  end
135
54
 
136
55
  end
data/test/filter_test.rb CHANGED
@@ -1,30 +1,39 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
- context "before filters" do
5
+ describe "Filters" do
6
+ include Sinatra::Test
4
7
 
5
- setup do
6
- Sinatra.application = nil
7
- @app = Sinatra.application
8
- end
8
+ it "executes filters in the order defined" do
9
+ count = 0
10
+ mock_app do
11
+ get('/') { 'Hello World' }
12
+ before {
13
+ count.should.be 0
14
+ count = 1
15
+ }
16
+ before {
17
+ count.should.be 1
18
+ count = 2
19
+ }
20
+ end
9
21
 
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 '/'
22
+ get '/'
16
23
  should.be.ok
17
- body.should.be == 'Hello World'
18
- invoked.should.be == 0x03
24
+ count.should.be 2
25
+ body.should.equal 'Hello World'
19
26
  end
20
27
 
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'
28
+ it "allows filters to modify the request" do
29
+ mock_app {
30
+ get('/foo') { 'foo' }
31
+ get('/bar') { 'bar' }
32
+ before { request.path_info = '/bar' }
33
+ }
34
+
35
+ get '/foo'
26
36
  should.be.ok
27
37
  body.should.be == 'bar'
28
38
  end
29
-
30
39
  end