public
Fork of bmizerany/sinatra
Description: Classy web-development dressed in a DSL
Homepage: http://sinatrarb.com
Clone URL: git://github.com/nicksieger/sinatra.git
FIX:  sloppy.  run setup! for tests!
Blake Mizerany (author)
Sun Feb 24 18:30:04 -0800 2008
commit  59199dcc13ea171c70eb042486b10d11b4b69045
tree    3d95511ca484adef3a867914e6528511bcf0565a
parent  5a61c3be45076cfe066df404bcd9316dc5420232
...
34
35
36
37
 
 
 
 
 
38
39
40
...
780
781
782
783
784
785
786
...
34
35
36
 
37
38
39
40
41
42
43
44
...
784
785
786
 
787
788
789
0
@@ -34,7 +34,11 @@ module Sinatra
0
   Result = Struct.new(:block, :params, :status) unless defined?(Result)
0
   
0
   def application
0
- @app ||= Application.new
0
+ unless @app
0
+ @app = Application.new
0
+ Sinatra::Environment.setup!
0
+ end
0
+ @app
0
   end
0
   
0
   def application=(app)
0
@@ -780,7 +784,6 @@ end
0
 at_exit do
0
   raise $! if $!
0
   if Sinatra.application.options.run
0
- Sinatra::Environment.setup!
0
     Sinatra.run
0
   end
0
 end
...
1
2
 
 
 
 
 
 
 
 
3
4
5
6
 
7
8
9
10
11
12
13
 
 
 
14
15
16
...
21
22
23
24
 
25
26
 
27
28
29
...
38
39
40
41
 
42
43
44
45
46
47
48
 
 
 
49
50
51
52
 
53
54
55
56
57
58
59
 
 
 
60
61
62
63
64
65
66
67
68
69
70
71
72
 
73
74
75
76
77
78
79
80
 
 
 
 
81
82
83
84
85
 
86
87
88
89
90
91
92
93
94
 
 
 
 
95
96
97
...
99
100
101
102
 
103
104
105
106
 
107
108
109
110
111
112
 
113
114
115
116
117
118
119
 
 
 
120
121
122
123
 
124
125
126
127
128
129
130
 
 
 
131
132
133
134
135
 
136
137
138
139
140
141
142
 
 
 
143
144
145
146
 
 
147
148
149
...
1
2
3
4
5
6
7
8
9
10
11
12
13
 
14
15
16
17
18
 
 
 
19
20
21
22
23
24
...
29
30
31
 
32
33
 
34
35
36
37
...
46
47
48
 
49
50
51
52
53
 
 
 
54
55
56
57
58
59
 
60
61
62
 
 
 
 
 
63
64
65
66
67
68
69
 
 
 
 
 
 
 
 
 
70
71
72
73
 
 
 
 
 
74
75
76
77
78
79
80
81
 
82
83
84
85
86
 
 
 
 
 
87
88
89
90
91
92
93
...
95
96
97
 
98
99
100
101
 
102
103
104
105
106
107
 
108
109
110
111
 
 
 
 
112
113
114
115
116
117
 
118
119
120
121
 
 
 
 
122
123
124
125
126
127
128
 
129
130
131
132
 
 
 
 
133
134
135
136
 
 
 
137
138
139
140
141
0
@@ -1,16 +1,24 @@
0
 require File.dirname(__FILE__) + '/helper'
0
 
0
+class TesterWithEach
0
+ def each
0
+ yield 'foo'
0
+ yield 'bar'
0
+ yield 'baz'
0
+ end
0
+end
0
+
0
 context "Looking up a request" do
0
 
0
   setup do
0
- @app = Sinatra::Application.new
0
+ Sinatra.application = nil
0
   end
0
 
0
   specify "returns what's at the end" do
0
     block = Proc.new { 'Hello' }
