goliath 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of goliath might be problematic. Click here for more details.

Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/goliath.gemspec +11 -7
  4. data/lib/goliath/api.rb +1 -1
  5. data/lib/goliath/connection.rb +15 -11
  6. data/lib/goliath/constants.rb +1 -0
  7. data/lib/goliath/rack/default_response_format.rb +3 -9
  8. data/lib/goliath/rack/formatters/json.rb +1 -1
  9. data/lib/goliath/rack/jsonp.rb +7 -2
  10. data/lib/goliath/rack/params.rb +4 -3
  11. data/lib/goliath/rack/validator.rb +1 -1
  12. data/lib/goliath/request.rb +37 -20
  13. data/lib/goliath/response.rb +2 -0
  14. data/lib/goliath/runner.rb +4 -3
  15. data/lib/goliath/server.rb +17 -2
  16. data/lib/goliath/test_helper_sse.rb +76 -0
  17. data/lib/goliath/validation/error.rb +4 -1
  18. data/lib/goliath/version.rb +1 -1
  19. data/spec/integration/async_request_processing.rb +2 -2
  20. data/spec/integration/chunked_streaming_spec.rb +1 -1
  21. data/spec/integration/early_abort_spec.rb +6 -6
  22. data/spec/integration/echo_spec.rb +7 -7
  23. data/spec/integration/empty_body_spec.rb +2 -2
  24. data/spec/integration/event_stream_spec.rb +50 -0
  25. data/spec/integration/exception_handling_spec.rb +202 -0
  26. data/spec/integration/http_log_spec.rb +16 -16
  27. data/spec/integration/jsonp_spec.rb +61 -10
  28. data/spec/integration/keepalive_spec.rb +2 -2
  29. data/spec/integration/pipelining_spec.rb +3 -3
  30. data/spec/integration/reloader_spec.rb +3 -3
  31. data/spec/integration/template_spec.rb +7 -7
  32. data/spec/integration/test_helper_spec.rb +3 -3
  33. data/spec/integration/trace_spec.rb +2 -2
  34. data/spec/integration/valid_spec.rb +25 -5
  35. data/spec/integration/websocket_spec.rb +2 -2
  36. data/spec/spec_helper.rb +1 -3
  37. data/spec/unit/api_spec.rb +1 -1
  38. data/spec/unit/connection_spec.rb +8 -8
  39. data/spec/unit/console_spec.rb +3 -3
  40. data/spec/unit/env_spec.rb +9 -9
  41. data/spec/unit/headers_spec.rb +8 -8
  42. data/spec/unit/rack/default_mime_type_spec.rb +3 -3
  43. data/spec/unit/rack/formatters/json_spec.rb +35 -13
  44. data/spec/unit/rack/formatters/plist_spec.rb +8 -8
  45. data/spec/unit/rack/formatters/xml_spec.rb +18 -18
  46. data/spec/unit/rack/formatters/yaml_spec.rb +13 -13
  47. data/spec/unit/rack/heartbeat_spec.rb +15 -15
  48. data/spec/unit/rack/params_spec.rb +99 -62
  49. data/spec/unit/rack/render_spec.rb +14 -14
  50. data/spec/unit/rack/validation/boolean_value_spec.rb +6 -6
  51. data/spec/unit/rack/validation/default_params_spec.rb +13 -13
  52. data/spec/unit/rack/validation/numeric_range_spec.rb +17 -17
  53. data/spec/unit/rack/validation/param_spec.rb +75 -75
  54. data/spec/unit/rack/validation/request_method_spec.rb +9 -9
  55. data/spec/unit/rack/validation/required_param_spec.rb +39 -39
  56. data/spec/unit/rack/validation/required_value_spec.rb +19 -19
  57. data/spec/unit/request_spec.rb +18 -18
  58. data/spec/unit/response_spec.rb +6 -6
  59. data/spec/unit/runner_spec.rb +31 -31
  60. data/spec/unit/server_spec.rb +21 -21
  61. data/spec/unit/validation/standard_http_errors_spec.rb +6 -6
  62. metadata +149 -94
  63. data/examples/around.rb +0 -38
  64. data/examples/clone.rb +0 -26
  65. data/examples/router.rb +0 -15
  66. data/examples/test.rb +0 -31
  67. data/examples/upload.rb +0 -17
