strelka 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ChangeLog +156 -9
- data/History.rdoc +15 -0
- data/IDEAS.rdoc +17 -1
- data/MILESTONES.rdoc +1 -1
- data/Manifest.txt +10 -2
- data/Plugins.rdoc +4 -4
- data/README.rdoc +3 -3
- data/Rakefile +5 -4
- data/bin/strelka +19 -10
- data/contrib/hoetemplate/data/project/apps/file_name_app +1 -0
- data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
- data/examples/apps/hello-world +1 -0
- data/examples/apps/ws-chat +69 -0
- data/examples/apps/ws-echo +61 -0
- data/examples/gen-config.rb +6 -5
- data/lib/strelka/app/auth.rb +2 -2
- data/lib/strelka/app/errors.rb +1 -1
- data/lib/strelka/app/filters.rb +3 -2
- data/lib/strelka/app/negotiation.rb +2 -2
- data/lib/strelka/app/parameters.rb +1 -2
- data/lib/strelka/app/restresources.rb +3 -2
- data/lib/strelka/app/routing.rb +1 -1
- data/lib/strelka/app/sessions.rb +2 -2
- data/lib/strelka/app/templating.rb +7 -3
- data/lib/strelka/app.rb +5 -145
- data/lib/strelka/behavior/plugin.rb +4 -4
- data/lib/strelka/discovery.rb +211 -0
- data/lib/strelka/httprequest.rb +1 -0
- data/lib/strelka/httpresponse/negotiation.rb +7 -1
- data/lib/strelka/mixins.rb +4 -1
- data/lib/strelka/paramvalidator.rb +1 -1
- data/lib/strelka/plugins.rb +8 -6
- data/lib/strelka/websocketserver/routing.rb +116 -0
- data/lib/strelka/websocketserver.rb +147 -0
- data/lib/strelka.rb +5 -4
- data/spec/{lib/constants.rb → constants.rb} +3 -2
- data/spec/{lib/helpers.rb → helpers.rb} +15 -14
- data/spec/strelka/app/auth_spec.rb +145 -142
- data/spec/strelka/app/errors_spec.rb +20 -26
- data/spec/strelka/app/filters_spec.rb +67 -54
- data/spec/strelka/app/negotiation_spec.rb +8 -14
- data/spec/strelka/app/parameters_spec.rb +23 -29
- data/spec/strelka/app/restresources_spec.rb +98 -100
- data/spec/strelka/app/routing_spec.rb +57 -57
- data/spec/strelka/app/sessions_spec.rb +11 -17
- data/spec/strelka/app/templating_spec.rb +36 -40
- data/spec/strelka/app_spec.rb +48 -147
- data/spec/strelka/authprovider/basic_spec.rb +5 -11
- data/spec/strelka/authprovider/hostaccess_spec.rb +9 -15
- data/spec/strelka/authprovider_spec.rb +3 -9
- data/spec/strelka/cookie_spec.rb +32 -38
- data/spec/strelka/cookieset_spec.rb +31 -37
- data/spec/strelka/discovery_spec.rb +144 -0
- data/spec/strelka/exceptions_spec.rb +2 -8
- data/spec/strelka/httprequest/acceptparams_spec.rb +74 -83
- data/spec/strelka/httprequest/auth_spec.rb +5 -15
- data/spec/strelka/httprequest/negotiation_spec.rb +93 -103
- data/spec/strelka/httprequest/session_spec.rb +12 -22
- data/spec/strelka/httprequest_spec.rb +1 -7
- data/spec/strelka/httpresponse/negotiation_spec.rb +84 -76
- data/spec/strelka/httpresponse/session_spec.rb +25 -35
- data/spec/strelka/httpresponse_spec.rb +20 -26
- data/spec/strelka/mixins_spec.rb +66 -61
- data/spec/strelka/multipartparser_spec.rb +31 -37
- data/spec/strelka/paramvalidator_spec.rb +389 -373
- data/spec/strelka/plugins_spec.rb +17 -23
- data/spec/strelka/router/default_spec.rb +32 -38
- data/spec/strelka/router/exclusive_spec.rb +28 -34
- data/spec/strelka/router_spec.rb +2 -8
- data/spec/strelka/session/db_spec.rb +17 -15
- data/spec/strelka/session/default_spec.rb +22 -28
- data/spec/strelka/session_spec.rb +3 -9
- data/spec/strelka/websocketserver/routing_spec.rb +119 -0
- data/spec/strelka/websocketserver_spec.rb +149 -0
- data/spec/strelka_spec.rb +11 -13
- data.tar.gz.sig +3 -3
- metadata +22 -14
- metadata.gz.sig +0 -0
@@ -2,16 +2,10 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../../helpers'
|
10
6
|
|
11
7
|
require 'rspec'
|
12
8
|
|
13
|
-
require 'spec/lib/helpers'
|
14
|
-
|
15
9
|
require 'strelka'
|
16
10
|
require 'strelka/plugins'
|
17
11
|
require 'strelka/app/routing'
|
@@ -35,7 +29,7 @@ describe Strelka::App::Routing do
|
|
35
29
|
end
|
36
30
|
|
37
31
|
|
38
|
-
it_should_behave_like( "A Strelka
|
32
|
+
it_should_behave_like( "A Strelka Plugin" )
|
39
33
|
|
40
34
|
|
41
35
|
describe "an including App" do
|
@@ -51,124 +45,126 @@ describe Strelka::App::Routing do
|
|
51
45
|
|
52
46
|
|
53
47
|
it "has an Array of raw routes" do
|
54
|
-
@app.routes.
|
48
|
+
expect( @app.routes ).to be_a( Array )
|
55
49
|
end
|
56
50
|
|
57
51
|
it "knows what its route methods are" do
|
58
|
-
@app.route_methods.
|
52
|
+
expect( @app.route_methods ).to eq( [] )
|
59
53
|
@app.class_eval do
|
60
54
|
get() {}
|
61
55
|
post( '/clowns' ) {}
|
62
56
|
options( '/clowns' ) {}
|
63
57
|
end
|
64
58
|
|
65
|
-
@app.route_methods.
|
59
|
+
expect( @app.route_methods ).to eq( [ :GET, :POST_clowns, :OPTIONS_clowns ] )
|
66
60
|
end
|
67
61
|
|
68
62
|
# OPTIONS GET/HEAD POST PUT DELETE TRACE CONNECT
|
69
63
|
|
70
64
|
it "can declare a OPTIONS route" do
|
71
|
-
@app.routes.
|
65
|
+
expect( @app.routes ).to be_empty()
|
72
66
|
|
73
67
|
@app.class_eval do
|
74
68
|
options do |req|
|
75
69
|
end
|
76
70
|
end
|
77
71
|
|
78
|
-
@app.routes.
|
72
|
+
expect( @app.routes ).to eq([
|
79
73
|
[ :OPTIONS, [], {action: @app.instance_method(:OPTIONS), options: {}} ]
|
80
|
-
]
|
74
|
+
])
|
81
75
|
end
|
82
76
|
|
83
77
|
it "can declare a GET route" do
|
84
|
-
@app.routes.
|
78
|
+
expect( @app.routes ).to be_empty()
|
85
79
|
|
86
80
|
@app.class_eval do
|
87
81
|
get do |req|
|
88
82
|
end
|
89
83
|
end
|
90
84
|
|
91
|
-
@app.routes.
|
85
|
+
expect( @app.routes ).to eq([
|
92
86
|
[ :GET, [], {action: @app.instance_method(:GET), options: {}} ]
|
93
|
-
]
|
87
|
+
])
|
94
88
|
end
|
95
89
|
|
96
90
|
it "can declare a POST route" do
|
97
|
-
@app.routes.
|
91
|
+
expect( @app.routes ).to be_empty()
|
98
92
|
|
99
93
|
@app.class_eval do
|
100
94
|
post do |req|
|
101
95
|
end
|
102
96
|
end
|
103
97
|
|
104
|
-
@app.routes.
|
98
|
+
expect( @app.routes ).to eq([
|
105
99
|
[ :POST, [], {action: @app.instance_method(:POST), options: {}} ]
|
106
|
-
]
|
100
|
+
])
|
107
101
|
end
|
108
102
|
|
109
103
|
it "can declare a PUT route" do
|
110
|
-
@app.routes.
|
104
|
+
expect( @app.routes ).to be_empty()
|
111
105
|
|
112
106
|
@app.class_eval do
|
113
107
|
put do |req|
|
114
108
|
end
|
115
109
|
end
|
116
110
|
|
117
|
-
@app.routes.
|
111
|
+
expect( @app.routes ).to eq([
|
112
|
+
[ :PUT, [], {action: @app.instance_method(:PUT), options: {}} ]
|
113
|
+
])
|
118
114
|
end
|
119
115
|
|
120
116
|
it "can declare a DELETE route" do
|
121
|
-
@app.routes.
|
117
|
+
expect( @app.routes ).to be_empty()
|
122
118
|
|
123
119
|
@app.class_eval do
|
124
120
|
delete do |req|
|
125
121
|
end
|
126
122
|
end
|
127
123
|
|
128
|
-
@app.routes.
|
124
|
+
expect( @app.routes ).to eq([
|
129
125
|
[ :DELETE, [], {action: @app.instance_method(:DELETE), options: {}} ]
|
130
|
-
]
|
126
|
+
])
|
131
127
|
end
|
132
128
|
|
133
129
|
it "can declare a TRACE route" do
|
134
|
-
@app.routes.
|
130
|
+
expect( @app.routes ).to be_empty()
|
135
131
|
|
136
132
|
@app.class_eval do
|
137
133
|
trace do |req|
|
138
134
|
end
|
139
135
|
end
|
140
136
|
|
141
|
-
@app.routes.
|
137
|
+
expect( @app.routes ).to eq([
|
142
138
|
[ :TRACE, [], {action: @app.instance_method(:TRACE), options: {}} ]
|
143
|
-
]
|
139
|
+
])
|
144
140
|
end
|
145
141
|
|
146
142
|
it "can declare a CONNECT route" do
|
147
|
-
@app.routes.
|
143
|
+
expect( @app.routes ).to be_empty()
|
148
144
|
|
149
145
|
@app.class_eval do
|
150
146
|
connect do |req|
|
151
147
|
end
|
152
148
|
end
|
153
149
|
|
154
|
-
@app.routes.
|
150
|
+
expect( @app.routes ).to eq([
|
155
151
|
[ :CONNECT, [], {action: @app.instance_method(:CONNECT), options: {}} ]
|
156
|
-
]
|
152
|
+
])
|
157
153
|
end
|
158
154
|
|
159
155
|
|
160
156
|
|
161
157
|
it "allows a route to specify a path" do
|
162
|
-
@app.routes.
|
158
|
+
expect( @app.routes ).to be_empty()
|
163
159
|
|
164
160
|
@app.class_eval do
|
165
161
|
get '/info' do |req|
|
166
162
|
end
|
167
163
|
end
|
168
164
|
|
169
|
-
@app.routes.
|
165
|
+
expect( @app.routes ).to eq([
|
170
166
|
[ :GET, ['info'], {action: @app.instance_method(:GET_info), options: {}} ]
|
171
|
-
]
|
167
|
+
])
|
172
168
|
end
|
173
169
|
|
174
170
|
it "allows a route to omit the leading '/' when specifying a path" do
|
@@ -177,9 +173,9 @@ describe Strelka::App::Routing do
|
|
177
173
|
end
|
178
174
|
end
|
179
175
|
|
180
|
-
@app.routes.
|
176
|
+
expect( @app.routes ).to eq([
|
181
177
|
[ :GET, ['info'], {action: @app.instance_method(:GET_info), options: {}} ]
|
182
|
-
]
|
178
|
+
])
|
183
179
|
end
|
184
180
|
|
185
181
|
it "allows a route to specify a path via a Regex" do
|
@@ -188,13 +184,13 @@ describe Strelka::App::Routing do
|
|
188
184
|
end
|
189
185
|
end
|
190
186
|
|
191
|
-
@app.routes.first[0,2].
|
187
|
+
expect( @app.routes.first[0,2] ).to eq( [ :GET, [/\.pdf$/] ] )
|
192
188
|
end
|
193
189
|
|
194
190
|
|
195
191
|
it "uses the Strelka::Router::Default as it's router by default" do
|
196
|
-
@app.routerclass.
|
197
|
-
@app.new.router.
|
192
|
+
expect( @app.routerclass ).to eq( :default )
|
193
|
+
expect( @app.new.router ).to be_a( Strelka::Router::Default )
|
198
194
|
end
|
199
195
|
|
200
196
|
it "can specify a different Router class than the default" do
|
@@ -202,8 +198,8 @@ describe Strelka::App::Routing do
|
|
202
198
|
@app.class_eval do
|
203
199
|
router MyRouter
|
204
200
|
end
|
205
|
-
@app.routerclass.
|
206
|
-
@app.new.router.
|
201
|
+
expect( @app.routerclass ).to equal( MyRouter )
|
202
|
+
expect( @app.new.router ).to be_a( MyRouter )
|
207
203
|
end
|
208
204
|
|
209
205
|
|
@@ -218,17 +214,17 @@ describe Strelka::App::Routing do
|
|
218
214
|
get( '/origami' ) {}
|
219
215
|
end
|
220
216
|
|
221
|
-
subclass.routes.
|
217
|
+
expect( subclass.routes ).to have( 3 ).members
|
222
218
|
|
223
219
|
subclass.routes.
|
224
220
|
should include([ :GET, ['info'], {action: @app.instance_method(:GET_info), options: {}} ])
|
225
221
|
subclass.routes.
|
226
222
|
should include([ :GET, ['about'], {action: @app.instance_method(:GET_about), options: {}} ])
|
227
|
-
subclass.routes.
|
223
|
+
expect( subclass.routes ).to include(
|
228
224
|
[ :GET, ['origami'], {action: subclass.instance_method(:GET_origami), options: {}} ]
|
229
225
|
)
|
230
226
|
|
231
|
-
subclass.routerclass.
|
227
|
+
expect( subclass.routerclass ).to eq( @app.routerclass )
|
232
228
|
end
|
233
229
|
|
234
230
|
describe "that also uses the :parameters plugin" do
|
@@ -244,9 +240,10 @@ describe Strelka::App::Routing do
|
|
244
240
|
end
|
245
241
|
end
|
246
242
|
|
247
|
-
@app.routes.
|
248
|
-
[
|
249
|
-
|
243
|
+
expect( @app.routes ).to eq([
|
244
|
+
[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
|
245
|
+
{action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]
|
246
|
+
])
|
250
247
|
end
|
251
248
|
|
252
249
|
it "unbinds parameter patterns bound with ^ and $ for the route" do
|
@@ -256,9 +253,10 @@ describe Strelka::App::Routing do
|
|
256
253
|
end
|
257
254
|
end
|
258
255
|
|
259
|
-
@app.routes.
|
260
|
-
[
|
261
|
-
|
256
|
+
expect( @app.routes ).to eq([
|
257
|
+
[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
|
258
|
+
{action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]
|
259
|
+
])
|
262
260
|
end
|
263
261
|
|
264
262
|
it "unbinds parameter patterns bound with \\A and \\z for the route" do
|
@@ -268,9 +266,10 @@ describe Strelka::App::Routing do
|
|
268
266
|
end
|
269
267
|
end
|
270
268
|
|
271
|
-
@app.routes.
|
272
|
-
[
|
273
|
-
|
269
|
+
expect( @app.routes ).to eq([
|
270
|
+
[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
|
271
|
+
{action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]
|
272
|
+
])
|
274
273
|
end
|
275
274
|
|
276
275
|
it "unbinds parameter patterns bound with \\Z for the route" do
|
@@ -280,9 +279,10 @@ describe Strelka::App::Routing do
|
|
280
279
|
end
|
281
280
|
end
|
282
281
|
|
283
|
-
@app.routes.
|
284
|
-
[
|
285
|
-
{action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]
|
282
|
+
expect( @app.routes ).to eq([
|
283
|
+
[ :POST, ['userinfo', /(?<username>[a-z]\w+)/i],
|
284
|
+
{action: @app.instance_method(:POST_userinfo__re_username), options: {}} ]
|
285
|
+
])
|
286
286
|
end
|
287
287
|
|
288
288
|
it "merges parameters from the route path into the request's param validator" do
|
@@ -295,7 +295,7 @@ describe Strelka::App::Routing do
|
|
295
295
|
req = @request_factory.get( '/userinfo/benthik' )
|
296
296
|
@app.new.handle( req )
|
297
297
|
|
298
|
-
req.params[:username].
|
298
|
+
expect( req.params[:username] ).to eq( 'benthik' )
|
299
299
|
end
|
300
300
|
|
301
301
|
|
@@ -1,15 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
6
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
7
|
-
}
|
3
|
+
require_relative '../../helpers'
|
8
4
|
|
9
5
|
require 'rspec'
|
10
6
|
|
11
|
-
require 'spec/lib/helpers'
|
12
|
-
|
13
7
|
require 'strelka'
|
14
8
|
require 'strelka/plugins'
|
15
9
|
require 'strelka/app/sessions'
|
@@ -33,7 +27,7 @@ describe Strelka::App::Sessions do
|
|
33
27
|
end
|
34
28
|
|
35
29
|
|
36
|
-
it_should_behave_like( "A Strelka
|
30
|
+
it_should_behave_like( "A Strelka Plugin" )
|
37
31
|
|
38
32
|
|
39
33
|
describe "session-class loading" do
|
@@ -49,12 +43,12 @@ describe Strelka::App::Sessions do
|
|
49
43
|
|
50
44
|
it "has a default associated session class" do
|
51
45
|
Strelka::App::Sessions.configure
|
52
|
-
Strelka::App::Sessions.session_class.
|
46
|
+
expect( Strelka::App::Sessions.session_class ).to be( Strelka::Session::Default )
|
53
47
|
end
|
54
48
|
|
55
49
|
it "is can be configured to use a different session class" do
|
56
50
|
Strelka::App::Sessions.configure( :session_class => 'testing' )
|
57
|
-
Strelka::App::Sessions.session_class.
|
51
|
+
expect( Strelka::App::Sessions.session_class ).to eq( @test_session_class )
|
58
52
|
end
|
59
53
|
|
60
54
|
end
|
@@ -103,11 +97,11 @@ describe Strelka::App::Sessions do
|
|
103
97
|
@app.session_namespace :indian_gurbles
|
104
98
|
subclass = Class.new( @app )
|
105
99
|
|
106
|
-
subclass.session_namespace.
|
100
|
+
expect( subclass.session_namespace ).to eq( @app.session_namespace )
|
107
101
|
end
|
108
102
|
|
109
103
|
it "has a default session key that's the same as its appid" do
|
110
|
-
@app.session_namespace.
|
104
|
+
expect( @app.session_namespace ).to eq( @app.default_appid )
|
111
105
|
end
|
112
106
|
|
113
107
|
it "can set its session namespace to something else" do
|
@@ -115,25 +109,25 @@ describe Strelka::App::Sessions do
|
|
115
109
|
session_namespace :findizzle
|
116
110
|
end
|
117
111
|
|
118
|
-
@app.session_namespace.
|
112
|
+
expect( @app.session_namespace ).to eq( :findizzle )
|
119
113
|
end
|
120
114
|
|
121
115
|
it "extends the request and response classes" do
|
122
116
|
@app.install_plugins
|
123
|
-
Strelka::HTTPRequest.
|
124
|
-
Strelka::HTTPResponse.
|
117
|
+
expect( Strelka::HTTPRequest ).to be < Strelka::HTTPRequest::Session
|
118
|
+
expect( Strelka::HTTPResponse ).to be < Strelka::HTTPResponse::Session
|
125
119
|
end
|
126
120
|
|
127
121
|
it "sets the session namespace on requests" do
|
128
122
|
req = @request_factory.get( '/foom' )
|
129
123
|
res = @app.new.handle( req )
|
130
|
-
req.session_namespace.
|
124
|
+
expect( req.session_namespace ).to eq( @app.default_appid )
|
131
125
|
end
|
132
126
|
|
133
127
|
it "saves the session automatically" do
|
134
128
|
req = @request_factory.get( '/foom' )
|
135
129
|
res = @app.new.handle( req )
|
136
|
-
res.cookies.
|
130
|
+
expect( res.cookies ).to include( Strelka::Session::Default.cookie_name )
|
137
131
|
end
|
138
132
|
|
139
133
|
end
|
@@ -2,17 +2,11 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../../helpers'
|
10
6
|
|
11
7
|
require 'rspec'
|
12
8
|
require 'inversion'
|
13
9
|
|
14
|
-
require 'spec/lib/helpers'
|
15
|
-
|
16
10
|
require 'strelka'
|
17
11
|
require 'strelka/plugins'
|
18
12
|
require 'strelka/app/templating'
|
@@ -38,7 +32,7 @@ describe Strelka::App::Templating do
|
|
38
32
|
end
|
39
33
|
|
40
34
|
|
41
|
-
it_should_behave_like( "A Strelka
|
35
|
+
it_should_behave_like( "A Strelka Plugin" )
|
42
36
|
|
43
37
|
|
44
38
|
describe "template discovery" do
|
@@ -55,27 +49,28 @@ describe Strelka::App::Templating do
|
|
55
49
|
specs[:karate] = make_gemspec( 'karate', '1.0.0', false )
|
56
50
|
specs[:javelin] = make_gemspec( 'javelin', '1.0.0' )
|
57
51
|
|
58
|
-
|
59
|
-
|
52
|
+
expect( Gem::Specification ).to receive( :each ).once do |&block|
|
53
|
+
specs.values.each {|spec| block.call(spec) }
|
54
|
+
end
|
60
55
|
|
61
56
|
gymnastics_path = specs[:gymnastics].full_gem_path
|
62
57
|
cycling_path = specs[:cycling_new].full_gem_path
|
63
58
|
javelin_path = specs[:javelin].full_gem_path
|
64
59
|
|
65
|
-
Dir.
|
60
|
+
expect( Dir ).to receive( :glob ).with( 'data/*/templates' ).
|
66
61
|
and_return([ "data/foom/templates" ])
|
67
|
-
Dir.
|
62
|
+
expect( Dir ).to receive( :glob ).with( "#{javelin_path}/data/javelin/templates" ).
|
68
63
|
and_return([ "#{javelin_path}/data/javelin/templates" ])
|
69
|
-
Dir.
|
64
|
+
expect( Dir ).to receive( :glob ).with( "#{gymnastics_path}/data/gymnastics/templates" ).
|
70
65
|
and_return([ "#{gymnastics_path}/data/gymnastics/templates" ])
|
71
66
|
|
72
|
-
Dir.
|
67
|
+
expect( Dir ).to receive( :glob ).with( "#{cycling_path}/data/cycling/templates" ).
|
73
68
|
and_return([])
|
74
69
|
|
75
70
|
template_dirs = described_class.discover_template_dirs
|
76
71
|
|
77
|
-
|
78
|
-
template_dirs.
|
72
|
+
expect( template_dirs ).to have( 3 ).pathnames
|
73
|
+
expect( template_dirs ).to include(
|
79
74
|
Pathname("data/foom/templates"),
|
80
75
|
Pathname("#{javelin_path}/data/javelin/templates"),
|
81
76
|
Pathname("#{gymnastics_path}/data/gymnastics/templates")
|
@@ -88,22 +83,23 @@ describe Strelka::App::Templating do
|
|
88
83
|
specs[:gymnastics] = make_gemspec( 'gymnastics', '1.0.0' )
|
89
84
|
specs[:javelin] = make_gemspec( 'javelin', '1.0.0' )
|
90
85
|
|
91
|
-
|
92
|
-
|
86
|
+
expect( Gem::Specification ).to receive( :each ).once do |&block|
|
87
|
+
specs.values.each {|spec| block.call(spec) }
|
88
|
+
end
|
93
89
|
|
94
90
|
gymnastics_path = specs[:gymnastics].full_gem_path
|
95
91
|
javelin_path = specs[:javelin].full_gem_path
|
96
92
|
|
97
|
-
Dir.
|
93
|
+
expect( Dir ).to receive( :glob ).with( 'data/*/templates' ).
|
98
94
|
and_return([ "data/foom/templates" ])
|
99
|
-
Dir.
|
95
|
+
expect( Dir ).to receive( :glob ).with( "#{javelin_path}/data/javelin/templates" ).
|
100
96
|
and_return([ "#{javelin_path}/data/javelin/templates" ])
|
101
|
-
Dir.
|
97
|
+
expect( Dir ).to receive( :glob ).with( "#{gymnastics_path}/data/gymnastics/templates" ).
|
102
98
|
and_return([ "#{gymnastics_path}/data/gymnastics/templates" ])
|
103
99
|
|
104
100
|
Module.new { include Strelka::App::Templating }
|
105
101
|
|
106
|
-
Inversion::Template.template_paths.
|
102
|
+
expect( Inversion::Template.template_paths ).to include(
|
107
103
|
Pathname("data/foom/templates"),
|
108
104
|
Pathname("#{javelin_path}/data/javelin/templates"),
|
109
105
|
Pathname("#{gymnastics_path}/data/gymnastics/templates")
|
@@ -133,14 +129,14 @@ describe Strelka::App::Templating do
|
|
133
129
|
@app.layout 'layout.tmpl'
|
134
130
|
subclass = Class.new( @app )
|
135
131
|
|
136
|
-
subclass.template_map.
|
137
|
-
subclass.template_map.
|
138
|
-
subclass.layout_template.
|
139
|
-
subclass.layout_template.
|
132
|
+
expect( subclass.template_map ).to eq( @app.template_map )
|
133
|
+
expect( subclass.template_map ).to_not equal( @app.template_map )
|
134
|
+
expect( subclass.layout_template ).to eq( @app.layout_template )
|
135
|
+
expect( subclass.layout_template ).to_not equal( @app.layout_template )
|
140
136
|
end
|
141
137
|
|
142
138
|
it "has a Hash of templates" do
|
143
|
-
@app.templates.
|
139
|
+
expect( @app.templates ).to be_a( Hash )
|
144
140
|
end
|
145
141
|
|
146
142
|
it "can add templates that it wants to use to its templates hash" do
|
@@ -148,7 +144,7 @@ describe Strelka::App::Templating do
|
|
148
144
|
templates :main => 'main.tmpl'
|
149
145
|
end
|
150
146
|
|
151
|
-
@app.templates.
|
147
|
+
expect( @app.templates ).to eq( { :main => 'main.tmpl' } )
|
152
148
|
end
|
153
149
|
|
154
150
|
it "can declare a layout template" do
|
@@ -156,7 +152,7 @@ describe Strelka::App::Templating do
|
|
156
152
|
layout 'layout.tmpl'
|
157
153
|
end
|
158
154
|
|
159
|
-
@app.layout.
|
155
|
+
expect( @app.layout ).to eq( 'layout.tmpl' )
|
160
156
|
end
|
161
157
|
|
162
158
|
describe "instance" do
|
@@ -178,7 +174,7 @@ describe Strelka::App::Templating do
|
|
178
174
|
|
179
175
|
|
180
176
|
it "can load declared templates by mentioning the symbol" do
|
181
|
-
@app.new.template( :main ).
|
177
|
+
expect( @app.new.template( :main ) ).to be_a( Inversion::Template )
|
182
178
|
end
|
183
179
|
|
184
180
|
it "can respond with just a template name" do
|
@@ -191,8 +187,8 @@ describe Strelka::App::Templating do
|
|
191
187
|
res = @app.new.handle( @req )
|
192
188
|
|
193
189
|
res.body.rewind
|
194
|
-
res.body.read.
|
195
|
-
res.status.
|
190
|
+
expect( res.body.read ).to eq( "A template for testing the Templating plugin.\n" )
|
191
|
+
expect( res.status ).to eq( 200 )
|
196
192
|
end
|
197
193
|
|
198
194
|
it "can respond with just a template instance" do
|
@@ -205,8 +201,8 @@ describe Strelka::App::Templating do
|
|
205
201
|
res = @app.new.handle( @req )
|
206
202
|
|
207
203
|
res.body.rewind
|
208
|
-
res.body.read.
|
209
|
-
res.status.
|
204
|
+
expect( res.body.read ).to eq( "A template for testing the Templating plugin.\n" )
|
205
|
+
expect( res.status ).to eq( 200 )
|
210
206
|
end
|
211
207
|
|
212
208
|
it "can respond with a Mongrel2::HTTPResponse with a template instance as its body" do
|
@@ -223,8 +219,8 @@ describe Strelka::App::Templating do
|
|
223
219
|
res = @app.new.handle( @req )
|
224
220
|
|
225
221
|
res.body.rewind
|
226
|
-
res.body.read.
|
227
|
-
res.status.
|
222
|
+
expect( res.body.read ).to eq( "A template for testing the Templating plugin.\n" )
|
223
|
+
expect( res.status ).to eq( 200 )
|
228
224
|
end
|
229
225
|
|
230
226
|
|
@@ -245,9 +241,9 @@ describe Strelka::App::Templating do
|
|
245
241
|
res = @app.new.handle( @req )
|
246
242
|
|
247
243
|
res.body.rewind
|
248
|
-
res.body.read.
|
249
|
-
"A template for testing the Templating plugin.\n\n"
|
250
|
-
res.status.
|
244
|
+
expect( res.body.read ).to eq( "A minimal layout template.\n" +
|
245
|
+
"A template for testing the Templating plugin.\n\n" )
|
246
|
+
expect( res.status ).to eq( 200 )
|
251
247
|
end
|
252
248
|
|
253
249
|
it "doesn't wrap the layout around non-template responses" do
|
@@ -267,7 +263,7 @@ describe Strelka::App::Templating do
|
|
267
263
|
res = @app.new.handle( @req )
|
268
264
|
|
269
265
|
res.body.rewind
|
270
|
-
res.body.read.
|
266
|
+
expect( res.body.read ).to eq( "A template for testing the Templating plugin.\n" )
|
271
267
|
end
|
272
268
|
|
273
269
|
end
|