strelka 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ChangeLog +156 -9
  4. data/History.rdoc +15 -0
  5. data/IDEAS.rdoc +17 -1
  6. data/MILESTONES.rdoc +1 -1
  7. data/Manifest.txt +10 -2
  8. data/Plugins.rdoc +4 -4
  9. data/README.rdoc +3 -3
  10. data/Rakefile +5 -4
  11. data/bin/strelka +19 -10
  12. data/contrib/hoetemplate/data/project/apps/file_name_app +1 -0
  13. data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
  14. data/examples/apps/hello-world +1 -0
  15. data/examples/apps/ws-chat +69 -0
  16. data/examples/apps/ws-echo +61 -0
  17. data/examples/gen-config.rb +6 -5
  18. data/lib/strelka/app/auth.rb +2 -2
  19. data/lib/strelka/app/errors.rb +1 -1
  20. data/lib/strelka/app/filters.rb +3 -2
  21. data/lib/strelka/app/negotiation.rb +2 -2
  22. data/lib/strelka/app/parameters.rb +1 -2
  23. data/lib/strelka/app/restresources.rb +3 -2
  24. data/lib/strelka/app/routing.rb +1 -1
  25. data/lib/strelka/app/sessions.rb +2 -2
  26. data/lib/strelka/app/templating.rb +7 -3
  27. data/lib/strelka/app.rb +5 -145
  28. data/lib/strelka/behavior/plugin.rb +4 -4
  29. data/lib/strelka/discovery.rb +211 -0
  30. data/lib/strelka/httprequest.rb +1 -0
  31. data/lib/strelka/httpresponse/negotiation.rb +7 -1
  32. data/lib/strelka/mixins.rb +4 -1
  33. data/lib/strelka/paramvalidator.rb +1 -1
  34. data/lib/strelka/plugins.rb +8 -6
  35. data/lib/strelka/websocketserver/routing.rb +116 -0
  36. data/lib/strelka/websocketserver.rb +147 -0
  37. data/lib/strelka.rb +5 -4
  38. data/spec/{lib/constants.rb → constants.rb} +3 -2
  39. data/spec/{lib/helpers.rb → helpers.rb} +15 -14
  40. data/spec/strelka/app/auth_spec.rb +145 -142
  41. data/spec/strelka/app/errors_spec.rb +20 -26
  42. data/spec/strelka/app/filters_spec.rb +67 -54
  43. data/spec/strelka/app/negotiation_spec.rb +8 -14
  44. data/spec/strelka/app/parameters_spec.rb +23 -29
  45. data/spec/strelka/app/restresources_spec.rb +98 -100
  46. data/spec/strelka/app/routing_spec.rb +57 -57
  47. data/spec/strelka/app/sessions_spec.rb +11 -17
  48. data/spec/strelka/app/templating_spec.rb +36 -40
  49. data/spec/strelka/app_spec.rb +48 -147
  50. data/spec/strelka/authprovider/basic_spec.rb +5 -11
  51. data/spec/strelka/authprovider/hostaccess_spec.rb +9 -15
  52. data/spec/strelka/authprovider_spec.rb +3 -9
  53. data/spec/strelka/cookie_spec.rb +32 -38
  54. data/spec/strelka/cookieset_spec.rb +31 -37
  55. data/spec/strelka/discovery_spec.rb +144 -0
  56. data/spec/strelka/exceptions_spec.rb +2 -8
  57. data/spec/strelka/httprequest/acceptparams_spec.rb +74 -83
  58. data/spec/strelka/httprequest/auth_spec.rb +5 -15
  59. data/spec/strelka/httprequest/negotiation_spec.rb +93 -103
  60. data/spec/strelka/httprequest/session_spec.rb +12 -22
  61. data/spec/strelka/httprequest_spec.rb +1 -7
  62. data/spec/strelka/httpresponse/negotiation_spec.rb +84 -76
  63. data/spec/strelka/httpresponse/session_spec.rb +25 -35
  64. data/spec/strelka/httpresponse_spec.rb +20 -26
  65. data/spec/strelka/mixins_spec.rb +66 -61
  66. data/spec/strelka/multipartparser_spec.rb +31 -37
  67. data/spec/strelka/paramvalidator_spec.rb +389 -373
  68. data/spec/strelka/plugins_spec.rb +17 -23
  69. data/spec/strelka/router/default_spec.rb +32 -38
  70. data/spec/strelka/router/exclusive_spec.rb +28 -34
  71. data/spec/strelka/router_spec.rb +2 -8
  72. data/spec/strelka/session/db_spec.rb +17 -15
  73. data/spec/strelka/session/default_spec.rb +22 -28
  74. data/spec/strelka/session_spec.rb +3 -9
  75. data/spec/strelka/websocketserver/routing_spec.rb +119 -0
  76. data/spec/strelka/websocketserver_spec.rb +149 -0
  77. data/spec/strelka_spec.rb +11 -13
  78. data.tar.gz.sig +3 -3
  79. metadata +22 -14
  80. metadata.gz.sig +0 -0