@@ -8,39 +8,39 @@ describe Goliath::Rack::Validation::Param do
8
8
  end
9
9
 
10
10
  it "should not allow invalid options" do
11
- lambda {
11
+ expect {
12
12
  Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => Class.new})
13
- }.should raise_error
13
+ }.to raise_error(Exception)
14
14
  end
15
15
 
16
16
  it "raises if key is not supplied" do
17
- lambda {
17
+ expect {
18
18
  Goliath::Rack::Validation::Param.new(@app)
19
- }.should raise_error(Exception)
19
+ }.to raise_error(Exception)
20
20
  end
21
21
 
22
22
  it "uses a default value if optional is not supplied" do
23
23
  cv = Goliath::Rack::Validation::Param.new(@app, :key => 'key')
24
- cv.optional.should be_false
24
+ expect(cv.optional).to be false
25
25
  end
26
26
 
27
27
  it "should have default and message be optional" do
28
28
  cv = nil
29
- lambda {
29
+ expect {
30
30
  cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'flag',
31
31
  :as => Goliath::Rack::Types::Boolean})
32
- }.should_not raise_error
32
+ }.not_to raise_error
33
33
 
34
- cv.default.should be_nil
35
- cv.message.should_not be_nil
34
+ expect(cv.default).to be_nil
35
+ expect(cv.message).not_to be_nil
36
36
  end
37
37
 
38
38
  it "should fail if given an invalid option" do
39
39
  cv = nil
40
- lambda {
40
+ expect {
41
41
  cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'flag',
42
42
  :as => Goliath::Rack::Types::Boolean, :animal => :monkey})
43
- }.should raise_error
43
+ }.to raise_error('Unknown options: {:animal=>:monkey}')
44
44
  end
45
45
 
46
46
  context "fetch_key" do
@@ -57,7 +57,7 @@ describe Goliath::Rack::Validation::Param do
57
57
  }
58
58
  }
59
59
  }
60
- @cv.fetch_key(params).should == "mike"
60
+ expect(@cv.fetch_key(params)).to eq("mike")
61
61
  end
62
62
 
63
63
  it "should return nil given an incorrect params" do
@@ -68,7 +68,7 @@ describe Goliath::Rack::Validation::Param do
68
68
  }
69
69
  }
70
70
  }
71
- @cv.fetch_key(params).should be_nil
71
+ expect(@cv.fetch_key(params)).to be_nil
72
72
  end
73
73
 
74
74
  it "should set value if given" do
@@ -79,8 +79,8 @@ describe Goliath::Rack::Validation::Param do
79
79
  }
80
80
  }
81
81
  }
82
- @cv.fetch_key(params, "tim").should == "tim"
83
- params['data']['credentials']['login'].should == "tim"
82
+ expect(@cv.fetch_key(params, "tim")).to eq("tim")
83
+ expect(params['data']['credentials']['login']).to eq("tim")
84
84
  end
85
85
  end
86
86
 
@@ -88,9 +88,9 @@ describe Goliath::Rack::Validation::Param do
88
88
 
89
89
  it 'defaults type and message' do
90
90
  @rp = Goliath::Rack::Validation::Param.new('app', :key => 'key')
91
- @rp.type.should_not be_nil
92
- @rp.type.should_not =~ /^\s*$/
93
- @rp.message.should == 'identifier missing'
91
+ expect(@rp.type).not_to be_nil
92
+ expect(@rp.type).not_to match(/^\s*$/)
93
+ expect(@rp.message).to eq('identifier missing')
94
94
  end
95
95
 
96
96
 
@@ -103,76 +103,76 @@ describe Goliath::Rack::Validation::Param do
103
103
  end
104
104
 
105
105
  it 'stores type and key options' do
106
- @rp.type.should == 'Monkey'
107
- @rp.key.should == 'mk'
106
+ expect(@rp.type).to eq('Monkey')
107
+ expect(@rp.key).to eq('mk')
108
108
  end
109
109
 
110
110
  it 'calls validation_error with a custom message' do
