grape 0.7.0 → 0.8.0

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

Potentially problematic release.


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

Files changed (62) hide show
  1. checksums.yaml +5 -13
  2. data/.rubocop.yml +6 -6
  3. data/.travis.yml +11 -2
  4. data/CHANGELOG.md +23 -1
  5. data/Gemfile +11 -10
  6. data/Guardfile +5 -6
  7. data/README.md +194 -13
  8. data/UPGRADING.md +3 -3
  9. data/grape.gemspec +1 -1
  10. data/grape.png +0 -0
  11. data/lib/grape/api.rb +21 -13
  12. data/lib/grape/endpoint.rb +31 -13
  13. data/lib/grape/exceptions/validation.rb +2 -2
  14. data/lib/grape/locale/en.yml +2 -0
  15. data/lib/grape/middleware/auth/oauth2.rb +69 -65
  16. data/lib/grape/middleware/error.rb +4 -2
  17. data/lib/grape/middleware/formatter.rb +2 -2
  18. data/lib/grape/middleware/versioner/accept_version_header.rb +1 -1
  19. data/lib/grape/middleware/versioner/header.rb +3 -3
  20. data/lib/grape/util/hash_stack.rb +1 -1
  21. data/lib/grape/validations.rb +22 -8
  22. data/lib/grape/validations/default.rb +1 -1
  23. data/lib/grape/validations/exactly_one_of.rb +26 -0
  24. data/lib/grape/validations/mutual_exclusion.rb +25 -0
  25. data/lib/grape/validations/presence.rb +1 -1
  26. data/lib/grape/validations/regexp.rb +2 -1
  27. data/lib/grape/validations/values.rb +7 -1
  28. data/lib/grape/version.rb +1 -1
  29. data/spec/grape/api_spec.rb +390 -333
  30. data/spec/grape/endpoint_spec.rb +129 -99
  31. data/spec/grape/entity_spec.rb +47 -27
  32. data/spec/grape/exceptions/invalid_formatter_spec.rb +1 -1
  33. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -1
  34. data/spec/grape/exceptions/missing_mime_type_spec.rb +2 -2
  35. data/spec/grape/exceptions/missing_option_spec.rb +1 -1
  36. data/spec/grape/exceptions/unknown_options_spec.rb +1 -1
  37. data/spec/grape/exceptions/unknown_validator_spec.rb +1 -1
  38. data/spec/grape/middleware/auth/basic_spec.rb +3 -3
  39. data/spec/grape/middleware/auth/digest_spec.rb +4 -4
  40. data/spec/grape/middleware/auth/oauth2_spec.rb +11 -11
  41. data/spec/grape/middleware/base_spec.rb +9 -9
  42. data/spec/grape/middleware/error_spec.rb +4 -4
  43. data/spec/grape/middleware/exception_spec.rb +17 -17
  44. data/spec/grape/middleware/formatter_spec.rb +38 -38
  45. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +11 -11
  46. data/spec/grape/middleware/versioner/header_spec.rb +39 -39
  47. data/spec/grape/middleware/versioner/param_spec.rb +10 -10
  48. data/spec/grape/middleware/versioner/path_spec.rb +7 -7
  49. data/spec/grape/middleware/versioner_spec.rb +4 -4
  50. data/spec/grape/path_spec.rb +6 -6
  51. data/spec/grape/util/hash_stack_spec.rb +22 -22
  52. data/spec/grape/validations/coerce_spec.rb +34 -34
  53. data/spec/grape/validations/default_spec.rb +16 -16
  54. data/spec/grape/validations/exactly_one_of_spec.rb +71 -0
  55. data/spec/grape/validations/mutual_exclusion_spec.rb +61 -0
  56. data/spec/grape/validations/presence_spec.rb +34 -34
  57. data/spec/grape/validations/regexp_spec.rb +11 -4
  58. data/spec/grape/validations/values_spec.rb +34 -20
  59. data/spec/grape/validations_spec.rb +300 -147
  60. data/spec/shared/versioning_examples.rb +18 -18
  61. data/spec/spec_helper.rb +2 -1
  62. metadata +81 -38
@@ -7,13 +7,44 @@ describe Grape::Endpoint do
7
7
  subject
8
8
  end
9
9
 