@@ -2,18 +2,12 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
5
- BEGIN {
6
- require 'pathname'
7
- basedir = Pathname.new( __FILE__ ).dirname.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 'zmq'
13
9
  require 'mongrel2'
14
10
 
15
- require 'spec/lib/helpers'
16
-
17
11
  require 'strelka'
18
12
  require 'strelka/app'
19
13
 
@@ -66,100 +60,13 @@ describe Strelka::App do
66
60
  # Examples
67
61
  #
68
62
 
69
- it "has a method for loading app class/es from a file" do
70
- app_file = 'an_app.rb'
71
- app_path = Pathname( app_file ).expand_path
72
- app_class = nil
73
-
74
- Kernel.should_receive( :load ).with( app_path.to_s ).and_return do
75
- app_class = Class.new( Strelka::App )
76
- end
77
- Strelka::App.load( app_file ).should == [ app_class ]
78
- end
79
-
80
- it "has a method for discovering installed Strelka app files" do
81
- specs = {}
82
- specs[:donkey] = make_gemspec( 'donkey', '1.0.0' )
83
- specs[:rabbit_old] = make_gemspec( 'rabbit', '1.0.0' )
84
- specs[:rabbit_new] = make_gemspec( 'rabbit', '1.0.8' )
85
- specs[:bear] = make_gemspec( 'bear', '1.0.0', false )
86
- specs[:giraffe] = make_gemspec( 'giraffe', '1.0.0' )
87
-
88
- expectation = Gem::Specification.should_receive( :each )
89
- specs.values.each {|spec| expectation.and_yield(spec) }
90
-
91
- donkey_path = specs[:donkey].full_gem_path
92
- rabbit_path = specs[:rabbit_new].full_gem_path
93
- giraffe_path = specs[:giraffe].full_gem_path
94
-
95
- Dir.should_receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
96
- and_return( [] )
97
- Dir.should_receive( :glob ).with( "#{giraffe_path}/data/giraffe/{apps,handlers}/**/*" ).
98
- and_return([ "#{giraffe_path}/data/giraffe/apps/app" ])
99
- Dir.should_receive( :glob ).with( "#{rabbit_path}/data/rabbit/{apps,handlers}/**/*" ).
100
- and_return([ "#{rabbit_path}/data/rabbit/apps/subdir/app1.rb",
101
- "#{rabbit_path}/data/rabbit/apps/subdir/app2.rb" ])
102
- Dir.should_receive( :glob ).with( "#{donkey_path}/data/donkey/{apps,handlers}/**/*" ).
103
- and_return([ "#{donkey_path}/data/donkey/apps/app.rb" ])
104
-
105
- app_paths = Strelka::App.discover_paths
106
-
107
- # app_paths.should have( 4 ).members
108
- app_paths.should include(
109
- 'donkey' => [Pathname("#{donkey_path}/data/donkey/apps/app.rb")],
110
- 'rabbit' => [Pathname("#{rabbit_path}/data/rabbit/apps/subdir/app1.rb"),
111
- Pathname("#{rabbit_path}/data/rabbit/apps/subdir/app2.rb")],
112
- 'giraffe' => [Pathname("#{giraffe_path}/data/giraffe/apps/app")]
113
- )
114
- end
115
-
116
- it "has a method for loading discovered app classes from installed Strelka app files" do
117
- gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
118
- Gem::Specification.should_receive( :each ).and_yield( gemspec ).at_least( :once )
119
-
120
- Dir.should_receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
121
- and_return( [] )
122
- Dir.should_receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
123
- and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
124
-
125
- Kernel.stub( :load ).
126
- with( "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ).
127
- and_return do
128
- Class.new( Strelka::App )
129
- true
130
- end
131
-
132
- app_classes = Strelka::App.discover
133
- app_classes.should have( 1 ).member
134
- app_classes.first.should be_a( Class )
135
- app_classes.first.should < Strelka::App
136
- end
137
-
138
- it "handles exceptions while loading discovered apps" do
139
- gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
140
- Gem::Specification.should_receive( :each ).and_yield( gemspec ).at_least( :once )
141
-
142
- Dir.should_receive( :glob ).with( 'data/*/{apps,handlers}/**/*' ).
143
- and_return( [] )
144
- Dir.should_receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
145
- and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
146
-
147
- Kernel.stub( :load ).
148
- with( "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ).
149
- and_raise( SyntaxError.new("kurzweil:1: syntax error, unexpected coffeeshop philosopher") )
150
-
151
- app_classes = Strelka::App.discover
152
- app_classes.should be_empty()
153
- end
154
-
155
-
156
63
  it "returns a No Content response by default" do
157
64
  res = @app.new.handle( @req )
158
65
 
159
- res.should be_a( Mongrel2::HTTPResponse )
160
- res.status_line.should == 'HTTP/1.1 204 No Content'
66
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
67
+ expect( res.status_line ).to eq( 'HTTP/1.1 204 No Content' )
161
68
  res.body.rewind
162
- res.body.read.should == ''
69
+ expect( res.body.read ).to eq( '' )
163
70
  end
164
71
 
165
72
 
@@ -178,10 +85,10 @@ describe Strelka::App do
178
85
 
179
86
  res = @app.new.handle( @req )
180
87
 
181
- res.should be_a( Mongrel2::HTTPResponse )
182
- res.status_line.should == 'HTTP/1.1 304 Not Modified'
88
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
89
+ expect( res.status_line ).to eq( 'HTTP/1.1 304 Not Modified' )
183
90
  res.body.rewind
184
- res.body.read.should == ''
91
+ expect( res.body.read ).to eq( '' )
185
92
  end
186
93
 
187
94
 
@@ -199,11 +106,11 @@ describe Strelka::App do
199
106
 
200
107
  res = @app.new.handle( @req )
201
108
 
202
- res.should be_a( Mongrel2::HTTPResponse )
203
- res.status_line.should == 'HTTP/1.1 403 Forbidden'
204
- res.content_type.should == 'text/plain'
109
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
110
+ expect( res.status_line ).to eq( 'HTTP/1.1 403 Forbidden' )
111
+ expect( res.content_type ).to eq( 'text/plain' )
205
112
  res.body.rewind
206
- res.body.read.should == "You aren't allowed to look at that.\n"
113
+ expect( res.body.read ).to eq( "You aren't allowed to look at that.\n" )
207
114
  end
208
115
 
209
116
 
@@ -222,11 +129,11 @@ describe Strelka::App do
222
129
 
223
130
  res = @app.new.handle( @req )
224
131
 
225
- res.should be_a( Mongrel2::HTTPResponse )
226
- res.status_line.should == 'HTTP/1.1 403 Forbidden'
227
- res.content_type.should == 'text/html'
132
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
133
+ expect( res.status_line ).to eq( 'HTTP/1.1 403 Forbidden' )
134
+ expect( res.content_type ).to eq( 'text/html' )
228
135
  res.body.rewind
229
- res.body.read.should == "You aren't allowed to look at that.\n"
136
+ expect( res.body.read ).to eq( "You aren't allowed to look at that.\n" )
230
137
  end
231
138
 
232
139
  it "sets the error status info in the transaction notes for error responses" do
@@ -242,10 +149,10 @@ describe Strelka::App do
242
149
 
243
150
  res = @app.new.handle( @req )
244
151
 
245
- res.notes.should include( :status_info )
246
- res.notes[:status_info].should include( :status, :message, :headers )
247
- res.notes[:status_info][:status].should == HTTP::FORBIDDEN
248
- res.notes[:status_info][:message].should == "You aren't allowed to look at that."
152
+ expect( res.notes ).to include( :status_info )
153
+ expect( res.notes[:status_info] ).to include( :status, :message, :headers )
154
+ expect( res.notes[:status_info][:status] ).to eq( HTTP::FORBIDDEN )
155
+ expect( res.notes[:status_info][:message] ).to eq( "You aren't allowed to look at that." )
249
156
  end
250
157
 
251
158
 
@@ -260,8 +167,8 @@ describe Strelka::App do
260
167
 
261
168
  res = @app.new.handle( @req )
262
169
 
263
- res.should be_a( Mongrel2::HTTPResponse )
264
- res.content_type.should == 'text/css'
170
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
171
+ expect( res.content_type ).to eq( 'text/css' )
265
172
  end
266
173
 
267
174
  it "doesn't override an explicitly-set content-type header with the default" do
@@ -276,8 +183,8 @@ describe Strelka::App do
276
183
 
277
184
  res = @app.new.handle( @req )
278
185
 
279
- res.should be_a( Mongrel2::HTTPResponse )
280
- res.content_type.should == 'text/plain'
186
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
187
+ expect( res.content_type ).to eq( 'text/plain' )
281
188
  end
282
189
 
283
190
 
@@ -293,11 +200,11 @@ describe Strelka::App do
293
200
  req = @request_factory.head( '/mail/inbox' )
294
201
  res = @app.new.handle( req )
295
202
 
296
- res.should be_a( Mongrel2::HTTPResponse )
297
- res.content_type.should == 'text/plain'
203
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
204
+ expect( res.content_type ).to eq( 'text/plain' )
298
205
  res.body.rewind
299
- res.body.read.should == ''
300
- res.headers.content_length.should == "Rendered output.\n".bytesize
206
+ expect( res.body.read ).to eq( '' )
207
+ expect( res.headers.content_length ).to eq( "Rendered output.\n".bytesize )
301
208
  end
302
209
 
303
210
 
@@ -305,9 +212,9 @@ describe Strelka::App do
305
212
  @app.const_set( :ID, 'testing-app' )
306
213
  conn = double( "Mongrel2 connection", close: true )
307
214
 
308
- Mongrel2::Handler.should_receive( :connection_info_for ).with( 'testing-app' ).
215
+ expect( Mongrel2::Handler ).to receive( :connection_info_for ).with( 'testing-app' ).
309
216
  and_return([ TEST_SEND_SPEC, TEST_RECV_SPEC ])
310
- Mongrel2::Connection.should_receive( :new ).
217
+ expect( Mongrel2::Connection ).to receive( :new ).
311
218
  with( 'testing-app', TEST_SEND_SPEC, TEST_RECV_SPEC ).
312
219
  and_return( conn )
313
220
 
@@ -321,9 +228,9 @@ describe Strelka::App do
321
228
  end
322
229
  conn = double( "Mongrel2 connection", close: true )
323
230
 
324
- Mongrel2::Handler.should_receive( :connection_info_for ).with( 'my-first-blog' ).
231
+ expect( Mongrel2::Handler ).to receive( :connection_info_for ).with( 'my-first-blog' ).
325
232
  and_return([ TEST_SEND_SPEC, TEST_RECV_SPEC ])
326
- Mongrel2::Connection.should_receive( :new ).
233
+ expect( Mongrel2::Connection ).to receive( :new ).
327
234
  with( 'my-first-blog', TEST_SEND_SPEC, TEST_RECV_SPEC ).
328
235
  and_return( conn )
329
236
 
@@ -340,20 +247,20 @@ describe Strelka::App do
340
247
 
341
248
  res = @app.new.handle( @req )
342
249
 
343
- res.should be_a( Mongrel2::HTTPResponse )
344
- res.status.should == HTTP::SERVER_ERROR
250
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
251
+ expect( res.status ).to eq( HTTP::SERVER_ERROR )
345
252
  res.content_type = 'text/plain'
346
253
  res.body.rewind
347
- res.body.read.should =~ /internal server error/i
254
+ expect( res.body.read ).to match( /internal server error/i )
348
255
  end
349
256
 
350
257
  it "isn't in 'developer mode' by default" do
351
- @app.should_not be_in_devmode()
258
+ expect( @app ).to_not be_in_devmode()
352
259
  end
353
260
 
354
261
  it "can be configured to be in 'developer mode' using the Configurability API" do
355
262
  @app.configure( devmode: true )
356
- @app.should be_in_devmode()
263
+ expect( @app ).to be_in_devmode()
357
264
  end
358
265
 
359
266
  it "configures itself to be in 'developer mode' if debugging is enabled" do
@@ -362,28 +269,22 @@ describe Strelka::App do
362
269
  begin
363
270
  $DEBUG = true
364
271
  @app.configure
365
- @app.should be_in_devmode()
272
+ expect( @app ).to be_in_devmode()
366
273
  ensure
367
274
  $DEBUG = debugsetting
368
275
  end
369
276
  end
370
277
 
371
- it "uses the default local data directory if the config is present without that key" do
372
- config = Configurability::Config.new( 'devmode: true' )
373
- @app.configure( config )
374
- @app.local_data_dirs.should == Strelka::App::CONFIG_DEFAULTS[:local_data_dirs]
375
- end
376
-
377
278
  it "closes async uploads with a 413 Request Entity Too Large by default" do
378
279
  @req.headers.x_mongrel2_upload_start = 'an/uploaded/file/path'
379
280
 
380
281
  app = @app.new
381
- app.conn.should_receive( :reply ).with( an_instance_of(Strelka::HTTPResponse) )
382
- app.conn.should_receive( :reply_close ).with( @req )
282
+ expect( app.conn ).to receive( :reply ).with( an_instance_of(Strelka::HTTPResponse) )
283
+ expect( app.conn ).to receive( :reply_close ).with( @req )
383
284
 
384
285
  res = app.handle_async_upload_start( @req )
385
286
 
386
- res.should be_nil()
287
+ expect( res ).to be_nil()
387
288
  end
388
289
 
389
290
 
@@ -400,8 +301,8 @@ describe Strelka::App do
400
301
  it "sets the process name to something more interesting than the command line" do
401
302
  @app.new.run
402
303
 
403
- $0.should =~ /#{@app.inspect}/
404
- $0.should =~ %r|\{\S+\} tcp://\S+ <-> \S+|
304
+ expect( $0 ).to match( /#{@app.inspect}/ )
305
+ expect( $0 ).to match( %r|\{\S+\} tcp://\S+ <-> \S+| )
405
306
  end
406
307
 
407
308
  end
@@ -428,10 +329,10 @@ describe Strelka::App do
428
329
 
429
330
  res = @app.new.handle( @req )
430
331
 
431
- res.should be_a( Mongrel2::HTTPResponse )
432
- res.status_line.should == 'HTTP/1.1 200 OK'
332
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
333
+ expect( res.status_line ).to eq( 'HTTP/1.1 200 OK' )
433
334
  res.body.rewind
434
- res.body.read.should == "Request was funted by Cragnux/1.1.3!\n"
335
+ expect( res.body.read ).to eq( "Request was funted by Cragnux/1.1.3!\n" )
435
336
  end
436
337
 
437
338
 
@@ -455,9 +356,9 @@ describe Strelka::App do
455
356
 
456
357
  res = @app.new.handle( @req )
457
358
 
458
- res.should be_a( Mongrel2::HTTPResponse )
459
- res.status_line.should == 'HTTP/1.1 200 OK'
460
- res.header_data.should =~ %r{X-Funted-By: Cragnux/1.1.3}
359
+ expect( res ).to be_a( Mongrel2::HTTPResponse )
360
+ expect( res.status_line ).to eq( 'HTTP/1.1 200 OK' )
361
+ expect( res.header_data ).to match( %r{X-Funted-By: Cragnux/1.1.3} )
461
362
  end
462
363
 
463
364
  end
@@ -1,17 +1,11 @@
1
1
  # -*- rspec -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
 
4
- BEGIN {
5
- require 'pathname'
6
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
7
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
8
- }
4
+ require_relative '../../helpers'
9
5
 
10
6
  require 'rspec'
11
7
  require 'ipaddr'
12
8
 
13
- require 'spec/lib/helpers'
14
-
15
9
  require 'strelka'
16
10
  require 'strelka/authprovider/basic'
17
11
 
@@ -28,7 +22,7 @@ describe Strelka::AuthProvider::Basic do
28
22
  end
29
23
 
30
24
  before( :each ) do
31
- @app = stub( "Strelka::App", :conn => stub("Connection", :app_id => 'test-app') )
25
+ @app = double( "Strelka::App", :conn => double("Connection", :app_id => 'test-app') )
32
26
  @provider = Strelka::AuthProvider.create( :basic, @app )
33
27
  @config = {
34
28
  :realm => 'Pern',
@@ -66,8 +60,8 @@ describe Strelka::AuthProvider::Basic do
66
60
 
67
61
  it "can be configured via the Configurability API" do
68
62
  described_class.configure( @config )
69
- described_class.realm.should == @config[:realm]
70
- described_class.users.should == @config[:users]
63
+ expect( described_class.realm ).to eq( @config[:realm] )
64
+ expect( described_class.users ).to eq( @config[:users] )
71
65
  end
72
66
 
73
67
 
@@ -171,7 +165,7 @@ describe Strelka::AuthProvider::Basic do
171
165
  req = @request_factory.get( '/admin/console' )
172
166
  req.header.authorization = make_authorization_header( 'lessa', 'ramoth' )
173
167
 
174
- @provider.authenticate( req ).should be_true()
168
+ expect( @provider.authenticate(req) ).to be_true()
175
169
  end
176
170
  end
177
171
 
@@ -1,17 +1,11 @@
1
1
  # -*- rspec -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
 
4
- BEGIN {
5
- require 'pathname'
6
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
7
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
8
- }
4
+ require_relative '../../helpers'
9
5
 
10
6
  require 'rspec'
11
7
  require 'ipaddr'
12
8
 
13
- require 'spec/lib/helpers'
14
-
15
9
  require 'strelka'
16
10
  require 'strelka/authprovider/hostaccess'
17
11
 
@@ -28,7 +22,7 @@ describe Strelka::AuthProvider::HostAccess do
28
22
  end
29
23
 
30
24
  before( :each ) do
31
- @app = stub( "Strelka::App" )
25
+ @app = double( "Strelka::App" )
32
26
  @provider = Strelka::AuthProvider.create( :hostaccess, @app )
33
27
  end
34
28
 
@@ -38,31 +32,31 @@ describe Strelka::AuthProvider::HostAccess do
38
32
 
39
33
 
40
34
  it "knows what its allowed netblocks are" do
41
- @provider.allowed_netblocks.should be_an( Array )
42
- @provider.allowed_netblocks.should include( IPAddr.new('127.0.0.0/8') )
35
+ expect( @provider.allowed_netblocks ).to be_an( Array )
36
+ expect( @provider.allowed_netblocks ).to include( IPAddr.new('127.0.0.0/8') )
43
37
  end
44
38
 
45
39
  it "allows its netblocks to be set" do
46
40
  @provider.allowed_netblocks = %w[10.5.2.0/22 10.6.2.0/24]
47
- @provider.allowed_netblocks.should have( 2 ).members
48
- @provider.allowed_netblocks.should include( IPAddr.new('10.5.2.0/22'), IPAddr.new('10.6.2.0/24') )
41
+ expect( @provider.allowed_netblocks ).to have( 2 ).members
42
+ expect( @provider.allowed_netblocks ).to include( IPAddr.new('10.5.2.0/22'), IPAddr.new('10.6.2.0/24') )
49
43
  end
50
44
 
51
45
  it "can be configured via the Configurability API" do
52
46
  @provider.configure( 'allowed_netblocks' => %w[10.5.2.0/22 10.6.2.0/24] )
53
- @provider.allowed_netblocks.should include( IPAddr.new('10.5.2.0/22'), IPAddr.new('10.6.2.0/24') )
47
+ expect( @provider.allowed_netblocks ).to include( IPAddr.new('10.5.2.0/22'), IPAddr.new('10.6.2.0/24') )
54
48
  end
55
49
 
56
50
 
57
51
  it "allows a request that originates from one of its allowed netblocks" do
58
52
  req = @request_factory.get( '/admin/console', :x_forwarded_for => '127.0.0.1' )
59
- @provider.authorize( nil, req, nil ).should be_true()
53
+ expect( @provider.authorize( nil, req, nil ) ).to be_true()
60
54
  end
61
55
 
62
56
 
63
57
  it "doesn't allow a request which is not from one of its allowed netblocks" do
64
58
  req = @request_factory.get( '/admin/console', :x_forwarded_for => '8.8.8.8' )
65
- @provider.authorize( nil, req, nil ).should be_false()
59
+ expect( @provider.authorize( nil, req, nil ) ).to be_false()
66
60
  end
67
61
 
68
62
 
@@ -1,16 +1,10 @@
1
1
  # -*- rspec -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
 
4
- BEGIN {
5
- require 'pathname'
6
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent
7
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
8
- }
4
+ require_relative '../helpers'
9
5
 
10
6
  require 'rspec'
11
7
 
12
- require 'spec/lib/helpers'
13
-
14
8
  require 'strelka'
15
9
  require 'strelka/authprovider'
16
10
 
@@ -32,7 +26,7 @@ describe Strelka::AuthProvider do
32
26
 
33
27
 
34
28
  it "looks for plugins under strelka/authprovider" do
35
- described_class.plugin_prefixes.should include( 'strelka/authprovider' )
29
+ expect( described_class.plugin_prefixes ).to include( 'strelka/authprovider' )
36
30
  end
37
31
 
38
32
 
@@ -64,7 +58,7 @@ describe Strelka::AuthProvider do
64
58
 
65
59
  it "returns 'anonymous' as credentials if asked to authenticate" do
66
60
  req = @request_factory.get( '/admin/console' )
67
- @provider.authenticate( req ).should == 'anonymous'
61
+ expect( @provider.authenticate(req) ).to eq( 'anonymous' )
68
62
  end
69
63
 
70
64
  it "has a callback for adding authentication information to the request" do
@@ -2,16 +2,10 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
5
- BEGIN {
6
- require 'pathname'
7
- basedir = Pathname.new( __FILE__ ).dirname.parent.parent
8
-
9
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
- }
5
+ require_relative '../helpers'
11
6
 
12
7
  require 'uri'
13
8
  require 'rspec'
14
- require 'spec/lib/helpers'
15
9
  require 'strelka/cookie'
16
10
 
17
11
 
@@ -30,39 +24,39 @@ describe Strelka::Cookie do
30
24
  end
31
25
 
32
26
  it "parses a 'nil' Cookie header field as an empty Hash" do
33
- Strelka::Cookie.parse( nil ).should == {}
27
+ expect( Strelka::Cookie.parse( nil ) ).to eq( {} )
34
28
  end
35
29
 
36
30
  it "parses an empty string Cookie header field as an empty Hash" do
37
- Strelka::Cookie.parse( '' ).should == {}
31
+ expect( Strelka::Cookie.parse( '' ) ).to eq( {} )
38
32
  end
39
33
 
40
34
  it "parses a cookie header field with a single value as a cookie with a single value" do
41
35
  result = Strelka::Cookie.parse( 'a=b' )
42
36
 
43
- result.should be_a( Hash )
44
- result.should have(1).member
45
- result[:a].should be_a( Strelka::Cookie )
46
- result[:a].name.should == 'a'
47
- result[:a].value.should == 'b'
37
+ expect( result ).to be_a( Hash )
38
+ expect( result ).to have(1).member
39
+ expect( result[:a] ).to be_a( Strelka::Cookie )
40
+ expect( result[:a].name ).to eq( 'a' )
41
+ expect( result[:a].value ).to eq( 'b' )
48
42
  end
49
43
 
50
44
  it "parses a cookie header field with an empty value as a cookie with a nil value" do
51
45
  result = Strelka::Cookie.parse( 'a=' )
52
46
 
53
- result.should have( 1 ).member
54
- result[:a].should be_a( Strelka::Cookie )
55
- result[:a].name.should == 'a'
56
- result[:a].value.should be_nil()
47
+ expect( result ).to have( 1 ).member
48
+ expect( result[:a] ).to be_a( Strelka::Cookie )
49
+ expect( result[:a].name ).to eq( 'a' )
50
+ expect( result[:a].value ).to be_nil()
57
51
  end
58
52
 
59
53
  it "doesn't raise an error if asked to parse an invalid cookie header" do
60
54
  result = Strelka::Cookie.parse( "{a}=foo" )
61
- result.should == {}
55
+ expect( result ).to eq( {} )
62
56
  end
63
57
 
64
58
  it "guards against a nil options hash" do
65
- Strelka::Cookie.new( :name, 'value', nil ).should be_a( Strelka::Cookie )
59
+ expect( Strelka::Cookie.new( :name, 'value', nil ) ).to be_a( Strelka::Cookie )
66
60
  end
67
61
 
68
62
 
@@ -73,28 +67,28 @@ describe Strelka::Cookie do
73
67
  end
74
68
 
75
69
  it "stringifies as a valid header value" do
76
- @cookie.to_s.should == 'by_rickirac=9917eb'
70
+ expect( @cookie.to_s ).to eq( 'by_rickirac=9917eb' )
77
71
  end
78
72
 
79
73
  it "stringifies with a version number if its version is set to something other than 0" do
80
74
  @cookie.version = 1
81
- @cookie.to_s.should =~ /; Version=1/i
75
+ expect( @cookie.to_s ).to match( /; Version=1/i )
82
76
  end
83
77
 
84
78
  it "stringifies with a domain if one is set" do
85
79
  @cookie.domain = 'example.com'
86
- @cookie.to_s.should =~ /; Domain=example.com/
80
+ expect( @cookie.to_s ).to match( /; Domain=example.com/ )
87
81
  end
88
82
 
89
83
  it "stringifies with the leading '.' in the domain" do
90
84
  @cookie.domain = '.example.com'
91
- @cookie.to_s.should =~ /; Domain=example.com/
85
+ expect( @cookie.to_s ).to match( /; Domain=example.com/ )
92
86
  end
93
87
 
94
88
  it "doesn't stringify with a domain if it is reset" do
95
89
  @cookie.domain = 'example.com'
96
90
  @cookie.domain = nil
97
- @cookie.to_s.should_not =~ /; Domain=/
91
+ expect( @cookie.to_s ).to_not match( /; Domain=/ )
98
92
  end
99
93
 
100
94
  it "raises an exception if the cookie value would be invalid when serialized" do
@@ -105,56 +99,56 @@ describe Strelka::Cookie do
105
99
 
106
100
  it "provides a convenience mechanism for setting the value to binary data" do
107
101
  @cookie.binary_value = %{"modern technology"; ain't it a paradox?}
108
- @cookie.to_s.should == 'by_rickirac=Im1vZGVybiB0ZWNobm9sb2d5IjsgYWluJ3Qg' +
109
- 'aXQgYSBwYXJhZG94Pw=='
102
+ expect( @cookie.to_s ).
103
+ to eq( 'by_rickirac=Im1vZGVybiB0ZWNobm9sb2d5IjsgYWluJ3QgaXQgYSBwYXJhZG94Pw==' )
110
104
  end
111
105
 
112
106
  it "stringifies with an expires date if one is set" do
113
107
  @cookie.expires = Time.at( 1331761184 )
114
- @cookie.to_s.should == 'by_rickirac=9917eb; Expires=Wed, 14 Mar 2012 21:39:44 GMT'
108
+ expect( @cookie.to_s ).to eq( 'by_rickirac=9917eb; Expires=Wed, 14 Mar 2012 21:39:44 GMT' )
115
109
  end
116
110
 
117
111
  it "stringifies with a max age if the 'max age' is set" do
118
112
  @cookie.max_age = 3600
119
- @cookie.to_s.should == 'by_rickirac=9917eb; Max-age=3600'
113
+ expect( @cookie.to_s ).to eq( 'by_rickirac=9917eb; Max-age=3600' )
120
114
  end
121
115
 
122
116
  it "stringifies with a Secure flag if secure is set" do
123
117
  @cookie.secure = true
124
- @cookie.to_s.should =~ /; Secure/i
118
+ expect( @cookie.to_s ).to match( /; Secure/i )
125
119
  end
126
120
 
127
121
  it "stringifies with an HttpOnly flag if httponly is set" do
128
122
  @cookie.httponly = true
129
- @cookie.to_s.should =~ /; HttpOnly/i
123
+ expect( @cookie.to_s ).to match( /; HttpOnly/i )
130
124
  end
131
125
 
132
126
  it "stringifies with both Secure and HttpOnly flags if they're both set" do
133
127
  @cookie.httponly = true
134
128
  @cookie.secure = true
135
- @cookie.to_s.should =~ /; HttpOnly/i
136
- @cookie.to_s.should =~ /; Secure/i
129
+ expect( @cookie.to_s ).to match( /; HttpOnly/i )
130
+ expect( @cookie.to_s ).to match( /; Secure/i )
137
131
  end
138
132
 
139
133
  it "hashes the same as another cookie with the same name, regardless of value" do
140
- @cookie.hash.should == Strelka::Cookie.new('by_rickirac', 'something_else').hash
134
+ expect( @cookie.hash ).to eq( Strelka::Cookie.new('by_rickirac', 'something_else').hash )
141
135
  end
142
136
 
143
137
 
144
138
  it "sets its expiration time to a time in the past if it's told to expire" do
145
139
  @cookie.expire!
146
- @cookie.expires.should < Time.now
140
+ expect( @cookie.expires ).to be < Time.now
147
141
  end
148
142
 
149
143
  it "uses the hash of its name as its hash value" do
150
- @cookie.hash.should == @cookie.name.to_s.hash
144
+ expect( @cookie.hash ).to eq( @cookie.name.to_s.hash )
151
145
  end
152
146
 
153
147
  it "can return its options as a Hash" do
154
148
  @cookie.domain = '.example.com'
155
149
  @cookie.secure = true
156
150
 
157
- @cookie.options.should == {
151
+ expect( @cookie.options ).to eq({
158
152
  domain: 'example.com',
159
153
  path: nil,
160
154
  secure: true,
@@ -162,7 +156,7 @@ describe Strelka::Cookie do
162
156
  expires: nil,
163
157
  max_age: nil,
164
158
  version: 0,
165
- }
159
+ })
166
160
  end
167
161
 
168
162
  end