111
- @rp.should_receive(:validation_error).with(anything, 'Monkey is required')
111
+ expect(@rp).to receive(:validation_error).with(anything, 'Monkey is required')
112
112
  @rp.call(@env)
113
113
  end
114
114
 
115
115
  it 'returns the app status, headers and body' do
116
116
  app_headers = {'Content-Type' => 'app'}
117
117
  app_body = {'b' => 'c'}
118
- @app.should_receive(:call).and_return([201, app_headers, app_body])
118
+ expect(@app).to receive(:call).and_return([201, app_headers, app_body])
119
119
 
120
120
  @env['params']['mk'] = 'monkey'
121
121
 
122
122
  status, headers, body = @rp.call(@env)
123
- status.should == 201
124
- headers.should == app_headers
125
- body.should == app_body
123
+ expect(status).to eq(201)
124
+ expect(headers).to eq(app_headers)
125
+ expect(body).to eq(app_body)
126
126
  end
127
127
 
128
128
  context 'key_valid?' do
129
129
  it 'raises exception if the key is not provided' do
130
- @rp.key_valid?(@env['params']).should be_false
130
+ expect(@rp.key_valid?(@env['params'])).to be false
131
131
  end
132
132
 
133
133
  it 'raises exception if the key is blank' do
134
134
  @env['params']['mk'] = ''
135
- @rp.key_valid?(@env['params']).should be_false
135
+ expect(@rp.key_valid?(@env['params'])).to be false
136
136
  end
137
137
 
138
138
  it 'raises exception if the key is nil' do
139
139
  @env['params']['mk'] = nil
140
- @rp.key_valid?(@env['params']).should be_false
140
+ expect(@rp.key_valid?(@env['params'])).to be false
141
141
  end
142
142
 
143
143
  it 'handles an empty array' do
144
144
  @env['params']['mk'] = []
145
- @rp.key_valid?(@env['params']).should be_false
145
+ expect(@rp.key_valid?(@env['params'])).to be false
146
146
  end
147
147
 
148
148
  it 'handles an array of nils' do
149
149
  @env['params']['mk'] = [nil, nil, nil]
150
- @rp.key_valid?(@env['params']).should be_false
150
+ expect(@rp.key_valid?(@env['params'])).to be false
151
151
  end
152
152
 
153
153
  it 'handles an array of blanks' do
154
154
  @env['params']['mk'] = ['', '', '']
155
- @rp.key_valid?(@env['params']).should be_false
155
+ expect(@rp.key_valid?(@env['params'])).to be false
156
156
  end
157
157
 
158
158
  it "doesn't raise if the key provided" do
159
159
  @env['params']['mk'] = 'my value'
160
- @rp.key_valid?(@env['params']).should be_true
160
+ expect(@rp.key_valid?(@env['params'])).to be true
161
161
  end
162
162
 
163
163
  it "doesn't raise if the array contains valid data" do
164
164
  @env['params']['mk'] = [1, 2, 3, 4]
165
- @rp.key_valid?(@env['params']).should be_true
165
+ expect(@rp.key_valid?(@env['params'])).to be true
166
166
  end
167
167
 
168
168
  it "doesn't raise if the key provided is multiline and has blanks" do
169
169
  @env['params']['mk'] = "my\n \nvalue"
170
- @rp.key_valid?(@env['params']).should be_true
170
+ expect(@rp.key_valid?(@env['params'])).to be true
171
171
  end
172
172
 
173
173
  it "doesn't raise if the key provided is an array and contains multiline with blanks" do
174
174
  @env['params']['mk'] = ["my\n \nvalue", "my\n \nother\n \nvalue"]
175
- @rp.key_valid?(@env['params']).should be_true
175
+ expect(@rp.key_valid?(@env['params'])).to be true
176
176
  end
177
177
  end
178
178
  end
@@ -194,7 +194,7 @@ describe Goliath::Rack::Validation::Param do
194
194
  }
195
195
  }
196
196
 
197
- @rp.key_valid?(@env['params']).should be_false
197
+ expect(@rp.key_valid?(@env['params'])).to be false
198
198
  end
199
199
 