10
+ describe '.before_each' do
11
+ after { Grape::Endpoint.before_each(nil) }
12
+
13
+ it 'should be settable via block' do
14
+ block = lambda { |endpoint| "noop" }
15
+ Grape::Endpoint.before_each(&block)
16
+ expect(Grape::Endpoint.before_each).to eq(block)
17
+ end
18
+
19
+ it 'should be settable via reference' do
20
+ block = lambda { |endpoint| "noop" }
21
+ Grape::Endpoint.before_each block
22
+ expect(Grape::Endpoint.before_each).to eq(block)
23
+ end
24
+
25
+ it 'should be able to override a helper' do
26
+ subject.get("/") { current_user }
27
+ expect { get '/' }.to raise_error(NameError)
28
+
29
+ Grape::Endpoint.before_each do |endpoint|
30
+ endpoint.stub(:current_user).and_return("Bob")
31
+ end
32
+
33
+ get '/'
34
+ expect(last_response.body).to eq("Bob")
35
+
36
+ Grape::Endpoint.before_each(nil)
37
+ expect { get '/' }.to raise_error(NameError)
38
+ end
39
+ end
40
+
10
41
  describe '#initialize' do
11
42
  it 'takes a settings stack, options, and a block' do
12
43
  p = proc {}
13
44
  expect {
14
45
  Grape::Endpoint.new(Grape::Util::HashStack.new, {
15
- path: '/',
16
- method: :get
46
+ path: '/',
47
+ method: :get
17
48
  }, &p)
18
49
  }.not_to raise_error
19
50
  end
@@ -22,7 +53,7 @@ describe Grape::Endpoint do
22
53
  it 'sets itself in the env upon call' do
23
54
  subject.get('/') { "Hello world." }
24
55
  get '/'
25
- last_request.env['api.endpoint'].should be_kind_of(Grape::Endpoint)
56
+ expect(last_request.env['api.endpoint']).to be_kind_of(Grape::Endpoint)
26
57
  end
27
58
 
28
59
  describe '#status' do
@@ -33,8 +64,8 @@ describe Grape::Endpoint do
33
64
  end
34
65
 
35
66
  get '/home'
36
- last_response.status.should == 206
37
- last_response.body.should == "Hello"
67
+ expect(last_response.status).to eq(206)
68
+ expect(last_response.body).to eq("Hello")
38
69
  end
39
70
  end
40
71
 
@@ -46,7 +77,7 @@ describe Grape::Endpoint do
46
77
  end
47
78
 
48
79
  get '/hey'
49
- last_response.headers['X-Awesome'].should == 'true'
80
+ expect(last_response.headers['X-Awesome']).to eq('true')
50
81
  end
51
82
  end
52
83
 
@@ -58,20 +89,20 @@ describe Grape::Endpoint do
58
89
  end
59
90
  it 'includes request headers' do
60
91
  get '/headers'
61
- JSON.parse(last_response.body).should == {
62
- "Host" => "example.org",
63
- "Cookie" => ""
64
- }
92
+ expect(JSON.parse(last_response.body)).to eq(
93
+ "Host" => "example.org",
94
+ "Cookie" => ""
95
+ )
65
96
  end
66
97
  it 'includes additional request headers' do
67
98
  get '/headers', nil, "HTTP_X_GRAPE_CLIENT" => "1"
68
- JSON.parse(last_response.body)["X-Grape-Client"].should == "1"
99
+ expect(JSON.parse(last_response.body)["X-Grape-Client"]).to eq("1")
69
100
  end
70
101
  it 'includes headers passed as symbols' do
71
102
  env = Rack::MockRequest.env_for("/headers")
72
103
  env["HTTP_SYMBOL_HEADER".to_sym] = "Goliath passes symbols"
73
104
  body = subject.call(env)[2].body.first
74
- JSON.parse(body)["Symbol-Header"].should == "Goliath passes symbols"
105
+ expect(JSON.parse(body)["Symbol-Header"]).to eq("Goliath passes symbols")
75
106
  end
76
107
  end
77
108
 
@@ -80,10 +111,10 @@ describe Grape::Endpoint do
80
111
  subject.get('/get/cookies') do
81
112
  cookies['my-awesome-cookie1'] = 'is cool'
82
113
  cookies['my-awesome-cookie2'] = {
83
- value: 'is cool too',
84
- domain: 'my.example.com',
85
- path: '/',
86
- secure: true,
114
+ value: 'is cool too',
115
+ domain: 'my.example.com',
116
+ path: '/',
117
+ secure: true
87
118
  }