0
- @app.define_event(:get, '/', &block)
0
-
0
- result = @app.lookup(
0
+ get '/', &block
0
+
0
+ result = Sinatra.application.lookup(
0
       'REQUEST_METHOD' => 'GET',
0
       'PATH_INFO' => '/'
0
     )
0
@@ -21,9 +29,9 @@ context "Looking up a request" do
0
   
0
   specify "takes params in path" do
0
     block = Proc.new { 'Hello' }
0
- @app.define_event(:get, '/:foo', &block)
0
+ get '/:foo', &block
0
     
0
- result = @app.lookup(
0
+ result = Sinatra.application.lookup(
0
       'REQUEST_METHOD' => 'GET',
0
       'PATH_INFO' => '/bar'
0
     )
0
@@ -38,60 +46,48 @@ end
0
 context "An app returns" do
0
   
0
   setup do
0
- @app = Sinatra::Application.new
0
+ Sinatra.application = nil
0
   end
0
     
0
   specify "404 if no events found" do
0
     request = Rack::MockRequest.new(@app)
0
- result = request.get('/')
0
- result.should.be.not_found
0
- result.body.should.equal '<h1>Not Found</h1>'
0
+ get_it '/'
0
+ should.be.not_found
0
+ body.should.equal '<h1>Not Found</h1>'
0
   end
0
   
0
   specify "200 if success" do
0
- @app.define_event(:get, '/') do
0
+ get '/' do
0
       'Hello World'
0
     end
0
-
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/')
0
- result.should.be.ok
0
- result.body.should.equal 'Hello World'
0
+ get_it '/'
0
+ should.be.ok
0
+ body.should.equal 'Hello World'
0
   end
0
   
0
   specify "an objects result from each if it has it" do
0
     
0
- class TesterWithEach
0
- def each
0
- yield 'foo'
0
- yield 'bar'
0
- yield 'baz'
0
- end
0
- end
0
-
0
- @app.define_event(:get, '/') do
0
+ get '/' do
0
       TesterWithEach.new
0
     end
0
     
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/')
0
- result.should.be.ok
0
- result.body.should.equal 'foobarbaz'
0
-
0
+ get_it '/'
0
+ should.be.ok
0
+ body.should.equal 'foobarbaz'
0
+
0
   end
0
   
0
   specify "the body set if set before the last" do
0
         
0
- @app.define_event(:get, '/') do
0
+ get '/' do
0
       body 'Blake'
0
       'Mizerany'
0
     end
0
     
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/')
0
- result.should.be.ok
0
- result.body.should.equal 'Blake'
0
-
0
+ get_it '/'
0
+ should.be.ok
0
+ body.should.equal 'Blake'
0
+
0
   end
0
   
0
 end
0
@@ -99,51 +95,47 @@ end
0
 context "Events in an app" do
0
   
0
   setup do
0
- @app = Sinatra::Application.new
0
+ Sinatra.application = nil
0
   end
0
   
0
   specify "evaluate in a clean context" do
0
- Sinatra::EventContext.class_eval do
0
+ helpers do
0
       def foo
0
         'foo'
0
       end
0
     end
0
     
0
- @app.define_event(:get, '/foo') do
0
+ get '/foo' do
0
       foo
0
     end
0
     
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/foo')
0
- result.should.be.ok
0
- result.body.should.equal 'foo'
0
+ get_it '/foo'
0
+ should.be.ok
0
+ body.should.equal 'foo'
0
   end
0
   
0
   specify "get access to request, response, and params" do
0
- @app.define_event(:get, '/:foo') do
0
+ get '/:foo' do
0
       params[:foo] + params[:bar]
0
     end
0
     
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/foo?bar=baz')
0
- result.should.be.ok
0
- result.body.should.equal 'foobaz'
0
+ get_it '/foo?bar=baz'
0
+ should.be.ok
0
+ body.should.equal 'foobaz'
0
   end
0
   
0
   specify "can filters by agent" do
0
     
0
- @app.define_event(:get, '/', :agent => /Windows/) do
0
+ get '/', :agent => /Windows/ do
0
       request.env['HTTP_USER_AGENT']
0
     end
0
     
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/', :agent => 'Windows')
0
- result.should.be.ok
0
- result.body.should.equal 'Windows'
0
+ get_it '/', :agent => 'Windows'
0
+ should.be.ok
0
+ body.should.equal 'Windows'
0
 
0
- request = Rack::MockRequest.new(@app)
0
- result = request.get('/', :agent => 'Mac')
0
- result.should.not.be.ok
0
+ get_it '/', :agent => 'Mac'
0
+ should.not.be.ok
0
 
0
   end
0
   

Comments

    No one has commented yet.