200
200
  it "return true if key is present" do
@@ -205,7 +205,7 @@ describe Goliath::Rack::Validation::Param do
205
205
  }
206
206
  }
207
207
 
208
- @rp.key_valid?(@env['params']).should be_true
208
+ expect(@rp.key_valid?(@env['params'])).to be true
209
209
  end
210
210
  end
211
211
 
@@ -225,7 +225,7 @@ describe Goliath::Rack::Validation::Param do
225
225
  }
226
226
  }
227
227
 
228
- @rp.key_valid?(@env['params']).should be_false
228
+ expect(@rp.key_valid?(@env['params'])).to be false
229
229
  end
230
230
 
231
231
  it "return true if key is present" do
@@ -236,7 +236,7 @@ describe Goliath::Rack::Validation::Param do
236
236
  }
237
237
  }
238
238
 
239
- @rp.key_valid?(@env['params']).should be_true
239
+ expect(@rp.key_valid?(@env['params'])).to be true
240
240
  end
241
241
  end
242
242
 
@@ -245,9 +245,9 @@ describe Goliath::Rack::Validation::Param do
245
245
  context "Coerce" do
246
246
 
247
247
  it "should only accept a class in the :as" do
248
- lambda {
248
+ expect {
249
249
  Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => "not a class"})
250
- }.should raise_error
250
+ }.to raise_error('Params as must be a class')
251
251
  end
252
252
 
253
253
  context 'with middleware' do
@@ -266,7 +266,7 @@ describe Goliath::Rack::Validation::Param do
266
266
  @env['params']['user'] = value.first
267
267
  cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => type})
268
268
  cv.call(@env)
269
- @env['params']['user'].should == value[1]
269
+ expect(@env['params']['user']).to eq(value[1])
270
270
  end
271
271
  end
272
272
  end
@@ -282,9 +282,9 @@ describe Goliath::Rack::Validation::Param do
282
282
  @env['params']['user'] = value
283
283
  cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => type})
284
284
  result = cv.call(@env)
285
- result.should be_an_instance_of(Array)
286
- result.first.should == 400
287
- result.last.should have_key(:error)
285
+ expect(result).to be_an_instance_of(Array)
286
+ expect(result.first).to eq(400)
287
+ expect(result.last).to have_key(:error)
288
288
  end
289
289
  end
290
290
  end
@@ -292,10 +292,10 @@ describe Goliath::Rack::Validation::Param do
292
292
  it "should not fail with a invalid input, given a default value" do
293
293
  cv = nil
294
294
  @env['params']['user'] = "boo"
295
- lambda {
295
+ expect {
296
296
  cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'user',
297
297
  :as => Goliath::Rack::Types::Boolean , :default => 'default'})
298
- }.should_not raise_error
298
+ }.not_to raise_error
299
299
  @env['params']['user'] = 'default'
300
300
  end
301
301
 
@@ -305,10 +305,10 @@ describe Goliath::Rack::Validation::Param do
305
305
  :as => Goliath::Rack::Types::Integer, :message => "custom message"})
306
306
 
307
307
  result = cv.call(@env)
308
- result.should be_an_instance_of(Array)
309
- result.first.should == 400
310
- result.last.should have_key(:error)
311
- result.last[:error].should == "custom message"
308
+ expect(result).to be_an_instance_of(Array)
309
+ expect(result.first).to eq(400)
310
+ expect(result.last).to have_key(:error)
311
+ expect(result.last[:error]).to eq("custom message")
312
312
  end
313
313
  end
314
314
 
@@ -320,15 +320,15 @@ describe Goliath::Rack::Validation::Param do
320
320
  :as => Goliath::Rack::Types::Integer
321
321
  @env['params']['login'] = "3"
322
322
  cv.call(@env)
323
- @env['params']['login'].should == 3
323
+ expect(@env['params']['login']).to eq(3)
324
324
 
325
325
  @env['params']['login'] = nil
326
326
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login",
327
327
  :as => Goliath::Rack::Types::Integer
328
328
  result = cv.call(@env)