88
119
  cookies[:cookie3] = 'symbol'
89
120
  cookies['cookie4'] = 'secret code here'
@@ -91,7 +122,7 @@ describe Grape::Endpoint do
91
122
 
92
123
  get('/get/cookies')
93
124
 
94
- last_response.headers['Set-Cookie'].split("\n").sort.should eql [
125
+ expect(last_response.headers['Set-Cookie'].split("\n").sort).to eql [
95
126
  "cookie3=symbol",
96
127
  "cookie4=secret+code+here",
97
128
  "my-awesome-cookie1=is+cool",
@@ -105,9 +136,8 @@ describe Grape::Endpoint do
105
136
  end
106
137
  get('/username', {}, 'HTTP_COOKIE' => 'username=mrplum; sandbox=true')
107
138
 
108
- last_response.body.should == 'mrplum'
109
- last_response.headers['Set-Cookie'].should_not =~ /username=mrplum/
110
- last_response.headers['Set-Cookie'].should_not =~ /sandbox=true/
139
+ expect(last_response.body).to eq('mrplum')
140
+ expect(last_response.headers['Set-Cookie']).to be_nil
111
141
  end
112
142
 
113
143
  it 'sets and update browser cookies' do
@@ -116,9 +146,9 @@ describe Grape::Endpoint do
116
146
  cookies[:username] += "_test"
117
147
  end
118
148
  get('/username', {}, 'HTTP_COOKIE' => 'username=user; sandbox=false')
119
- last_response.body.should == 'user_test'
120
- last_response.headers['Set-Cookie'].should =~ /username=user_test/
121
- last_response.headers['Set-Cookie'].should =~ /sandbox=true/
149
+ expect(last_response.body).to eq('user_test')
150
+ expect(last_response.headers['Set-Cookie']).to match(/username=user_test/)
151
+ expect(last_response.headers['Set-Cookie']).to match(/sandbox=true/)
122
152
  end
123
153
 
124
154
  it 'deletes cookie' do
@@ -131,17 +161,17 @@ describe Grape::Endpoint do
131
161
  sum
132
162
  end
133
163
  get '/test', {}, 'HTTP_COOKIE' => 'delete_this_cookie=1; and_this=2'
134
- last_response.body.should == '3'
164
+ expect(last_response.body).to eq('3')
135
165
  cookies = Hash[last_response.headers['Set-Cookie'].split("\n").map do |set_cookie|
136
166
  cookie = CookieJar::Cookie.from_set_cookie 'http://localhost/test', set_cookie
137
167
  [cookie.name, cookie]
138
168
  end]
139
- cookies.size.should == 2
169
+ expect(cookies.size).to eq(2)
140
170
  ["and_this", "delete_this_cookie"].each do |cookie_name|
141
171
  cookie = cookies[cookie_name]
142
- cookie.should_not be_nil
143
- cookie.value.should == "deleted"
144
- cookie.expired?.should be true
172
+ expect(cookie).not_to be_nil
173
+ expect(cookie.value).to eq("deleted")
174
+ expect(cookie.expired?).to be true
145
175
  end
146
176
  end
147
177
 
@@ -155,18 +185,18 @@ describe Grape::Endpoint do
155
185
  sum
156
186
  end
157
187
  get('/test', {}, 'HTTP_COOKIE' => 'delete_this_cookie=1; and_this=2')
158
- last_response.body.should == '3'
188
+ expect(last_response.body).to eq('3')
159
189
  cookies = Hash[last_response.headers['Set-Cookie'].split("\n").map do |set_cookie|
160
190
  cookie = CookieJar::Cookie.from_set_cookie 'http://localhost/test', set_cookie
161
191
  [cookie.name, cookie]
162
192
  end]
163
- cookies.size.should == 2
193
+ expect(cookies.size).to eq(2)
164
194
  ["and_this", "delete_this_cookie"].each do |cookie_name|
165
195
  cookie = cookies[cookie_name]
166
- cookie.should_not be_nil
167
- cookie.value.should == "deleted"
168
- cookie.path.should == "/test"
169
- cookie.expired?.should be true
196
+ expect(cookie).not_to be_nil
197
+ expect(cookie.value).to eq("deleted")
198
+ expect(cookie.path).to eq("/test")
199
+ expect(cookie.expired?).to be true
170
200
  end
171
201
  end
172
202
  end
@@ -190,7 +220,7 @@ describe Grape::Endpoint do
190
220
  end
191
221
 
192
222
  get '/declared?first=present'
193
- last_response.status.should == 200
223
+ expect(last_response.status).to eq(200)
194
224
  end
195
225
 
196
226
  it 'has a optional param with default value all the time' do
@@ -200,7 +230,7 @@ describe Grape::Endpoint do
200
230
  end
201
231
 
202
232
  get '/declared?first=one'
203
- last_response.status.should == 200
233
+ expect(last_response.status).to eq(200)
204
234
  end
205
235
 
206
236
  it 'builds nested params' do
@@ -210,7 +240,7 @@ describe Grape::Endpoint do
210
240
  end
211
241
 
212
242
  get '/declared?first=present&nested[fourth]=1'
213
- last_response.status.should == 200
243
+ expect(last_response.status).to eq(200)
214
244
  end
215
245
 
216
246
  it 'builds nested params when given array' do
@@ -230,7 +260,7 @@ describe Grape::Endpoint do
230
260
  end
231
261
 
232
262
  get '/declared?first=present&nested[][fourth]=1&nested[][fourth]=2'
233
- last_response.status.should == 200
263
+ expect(last_response.status).to eq(200)
234
264
  end
235
265
 
236
266
  it 'filters out any additional params that are given' do
@@ -240,7 +270,7 @@ describe Grape::Endpoint do
240
270
  end
241
271
 
242
272
  get '/declared?first=one&other=two'
243
- last_response.status.should == 200
273
+ expect(last_response.status).to eq(200)
244
274
  end
245
275
 
246
276
  it 'stringifies if that option is passed' do
@@ -250,7 +280,7 @@ describe Grape::Endpoint do
250
280
  end
251
281
 
252
282
  get '/declared?first=one&other=two'
253
- last_response.status.should == 200
283
+ expect(last_response.status).to eq(200)
254
284
  end
255
285
 
256
286
  it 'does not include missing attributes if that option is passed' do
@@ -260,7 +290,7 @@ describe Grape::Endpoint do
260
290
  end
261
291
 
262
292
  get '/declared?first=one&other=two'
263
- last_response.status.should == 200
293
+ expect(last_response.status).to eq(200)
264
294
  end
265
295
  end
266
296
 
@@ -320,7 +350,7 @@ describe Grape::Endpoint do
320
350
  end
321
351
 
322
352
  get '/hey?howdy=hey'
323
- last_response.body.should == 'hey'
353
+ expect(last_response.body).to eq('hey')
324
354
  end
325
355
 
326
356
  it 'parses from path segments' do
@@ -329,7 +359,7 @@ describe Grape::Endpoint do
329
359
  end
330
360
 
331
361
  get '/hey/12'
332
- last_response.body.should == '12'
362
+ expect(last_response.body).to eq('12')
333
363
  end
334
364
 
335
365
  it 'deeply converts nested params' do
@@ -337,7 +367,7 @@ describe Grape::Endpoint do
337
367
  params[:location][:city]
338
368
  end
339
369
  get '/location?location[city]=Dallas'
340
- last_response.body.should == 'Dallas'
370
+ expect(last_response.body).to eq('Dallas')
341
371
  end
342
372
 
343
373
  context 'with special requirements' do
@@ -347,10 +377,10 @@ describe Grape::Endpoint do
347
377
  end
348
378
 
349
379
  get '/someone@example.com'
350
- last_response.body.should == 'someone@example.com'
380
+ expect(last_response.body).to eq('someone@example.com')
351
381
 
352
382
  get 'someone@example.com.pl'
353
- last_response.body.should == 'someone@example.com.pl'
383
+ expect(last_response.body).to eq('someone@example.com.pl')
354
384
  end
355
385
 
356
386
  it 'parses many params with provided regexps' do
@@ -359,16 +389,16 @@ describe Grape::Endpoint do
359
389
  end
360
390
 
361
391
  get '/someone@example.com/test/1'
362
- last_response.body.should == 'someone@example.com1'
392
+ expect(last_response.body).to eq('someone@example.com1')
363
393
 
364
394
  get '/someone@testing.wrong/test/1'
365
- last_response.status.should == 404
395
+ expect(last_response.status).to eq(404)
366
396
 
367
397
  get 'someone@test.com/test/wrong_number'
368
- last_response.status.should == 404
398
+ expect(last_response.status).to eq(404)
369
399
 
370
400
  get 'someone@test.com/wrong_middle/1'
371
- last_response.status.should == 404
401
+ expect(last_response.status).to eq(404)
372
402
  end
373
403
 
374
404
  context 'namespace requirements' do
@@ -387,16 +417,16 @@ describe Grape::Endpoint do
387
417
  end
388
418
  it "parse email param with provided requirements for params" do
389
419
  get '/outer/abc@example.com'
390
- last_response.body.should == 'abc@example.com'
420
+ expect(last_response.body).to eq('abc@example.com')
391
421
  end
392
422
 
393
423
  it "should override outer namespace's requirements" do
394
424
  get '/outer/inner/someone@testing.wrong/test/1'
395
- last_response.status.should == 404
425
+ expect(last_response.status).to eq(404)
396
426
 
397
427
  get '/outer/inner/someone@testing.com/test/1'
398
- last_response.status.should == 200
399
- last_response.body.should == 'someone@testing.com1'
428
+ expect(last_response.status).to eq(200)
429
+ expect(last_response.body).to eq('someone@testing.com1')
400
430
  end
401
431
 
402
432
  end
@@ -414,22 +444,22 @@ describe Grape::Endpoint do
414
444
 
415
445
  it 'converts JSON bodies to params' do
416
446
  post '/request_body', MultiJson.dump(user: 'Bobby T.'), 'CONTENT_TYPE' => 'application/json'
417
- last_response.body.should == 'Bobby T.'
447
+ expect(last_response.body).to eq('Bobby T.')
418
448
  end
419
449
 
420
450
  it 'does not convert empty JSON bodies to params' do
421
451
  put '/request_body', '', 'CONTENT_TYPE' => 'application/json'
422
- last_response.body.should == ''
452
+ expect(last_response.body).to eq('')
423
453
  end
424
454
 
425
455
  it 'converts XML bodies to params' do
426
456
  post '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
427
- last_response.body.should == 'Bobby T.'
457
+ expect(last_response.body).to eq('Bobby T.')
428
458
  end
429
459
 
430
460
  it 'converts XML bodies to params' do
431
461
  put '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
432
- last_response.body.should == 'Bobby T.'
462
+ expect(last_response.body).to eq('Bobby T.')
433
463
  end
434
464
 
435
465
  it 'does not include parameters not defined by the body' do
@@ -438,8 +468,8 @@ describe Grape::Endpoint do
438
468
  params[:user]
439
469
  end
440
470
  post '/omitted_params', MultiJson.dump(user: 'Bob'), 'CONTENT_TYPE' => 'application/json'
441
- last_response.status.should == 201
442
- last_response.body.should == "Bob"
471
+ expect(last_response.status).to eq(201)
472
+ expect(last_response.body).to eq("Bob")
443
473
  end
444
474
  end
445
475
 
@@ -450,8 +480,8 @@ describe Grape::Endpoint do
450
480
  params[:user]
451
481
  end
452
482
  put '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
453
- last_response.status.should == 406
454
- last_response.body.should == '{"error":"The requested content-type \'application/xml\' is not supported."}'
483
+ expect(last_response.status).to eq(406)
484
+ expect(last_response.body).to eq('{"error":"The requested content-type \'application/xml\' is not supported."}')
455
485
  end
456
486
 
457
487
  context 'content type with params' do
@@ -466,11 +496,11 @@ describe Grape::Endpoint do
466
496
  end
467
497
 
468
498
  it "should not response with 406 for same type without params" do
469
- last_response.status.should_not be 406
499
+ expect(last_response.status).not_to be 406
470
500
  end
471
501
 
472
502
  it "should response with given content type in headers" do
473
- last_response.headers['Content-Type'].should eq 'application/json; charset=utf-8'
503
+ expect(last_response.headers['Content-Type']).to eq 'application/json; charset=utf-8'
474
504
  end
475
505
 
476
506
  end
@@ -523,8 +553,8 @@ describe Grape::Endpoint do
523
553
  end
524
554
 
525
555
  get '/hey'
526
- last_response.status.should == 500
527
- last_response.body.should == "This is not valid."
556
+ expect(last_response.status).to eq(500)
557
+ expect(last_response.body).to eq("This is not valid.")
528
558
  end
529
559
 
530
560
  it 'accepts a code' do
@@ -533,8 +563,8 @@ describe Grape::Endpoint do
533
563
  end
534
564
 
535
565
  get '/hey'
536
- last_response.status.should == 401
537
- last_response.body.should == "Unauthorized."
566
+ expect(last_response.status).to eq(401)
567
+ expect(last_response.body).to eq("Unauthorized.")
538
568
  end
539
569
 
540
570
  it 'accepts an object and render it in format' do
@@ -543,8 +573,8 @@ describe Grape::Endpoint do
543
573
  end
544
574
 
545
575
  get '/hey.json'
546
- last_response.status.should == 403
547
- last_response.body.should == '{"dude":"rad"}'
576
+ expect(last_response.status).to eq(403)
577
+ expect(last_response.body).to eq('{"dude":"rad"}')
548
578
  end
549
579
 
550
580
  it 'can specifiy headers' do
@@ -553,8 +583,8 @@ describe Grape::Endpoint do
553
583
  end
554
584
 
555
585
  get '/hey.json'
556
- last_response.status.should == 403
557
- last_response.headers['X-Custom'].should == 'value'
586
+ expect(last_response.status).to eq(403)
587
+ expect(last_response.headers['X-Custom']).to eq('value')
558
588
  end
559
589
  end
560
590
 
@@ -564,9 +594,9 @@ describe Grape::Endpoint do
564
594
  redirect "/ha"
565
595
  end
566
596
  get '/hey'
567
- last_response.status.should eq 302
568
- last_response.headers['Location'].should eq "/ha"
569
- last_response.body.should eq ""
597
+ expect(last_response.status).to eq 302
598
+ expect(last_response.headers['Location']).to eq "/ha"
599
+ expect(last_response.body).to eq ""
570
600
  end
571
601
 
572
602
  it 'has status code 303 if it is not get request and it is http 1.1' do
@@ -574,8 +604,8 @@ describe Grape::Endpoint do
574
604
  redirect "/ha"
575
605
  end
576
606
  post '/hey', {}, 'HTTP_VERSION' => 'HTTP/1.1'
577
- last_response.status.should eq 303
578
- last_response.headers['Location'].should eq "/ha"
607
+ expect(last_response.status).to eq 303
608
+ expect(last_response.headers['Location']).to eq "/ha"
579
609
  end
580
610
 
581
611
  it 'support permanent redirect' do
@@ -583,9 +613,9 @@ describe Grape::Endpoint do
583
613
  redirect "/ha", permanent: true
584
614
  end
585
615
  get '/hey'
586
- last_response.status.should eq 301
587
- last_response.headers['Location'].should eq "/ha"
588
- last_response.body.should eq ""
616
+ expect(last_response.status).to eq 301
617
+ expect(last_response.headers['Location']).to eq "/ha"
618
+ expect(last_response.body).to eq ""
589
619
  end
590
620
  end
591
621
 
@@ -595,10 +625,10 @@ describe Grape::Endpoint do
595
625
  end
596
626
 
597
627
  post '/new', text: 'abc'
598
- last_response.body.should == 'abc'
628
+ expect(last_response.body).to eq('abc')
599
629
 
600
630
  post '/new', text: 'def'
601
- last_response.body.should == 'def'
631
+ expect(last_response.body).to eq('def')
602
632
  end
603
633
 
604
634
  it 'resets all instance variables (except block) between calls' do
@@ -613,9 +643,9 @@ describe Grape::Endpoint do
613
643
  end
614
644
 
615
645
  get '/hello?howdy=hey'
616
- last_response.body.should == 'hey'
646
+ expect(last_response.body).to eq('hey')
617
647
  get '/hello?howdy=yo'
618
- last_response.body.should == 'yo'
648
+ expect(last_response.body).to eq('yo')
619
649
  end
620
650
 
621
651
  it 'allows explicit return calls' do
@@ -624,8 +654,8 @@ describe Grape::Endpoint do
624
654
  end
625
655
 
626
656
  get '/home'
627
- last_response.status.should == 200
628
- last_response.body.should == "Hello"
657
+ expect(last_response.status).to eq(200)
658
+ expect(last_response.body).to eq("Hello")
629
659
  end
630
660
 
631
661
  describe '.generate_api_method' do
@@ -640,7 +670,7 @@ describe Grape::Endpoint do
640
670
  }.to raise_error(ArgumentError)
641
671
  end
642
672
  it 'returns a Proc' do
643
- Grape::Endpoint.generate_api_method("GET test for a proc", &proc {}).should be_a Proc
673
+ expect(Grape::Endpoint.generate_api_method("GET test for a proc", &proc {})).to be_a Proc
644
674
  end
645
675
  end
646
676
 
@@ -651,7 +681,7 @@ describe Grape::Endpoint do
651
681
  subject.get('/before_test') { env['before_test'] }
652
682
 
653
683
  get '/before_test'
654
- last_response.body.should == "OK"
684
+ expect(last_response.body).to eq("OK")
655
685
  end
656
686
  end
657
687
 
@@ -660,14 +690,14 @@ describe Grape::Endpoint do
660
690
  subject.after { body "after" }
661
691
  subject.get('/after_test') { "during" }
662
692
  get '/after_test'
663
- last_response.body.should == 'after'
693
+ expect(last_response.body).to eq('after')
664
694
  end
665
695
 
666
696
  it 'does not override the response body with its return' do
667
697
  subject.after { "after" }
668
698
  subject.get('/after_test') { "body" }
669
699
  get '/after_test'
670
- last_response.body.should == "body"
700
+ expect(last_response.body).to eq("body")
671
701
  end
672
702
  end
673
703
  end
@@ -681,7 +711,7 @@ describe Grape::Endpoint do
681
711
  verb
682
712
  end
683
713
  send(verb, '/example/and/some/more')
684
- last_response.status.should eql 404
714
+ expect(last_response.status).to eql 404
685
715
  end
686
716
 
687
717
  it 'anchors paths by default for the #{verb.upcase} method' do
@@ -689,7 +719,7 @@ describe Grape::Endpoint do
689
719
  verb
690
720
  end
691
721
  send(verb, '/example/and/some/more')
692
- last_response.status.should eql 404
722
+ expect(last_response.status).to eql 404
693
723
  end
694
724
 
695
725
  it 'responds to /example/and/some/more for the non-anchored #{verb.upcase} method' do
@@ -697,8 +727,8 @@ describe Grape::Endpoint do
697
727
  verb
698
728
  end
699
729
  send(verb, '/example/and/some/more')
700
- last_response.status.should eql verb == "post" ? 201 : 200
701
- last_response.body.should eql verb == 'head' ? '' : verb
730
+ expect(last_response.status).to eql verb == "post" ? 201 : 200
731
+ expect(last_response.body).to eql verb == 'head' ? '' : verb
702
732
  end
703
733
  end
704
734
  end
@@ -709,7 +739,7 @@ describe Grape::Endpoint do
709
739
  request.url
710
740
  end
711
741
  get '/url'
712
- last_response.body.should == "http://example.org/url"
742
+ expect(last_response.body).to eq("http://example.org/url")
713
743
  end
714
744
  ['v1', :v1].each do |version|
715
745
  it 'should include version #{version}' do
@@ -718,7 +748,7 @@ describe Grape::Endpoint do
718
748
  request.url
719
749
  end
720
750
  get "/#{version}/url"
721
- last_response.body.should == "http://example.org/#{version}/url"
751
+ expect(last_response.body).to eq("http://example.org/#{version}/url")
722
752
  end
723
753
  end
724
754
  it 'should include prefix' do
@@ -728,7 +758,7 @@ describe Grape::Endpoint do
728
758
  request.url
729
759
  end
730
760
  get '/api/v1/url'
731
- last_response.body.should == "http://example.org/api/v1/url"
761
+ expect(last_response.body).to eq("http://example.org/api/v1/url")
732
762
  end
733
763
  end
734
764
 
@@ -743,12 +773,12 @@ describe Grape::Endpoint do
743
773
 
744
774
  it 'result in a 406 response if they are invalid' do
745
775
  get '/test', {}, 'HTTP_ACCEPT' => 'application/vnd.ohanapi.v1+json'
746
- last_response.status.should == 406
776
+ expect(last_response.status).to eq(406)
747
777
  end
748
778
 
749
779
  it 'result in a 406 response if they cannot be parsed by rack-accept' do
750
780
  get '/test', {}, 'HTTP_ACCEPT' => 'application/vnd.ohanapi.v1+json; version=1'
751
- last_response.status.should == 406
781
+ expect(last_response.status).to eq(406)
752
782
  end
753
783
  end
754
784
  end