329
- result.should be_an_instance_of(Array)
330
- result.first.should == 400
331
- result.last.should have_key(:error)
329
+ expect(result).to be_an_instance_of(Array)
330
+ expect(result.first).to eq(400)
331
+ expect(result.last).to have_key(:error)
332
332
  end
333
333
 
334
334
  it "should do required param + coerce (nested)" do
@@ -337,30 +337,30 @@ describe Goliath::Rack::Validation::Param do
337
337
  @env['params']['login'] = {}
338
338
  @env['params']['login']['other'] = "3"
339
339
  cv.call(@env)
340
- @env['params']['login']['other'].should == 3
340
+ expect(@env['params']['login']['other']).to eq(3)
341
341
 
342
342
  @env['params']['login'] = {}
343
343
  @env['params']['login']['other'] = nil
344
344
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login.other",
345
345
  :as => Goliath::Rack::Types::Integer
346
346
  result = cv.call(@env)
347
- result.should be_an_instance_of(Array)
348
- result.first.should == 400
349
- result.last.should have_key(:error)
347
+ expect(result).to be_an_instance_of(Array)
348
+ expect(result.first).to eq(400)
349
+ expect(result.last).to have_key(:error)
350
350
  end
351
351
 
352
352
  it "should do required param + not coerce (not nested)" do
353
353
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login"
354
354
  @env['params']['login'] = "3"
355
355
  cv.call(@env)
356
- @env['params']['login'].should == "3"
356
+ expect(@env['params']['login']).to eq("3")
357
357
 
358
358
  @env['params']['login'] = nil
359
359
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login"
360
360
  result = cv.call(@env)
361
- result.should be_an_instance_of(Array)
362
- result.first.should == 400
363
- result.last.should have_key(:error)
361
+ expect(result).to be_an_instance_of(Array)
362
+ expect(result.first).to eq(400)
363
+ expect(result.last).to have_key(:error)
364
364
  end
365
365
 
366
366
  it "should do required param + not coerce (nested)" do
@@ -368,15 +368,15 @@ describe Goliath::Rack::Validation::Param do
368
368
  @env['params']['login'] = {}
369
369
  @env['params']['login']['other'] = "3"
370
370
  cv.call(@env)
371
- @env['params']['login']['other'].should == "3"
371
+ expect(@env['params']['login']['other']).to eq("3")
372
372
 
373
373
  @env['params']['login'] = {}
374
374
  @env['params']['login']['other'] = nil
375
375
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login.other"
376
376
  result = cv.call(@env)
377
- result.should be_an_instance_of(Array)
378
- result.first.should == 400
379
- result.last.should have_key(:error)
377
+ expect(result).to be_an_instance_of(Array)
378
+ expect(result.first).to eq(400)
379
+ expect(result.last).to have_key(:error)
380
380
  end
381
381
 
382
382
  it "should do optional param + coerce (not nested)" do
@@ -384,13 +384,13 @@ describe Goliath::Rack::Validation::Param do
384
384
  :as => Goliath::Rack::Types::Integer, :optional => true
385
385
  @env['params']['login'] = "3"
386
386
  cv.call(@env)
387
- @env['params']['login'].should == 3
387
+ expect(@env['params']['login']).to eq(3)
388
388
 
389
389
  @env['params']['login'] = nil
390
390
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login",
391
391
  :as => Goliath::Rack::Types::Integer, :optional => true
392
392
  result = cv.call(@env)
393
- result.should_not be_an_instance_of(Array) #implying its OK
393
+ expect(result).not_to be_an_instance_of(Array) #implying its OK
394
394
  end
395
395
 
396
396
  it "should do optional param + coerce (nested)" do
@@ -399,14 +399,14 @@ describe Goliath::Rack::Validation::Param do
399
399
  @env['params']['login'] = {}
400
400
  @env['params']['login']['other'] = "3"
401
401
  cv.call(@env)
402
- @env['params']['login']['other'].should == 3
402
+ expect(@env['params']['login']['other']).to eq(3)
403
403
 
404
404
  @env['params']['login'] = {}
405
405
  @env['params']['login']['other'] = nil
406
406
  cv = Goliath::Rack::Validation::Param.new @app, :key => ['login', 'other'],
407
407
  :as => Goliath::Rack::Types::Integer, :optional => true
408
408
  result = cv.call(@env)
409
- result.should_not be_an_instance_of(Array) #implying its OK
409
+ expect(result).not_to be_an_instance_of(Array) #implying its OK
410
410
  end
411
411
 
412
412
  it "should do optional param and not coerce (not nested)" do
@@ -414,13 +414,13 @@ describe Goliath::Rack::Validation::Param do
414
414
  :optional => true
415
415
  @env['params']['login'] = "3"
416
416
  cv.call(@env)
417
- @env['params']['login'].should == "3"
417
+ expect(@env['params']['login']).to eq("3")
418
418
 
419
419
  @env['params']['login'] = nil
420
420
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login",
421
421
  :optional => true
422
422
  result = cv.call(@env)
423
- result.should_not be_an_instance_of(Array) #implying its OK
423
+ expect(result).not_to be_an_instance_of(Array) #implying its OK
424
424
  end
425
425
 
426
426
  it "should do optional param and not coerce (nested)" do
@@ -429,14 +429,14 @@ describe Goliath::Rack::Validation::Param do
429
429
  @env['params']['login'] = {}
430
430
  @env['params']['login']['other'] = "3"
431
431
  cv.call(@env)
432
- @env['params']['login']['other'].should == "3"
432
+ expect(@env['params']['login']['other']).to eq("3")
433
433
 
434
434
  @env['params']['login'] = {}
435
435
  @env['params']['login']['other'] = nil
436
436
  cv = Goliath::Rack::Validation::Param.new @app, :key => "login.other",
437
437
  :optional => true
438
438
  result = cv.call(@env)
439
- result.should_not be_an_instance_of(Array) #implying its OK
439
+ expect(result).not_to be_an_instance_of(Array) #implying its OK
440
440
  end
441
441
  end
442
442
  end
@@ -7,11 +7,11 @@ describe Goliath::Rack::Validation::RequestMethod do
7
7
  @app_body = {'a' => 'b'}
8
8
 
9
9
  @app = double('app').as_null_object
10
- @app.stub(:call).and_return([200, @app_headers, @app_body])
10
+ allow(@app).to receive(:call).and_return([200, @app_headers, @app_body])
11
11
  end
12
12
 
13
13
  it 'accepts an app' do
14
- lambda { Goliath::Rack::Validation::RequestMethod.new('my app') }.should_not raise_error
14
+ expect { Goliath::Rack::Validation::RequestMethod.new('my app') }.not_to raise_error
15
15
  end
16
16
 
17
17
  describe 'with defaults' do
@@ -22,31 +22,31 @@ describe Goliath::Rack::Validation::RequestMethod do
22
22
 
23
23
  it 'raises error if method is invalid' do
24
24
  @env['REQUEST_METHOD'] = 'fubar'
25
- @rm.call(@env).should == [405, {'Allow' => 'GET, POST'}, {:error => "Invalid request method"}]
25
+ expect(@rm.call(@env)).to eq([405, {'Allow' => 'GET, POST'}, {:error => "Invalid request method"}])
26
26
  end
27
27
 
28
28
  it 'allows valid methods through' do
29
29
  @env['REQUEST_METHOD'] = 'GET'
30
- @rm.call(@env).should == [200, @app_headers, @app_body]
30
+ expect(@rm.call(@env)).to eq([200, @app_headers, @app_body])
31
31
  end
32
32
 
33
33
  it 'returns app status, headers and body' do
34
34
  @env['REQUEST_METHOD'] = 'POST'
35
35
 
36
36
  status, headers, body = @rm.call(@env)
37
- status.should == 200
38
- headers.should == @app_headers
39
- body.should == @app_body
37
+ expect(status).to eq(200)
38
+ expect(headers).to eq(@app_headers)
39
+ expect(body).to eq(@app_body)
40
40
  end
41
41
  end
42
42
 
43
43
  it 'accepts methods on initialize' do
44
44
  rm = Goliath::Rack::Validation::RequestMethod.new('my app', ['GET', 'DELETE', 'HEAD'])
45
- rm.methods.should == ['GET', 'DELETE', 'HEAD']
45
+ expect(rm.methods).to eq(['GET', 'DELETE', 'HEAD'])
46
46
  end
47
47
 
48
48
  it 'accepts string method on initialize' do
49
49
  rm = Goliath::Rack::Validation::RequestMethod.new('my app', 'GET')
50
- rm.methods.should == ['GET']
50
+ expect(rm.methods).to eq(['GET'])
51
51
  end
52
52
  end
@@ -3,23 +3,23 @@ require 'goliath/rack/validation/required_param'
3
3
 
4
4
  describe Goliath::Rack::Validation::RequiredParam do
5
5
  it 'accepts an app' do
6
- lambda { Goliath::Rack::Validation::RequiredParam.new('my app') }.should_not raise_error
6
+ expect { Goliath::Rack::Validation::RequiredParam.new('my app') }.not_to raise_error
7
7
  end
8
8
 
9
9
  it 'accepts options on create' do
10
10
  opts = { :type => 1, :key => 2, :message => 'is required' }
11
- lambda { Goliath::Rack::Validation::RequiredParam.new('my app', opts) }.should_not raise_error
11
+ expect { Goliath::Rack::Validation::RequiredParam.new('my app', opts) }.not_to raise_error
12
12
  end
13
13
 
14
14
  it 'defaults type, key and message' do
15
15
  @rp = Goliath::Rack::Validation::RequiredParam.new('app')
16
- @rp.key.should_not be_nil
17
- @rp.key.should_not =~ /^\s*$/
16
+ expect(@rp.key).not_to be_nil
17
+ expect(@rp.key).not_to match(/^\s*$/)
18
18
 
19
- @rp.type.should_not be_nil
20
- @rp.type.should_not =~ /^\s*$/
19
+ expect(@rp.type).not_to be_nil
20
+ expect(@rp.type).not_to match(/^\s*$/)
21
21
 
22
- @rp.message.should == 'identifier missing'
22
+ expect(@rp.message).to eq('identifier missing')
23
23
  end
24
24
 
25
25
  describe 'with middleware' do
@@ -30,80 +30,80 @@ describe Goliath::Rack::Validation::RequiredParam do
30
30
  end
31
31
 
32
32
  it 'stores type and key options' do
33
- @rp.type.should == 'Monkey'
34
- @rp.key.should == 'mk'
33
+ expect(@rp.type).to eq('Monkey')
34
+ expect(@rp.key).to eq('mk')
35
35
  end
36
36
 
37
37
  it 'calls validation_error with a custom message' do
38
- @rp.should_receive(:validation_error).with(anything, 'Monkey is required')
38
+ expect(@rp).to receive(:validation_error).with(anything, 'Monkey is required')
39
39
  @rp.call(@env)
40
40
  end
41
41
 
42
42
  it 'returns the app status, headers and body' do
43
43
  app_headers = {'Content-Type' => 'app'}
44
44
  app_body = {'b' => 'c'}
45
- @app.should_receive(:call).and_return([201, app_headers, app_body])
45
+ expect(@app).to receive(:call).and_return([201, app_headers, app_body])
46
46
 
47
47
  @env['params']['mk'] = 'monkey'
48
48
 
49
49
  status, headers, body = @rp.call(@env)
50
- status.should == 201
51
- headers.should == app_headers
52
- body.should == app_body
50
+ expect(status).to eq(201)
51
+ expect(headers).to eq(app_headers)
52
+ expect(body).to eq(app_body)
53
53
  end
54
54
 
55
55
  describe 'key_valid?' do
56
56
  it 'raises exception if the key is not provided' do
57
- @rp.key_valid?(@env['params']).should be_false
57
+ expect(@rp.key_valid?(@env['params'])).to be false
58
58
  end
59
59
 
60
60
  it 'raises exception if the key is blank' do
61
61
  @env['params']['mk'] = ''
62
- @rp.key_valid?(@env['params']).should be_false
62
+ expect(@rp.key_valid?(@env['params'])).to be false
63
63
  end
64
64
 
65
65
  it 'raises exception if the key is nil' do
66
66
  @env['params']['mk'] = nil
67
- @rp.key_valid?(@env['params']).should be_false
67
+ expect(@rp.key_valid?(@env['params'])).to be false
68
68
  end
69
69
 
70
70
  it 'handles an empty array' do
71
71
  @env['params']['mk'] = []
72
- @rp.key_valid?(@env['params']).should be_false
72
+ expect(@rp.key_valid?(@env['params'])).to be false
73
73
  end
74
74
 
75
75
  it 'handles an array of nils' do
76
76
  @env['params']['mk'] = [nil, nil, nil]
77
- @rp.key_valid?(@env['params']).should be_false
77
+ expect(@rp.key_valid?(@env['params'])).to be false
78
78
  end
79
79
 
80
80
  it 'handles an array of blanks' do
81
81
  @env['params']['mk'] = ['', '', '']
82
- @rp.key_valid?(@env['params']).should be_false
82
+ expect(@rp.key_valid?(@env['params'])).to be false
83
83
  end
84
84
 
85
85
  it "doesn't raise if the key provided" do
86
86
  @env['params']['mk'] = 'my value'
87
- @rp.key_valid?(@env['params']).should be_true
87
+ expect(@rp.key_valid?(@env['params'])).to be true
88
88
  end
89
89
 
90
90
  it "doesn't raise if the array contains valid data" do
91
91
  @env['params']['mk'] = [1, 2, 3, 4]
92
- @rp.key_valid?(@env['params']).should be_true
92
+ expect(@rp.key_valid?(@env['params'])).to be true
93
93
  end
94
94
 
95
95
  it "doesn't raise if the key provided is multiline and has blanks" do
96
96
  @env['params']['mk'] = "my\n \nvalue"
97
- @rp.key_valid?(@env['params']).should be_true
97
+ expect(@rp.key_valid?(@env['params'])).to be true
98
98
  end
99
99
 
100
100
  it "doesn't raise if the key provided is an array and contains multiline with blanks" do
101
101
  @env['params']['mk'] = ["my\n \nvalue", "my\n \nother\n \nvalue"]
102
- @rp.key_valid?(@env['params']).should be_true
103
- end
102
+ expect(@rp.key_valid?(@env['params'])).to be true
103
+ end
104
104
  end
105
105
  end
106
-
106
+
107
107
  describe 'Nested keys tests' do
108
108
  before do
109
109
  @app = double('app').as_null_object
@@ -122,10 +122,10 @@ describe Goliath::Rack::Validation::RequiredParam do
122
122
  'pass' => "password"}
123
123
  }
124
124
  }
125
-
126
- @rp.key_valid?(@env['params']).should be_false
125
+
126
+ expect(@rp.key_valid?(@env['params'])).to be false
127
127
  end
128
-
128
+
129
129
  it "return true if key is present" do
130
130
  @env['params'] = {'data' => {
131
131
  'credentials' => {
@@ -133,11 +133,11 @@ describe Goliath::Rack::Validation::RequiredParam do
133
133
  'pass' => "password"}
134
134
  }
135
135
  }
136
-
137
- @rp.key_valid?(@env['params']).should be_true
136
+
137
+ expect(@rp.key_valid?(@env['params'])).to be true
138
138
  end
139
139
  end
140
-
140
+
141
141
  describe 'Nested keys tests (with string)' do
142
142
  before do
143
143
  @app = double('app').as_null_object
@@ -156,10 +156,10 @@ describe Goliath::Rack::Validation::RequiredParam do
156
156
  'pass' => "password"}
157
157
  }
158
158
  }
159
-
160
- @rp.key_valid?(@env['params']).should be_false
159
+
160
+ expect(@rp.key_valid?(@env['params'])).to be false
161
161
  end
162
-
162
+
163
163
  it "return true if key is present" do
164
164
  @env['params'] = {'data' => {
165
165
  'credentials' => {
@@ -167,10 +167,10 @@ describe Goliath::Rack::Validation::RequiredParam do
167
167
  'pass' => "password"}
168
168
  }
169
169
  }
170
-
171
- @rp.key_valid?(@env['params']).should be_true
170
+
171
+ expect(@rp.key_valid?(@env['params'])).to be true
172
172
  end
173
173
  end
174
-
175
-
174
+
175
+
176
176
  end