sinatra-param 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module Sinatra
14
14
  def param(name, type, options = {})
15
15
  name = name.to_s
16
16
 
17
- return unless params.member?(name) or present?(options[:default]) or options[:required]
17
+ return unless params.member?(name) or options[:default] or options[:required]
18
18
 
19
19
  begin
20
20
  params[name] = coerce(params[name], type, options)
@@ -36,20 +36,26 @@ module Sinatra
36
36
  end
37
37
  end
38
38
 
39
- def one_of(*names)
40
- count = 0
41
- names.each do |name|
42
- if params[name] and present?(params[name])
43
- count += 1
44
- next unless count > 1
39
+ def one_of(*args)
40
+ options = args.last.is_a?(Hash) ? args.pop : {}
41
+ names = args.collect(&:to_s)
45
42
 
46
- error = "Parameters #{names.join(', ')} are mutually exclusive"
47
- if content_type and content_type.match(mime_type(:json))
48
- error = {message: error}.to_json
49
- end
43
+ return unless names.length > 2
50
44
 
51
- halt 400, error
45
+ begin
46
+ validate_one_of!(params, names, options)
47
+ rescue InvalidParameterError => exception
48
+ if options[:raise] or (settings.raise_sinatra_param_exceptions rescue false)
49
+ exception.param, exception.options = names, options
50
+ raise exception
52
51
  end
52
+
53
+ error = "Parameters #{names.join(', ')} are mutually exclusive"
54
+ if content_type and content_type.match(mime_type(:json))
55
+ error = {message: error, errors: {names => exception.message}}.to_json
56
+ end
57
+
58
+ halt 400, error
53
59
  end
54
60
  end
55
61
 
@@ -112,6 +118,10 @@ module Sinatra
112
118
  end
113
119
  end
114
120
 
121
+ def validate_one_of!(params, names, options)
122
+ raise InvalidParameterError, "Parameters #{names.join(', ')} are mutually exclusive" if names.count{|name| present?(params[name])} > 1
123
+ end
124
+
115
125
  # ActiveSupport #present? and #blank? without patching Object
116
126
  def present?(object)
117
127
  !blank?(object)
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Param
3
- VERSION = '1.2.2'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
@@ -80,6 +80,11 @@ class App < Sinatra::Base
80
80
  params.to_json
81
81
  end
82
82
 
83
+ get '/default/hash' do
84
+ param :attributes, Hash, default: {}
85
+ params.to_json
86
+ end
87
+
83
88
  get '/default/proc' do
84
89
  param :year, Integer, default: proc { 2014 }
85
90
  params.to_json
@@ -185,15 +190,27 @@ class App < Sinatra::Base
185
190
  param :b, String
186
191
  param :c, String
187
192
 
188
- one_of(:a, :b, :c)
193
+ one_of :a, :b, :c
189
194
 
190
195
  {
191
196
  message: 'OK'
192
197
  }.to_json
193
198
  end
194
199
 
195
- get '/raise' do
200
+ get '/raise/validation/required' do
196
201
  param :arg, String, required: true, raise: true
197
202
  params.to_json
198
203
  end
204
+
205
+ get '/raise/choice' do
206
+ param :a, String
207
+ param :b, String
208
+ param :c, String
209
+
210
+ one_of :a, :b, :c, raise: true
211
+
212
+ {
213
+ message: 'OK'
214
+ }.to_json
215
+ end
199
216
  end
@@ -8,26 +8,35 @@ describe 'Parameter Sets' do
8
8
  {b: 2, c: 3},
9
9
  {a: 1, b: 2, c: 3}
10
10
  ]
11
+
11
12
  params.each do |param|
12
13
  get('/choice', param) do |response|
13
- response.status.should == 400
14
- JSON.parse(response.body)['message'].should =~ /mutually exclusive/
14
+ expect(response.status).to eql 400
15
+ expect(JSON.parse(response.body)['message']).to match(/mutually exclusive/)
15
16
  end
16
17
  end
17
18
  end
18
19
 
19
- it 'returns successfully for requests that only have one parameter' do
20
+ it 'returns successfully for requests that have one parameter' do
20
21
  params = [
21
22
  {a: 1},
22
23
  {b: 2},
23
24
  {c: 3}
24
25
  ]
26
+
25
27
  params.each do |param|
26
28
  get('/choice', param) do |response|
27
- response.status.should == 200
28
- JSON.parse(response.body)['message'].should =~ /OK/
29
+ expect(response.status).to eql 200
30
+ expect(JSON.parse(response.body)['message']).to match(/OK/)
29
31
  end
30
32
  end
31
33
  end
34
+
35
+ it 'returns successfully for requests that have no parameter' do
36
+ get('/choice') do |response|
37
+ expect(response.status).to eql 200
38
+ expect(JSON.parse(response.body)['message']).to match(/OK/)
39
+ end
40
+ end
32
41
  end
33
42
  end
@@ -4,8 +4,15 @@ describe 'Exception' do
4
4
  describe 'raise' do
5
5
  it 'should raise error when option is specified' do
6
6
  expect {
7
- get('/raise')
7
+ get('/raise/validation/required')
8
8
  }.to raise_error
9
9
  end
10
10
  end
11
+
12
+ it 'should raise error when more than one parameter is specified' do
13
+ params = {a: 1, b: 2, c: 3}
14
+ expect {
15
+ get('/raise/choice', params)
16
+ }.to raise_error
17
+ end
11
18
  end
@@ -4,16 +4,16 @@ describe 'Parameter' do
4
4
  it 'only sets parameters present in request or with a default value' do
5
5
  get('/', a: 'a', b: 'b') do |response|
6
6
  response_body = JSON.parse(response.body)
7
- response_body.member?('a').should eq true
8
- response_body.member?('b').should eq true
9
- response_body.member?('c').should eq true
10
- response_body.member?('d').should eq false
7
+ expect(response_body).to be_member('a')
8
+ expect(response_body).to be_member('b')
9
+ expect(response_body).to be_member('c')
10
+ expect(response_body).to_not be_member('d')
11
11
  end
12
12
  end
13
13
 
14
14
  it 'stringifies parameters' do
15
15
  get('/keys/stringify', q: 'test') do |response|
16
- response.body.should eq 'TEST'
16
+ expect(response.body).to eq 'TEST'
17
17
  end
18
18
  end
19
19
  end
@@ -4,15 +4,22 @@ describe 'Parameter Transformations' do
4
4
  describe 'default' do
5
5
  it 'sets a default value when none is given' do
6
6
  get('/default') do |response|
7
- response.status.should == 200
8
- JSON.parse(response.body)['sort'].should == 'title'
7
+ expect(response.status).to eql 200
8
+ expect(JSON.parse(response.body)['sort']).to eql 'title'
9
+ end
10
+ end
11
+
12
+ it 'sets a default value from an empty hash' do
13
+ get('/default/hash') do |response|
14
+ expect(response.status).to eql 200
15
+ expect(JSON.parse(response.body)['attributes']).to eql Hash.new
9
16
  end
10
17
  end
11
18
 
12
19
  it 'sets a default value from a proc' do
13
20
  get('/default/proc') do |response|
14
- response.status.should == 200
15
- JSON.parse(response.body)['year'].should == 2014
21
+ expect(response.status).to eql 200
22
+ expect(JSON.parse(response.body)['year']).to eql 2014
16
23
  end
17
24
  end
18
25
  end
@@ -20,15 +27,15 @@ describe 'Parameter Transformations' do
20
27
  describe 'transform' do
21
28
  it 'transforms the input using to_proc' do
22
29
  get('/transform', order: 'asc') do |response|
23
- response.status.should == 200
24
- JSON.parse(response.body)['order'].should == 'ASC'
30
+ expect(response.status).to eql 200
31
+ expect(JSON.parse(response.body)['order']).to eql 'ASC'
25
32
  end
26
33
  end
27
34
 
28
35
  it 'skips transformations when the value is nil' do
29
36
  get('/transform/required') do |response|
30
- response.status.should == 400
31
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: order')
37
+ expect(response.status).to eql 400
38
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: order')
32
39
  end
33
40
  end
34
41
  end
@@ -4,8 +4,8 @@ describe 'Parameter Types' do
4
4
  describe 'String' do
5
5
  it 'coerces strings' do
6
6
  get('/coerce/string', arg: '1234') do |response|
7
- response.status.should == 200
8
- JSON.parse(response.body)['arg'].should eq('1234')
7
+ expect(response.status).to eql 200
8
+ expect(JSON.parse(response.body)['arg']).to eq('1234')
9
9
  end
10
10
  end
11
11
  end
@@ -13,15 +13,15 @@ describe 'Parameter Types' do
13
13
  describe 'Integer' do
14
14
  it 'coerces integers' do
15
15
  get('/coerce/integer', arg: '1234') do |response|
16
- response.status.should == 200
17
- JSON.parse(response.body)['arg'].should eq(1234)
16
+ expect(response.status).to eql 200
17
+ expect(JSON.parse(response.body)['arg']).to eq(1234)
18
18
  end
19
19
  end
20
20
 
21
21
  it 'returns 400 on requests when integer is invalid' do
22
22
  get('/coerce/integer', arg: '123abc') do |response|
23
- response.status.should == 400
24
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
23
+ expect(response.status).to eql 400
24
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
25
25
  end
26
26
  end
27
27
  end
@@ -29,15 +29,15 @@ describe 'Parameter Types' do
29
29
  describe 'Float' do
30
30
  it 'coerces floats' do
31
31
  get('/coerce/float', arg: '1234') do |response|
32
- response.status.should == 200
33
- JSON.parse(response.body)['arg'].should eq(1234.0)
32
+ expect(response.status).to eql 200
33
+ expect(JSON.parse(response.body)['arg']).to eq(1234.0)
34
34
  end
35
35
  end
36
36
 
37
37
  it 'returns 400 on requests when float is invalid' do
38
38
  get('/coerce/float', arg: '123abc') do |response|
39
- response.status.should == 400
40
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
39
+ expect(response.status).to eql 400
40
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
41
41
  end
42
42
  end
43
43
  end
@@ -45,15 +45,15 @@ describe 'Parameter Types' do
45
45
  describe 'Time' do
46
46
  it 'coerces time' do
47
47
  get('/coerce/time', arg: '20130117') do |response|
48
- response.status.should == 200
49
- JSON.parse(response.body)['arg'].should match(/2013-01-17 00:00:00/)
48
+ expect(response.status).to eql 200
49
+ expect(JSON.parse(response.body)['arg']).to match(/2013-01-17 00:00:00/)
50
50
  end
51
51
  end
52
52
 
53
53
  it 'returns 400 on requests when time is invalid' do
54
54
  get('/coerce/time', arg: '123abc') do |response|
55
- response.status.should == 400
56
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
55
+ expect(response.status).to eql 400
56
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
57
57
  end
58
58
  end
59
59
  end
@@ -61,15 +61,15 @@ describe 'Parameter Types' do
61
61
  describe 'Date' do
62
62
  it 'coerces date' do
63
63
  get('/coerce/date', arg: '20130117') do |response|
64
- response.status.should == 200
65
- JSON.parse(response.body)['arg'].should eq('2013-01-17')
64
+ expect(response.status).to eql 200
65
+ expect(JSON.parse(response.body)['arg']).to eq('2013-01-17')
66
66
  end
67
67
  end
68
68
 
69
69
  it 'returns 400 on requests when date is invalid' do
70
70
  get('/coerce/date', arg: 'abc') do |response|
71
- response.status.should == 400
72
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
71
+ expect(response.status).to eql 400
72
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
73
73
  end
74
74
  end
75
75
  end
@@ -77,15 +77,15 @@ describe 'Parameter Types' do
77
77
  describe 'DateTime' do
78
78
  it 'coerces datetimes' do
79
79
  get('/coerce/datetime', arg: '20130117') do |response|
80
- response.status.should == 200
81
- JSON.parse(response.body)['arg'].should eq('2013-01-17T00:00:00+00:00')
80
+ expect(response.status).to eql 200
81
+ expect(JSON.parse(response.body)['arg']).to eq('2013-01-17T00:00:00+00:00')
82
82
  end
83
83
  end
84
84
 
85
85
  it 'returns 400 on requests when datetime is invalid' do
86
86
  get('/coerce/datetime', arg: 'abc') do |response|
87
- response.status.should == 400
88
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
87
+ expect(response.status).to eql 400
88
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
89
89
  end
90
90
  end
91
91
  end
@@ -93,28 +93,28 @@ describe 'Parameter Types' do
93
93
  describe 'Array' do
94
94
  it 'coerces arrays' do
95
95
  get('/coerce/array', arg: '1,2,3,4,5') do |response|
96
- response.status.should == 200
96
+ expect(response.status).to eql 200
97
97
  parsed_body = JSON.parse(response.body)
98
- parsed_body['arg'].should be_an(Array)
99
- parsed_body['arg'].should eq(%w(1 2 3 4 5))
98
+ expect(parsed_body['arg']).to be_an(Array)
99
+ expect(parsed_body['arg']).to eq(%w(1 2 3 4 5))
100
100
  end
101
101
  end
102
102
 
103
103
  it 'coerces arrays of size 1' do
104
104
  get('/coerce/array', arg: '1') do |response|
105
- response.status.should == 200
105
+ expect(response.status).to eql 200
106
106
  parsed_body = JSON.parse(response.body)
107
- parsed_body['arg'].should be_an(Array)
108
- parsed_body['arg'].should eq(%w(1))
107
+ expect(parsed_body['arg']).to be_an(Array)
108
+ expect(parsed_body['arg']).to eq(%w(1))
109
109
  end
110
110
  end
111
111
 
112
112
  it 'coerces arrays with arg[] style' do
113
113
  get('/coerce/array', 'arg[]' => ['1','2','3','4','5']) do |response|
114
- response.status.should == 200
114
+ expect(response.status).to eql 200
115
115
  parsed_body = JSON.parse(response.body)
116
- parsed_body['arg'].should be_an(Array)
117
- parsed_body['arg'].should eq(%w(1 2 3 4 5))
116
+ expect(parsed_body['arg']).to be_an(Array)
117
+ expect(parsed_body['arg']).to eq(%w(1 2 3 4 5))
118
118
  end
119
119
  end
120
120
  end
@@ -122,10 +122,10 @@ describe 'Parameter Types' do
122
122
  describe 'Hash' do
123
123
  it 'coerces hashes' do
124
124
  get('/coerce/hash', arg: 'a:b,c:d') do |response|
125
- response.status.should == 200
125
+ expect(response.status).to eql 200
126
126
  parsed_body = JSON.parse(response.body)
127
- parsed_body['arg'].should be_an(Hash)
128
- parsed_body['arg'].should eq({ 'a' => 'b', 'c' => 'd'})
127
+ expect(parsed_body['arg']).to be_an(Hash)
128
+ expect(parsed_body['arg']).to eq({ 'a' => 'b', 'c' => 'd'})
129
129
  end
130
130
  end
131
131
  end
@@ -134,8 +134,8 @@ describe 'Parameter Types' do
134
134
  it 'coerces truthy booleans to true' do
135
135
  %w(1 true t yes y).each do |bool|
136
136
  get('/coerce/boolean', arg: bool) do |response|
137
- response.status.should == 200
138
- JSON.parse(response.body)['arg'].should be_true
137
+ expect(response.status).to eql 200
138
+ expect(JSON.parse(response.body)['arg']).to be true
139
139
  end
140
140
  end
141
141
  end
@@ -143,9 +143,9 @@ describe 'Parameter Types' do
143
143
  it 'coerces falsey booleans to false' do
144
144
  %w(0 false f no n).each do |bool|
145
145
  get('/coerce/boolean', arg: bool) do |response|
146
- response.status.should == 200
147
- JSON.parse(response.body)['arg'].should be_false
148
- JSON.parse(response.body)['arg'].should_not be_nil
146
+ expect(response.status).to eql 200
147
+ expect(JSON.parse(response.body)['arg']).to be false
148
+ expect(JSON.parse(response.body)['arg']).to_not be_nil
149
149
  end
150
150
  end
151
151
  end
@@ -153,8 +153,8 @@ describe 'Parameter Types' do
153
153
  it 'coerces truthy booleans to true when default is false' do
154
154
  %w(1 true t yes y).each do |bool|
155
155
  get('/default/boolean/false', arg: bool) do |response|
156
- response.status.should == 200
157
- JSON.parse(response.body)['arg'].should be_true
156
+ expect(response.status).to eql 200
157
+ expect(JSON.parse(response.body)['arg']).to be true
158
158
  end
159
159
  end
160
160
  end
@@ -162,9 +162,9 @@ describe 'Parameter Types' do
162
162
  it 'coerces falsey booleans to false when default is true' do
163
163
  %w(0 false f no n).each do |bool|
164
164
  get('/default/boolean/true', arg: bool) do |response|
165
- response.status.should == 200
166
- JSON.parse(response.body)['arg'].should be_false
167
- JSON.parse(response.body)['arg'].should_not be_nil
165
+ expect(response.status).to eql 200
166
+ expect(JSON.parse(response.body)['arg']).to be false
167
+ expect(JSON.parse(response.body)['arg']).to_not be_nil
168
168
  end
169
169
  end
170
170
  end
@@ -4,14 +4,14 @@ describe 'Parameter Validations' do
4
4
  describe 'required' do
5
5
  it 'returns 400 on requests without required fields' do
6
6
  get('/validation/required') do |response|
7
- response.status.should eq(400)
8
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
7
+ expect(response.status).to eq(400)
8
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
9
9
  end
10
10
  end
11
11
 
12
12
  it 'returns 200 on requests when required field present' do
13
13
  get('/validation/required', arg: 'foo') do |response|
14
- response.status.should eq(200)
14
+ expect(response.status).to eq(200)
15
15
  end
16
16
  end
17
17
  end
@@ -19,35 +19,35 @@ describe 'Parameter Validations' do
19
19
  describe 'blank' do
20
20
  it 'returns 400 on requests when string is blank' do
21
21
  get('/validation/blank/string', arg: '') do |response|
22
- response.status.should eq(400)
23
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
22
+ expect(response.status).to eq(400)
23
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
24
24
  end
25
25
  end
26
26
 
27
27
  it 'returns 400 on requests when array is blank' do
28
28
  get('/validation/blank/array', arg: '') do |response|
29
- response.status.should eq(400)
30
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
29
+ expect(response.status).to eq(400)
30
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
31
31
  end
32
32
  end
33
33
 
34
34
  it 'returns 400 on requests when hash is blank' do
35
35
  get('/validation/blank/hash', arg: '') do |response|
36
- response.status.should eq(400)
37
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
36
+ expect(response.status).to eq(400)
37
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
38
38
  end
39
39
  end
40
40
 
41
41
  it 'returns 400 on requests when hash is blank' do
42
42
  get('/validation/blank/other', arg: '') do |response|
43
- response.status.should eq(400)
44
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
43
+ expect(response.status).to eq(400)
44
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
45
45
  end
46
46
  end
47
47
 
48
48
  it 'returns 200 on request when blank is true' do
49
49
  get('/validation/nonblank/string', arg: '') do |response|
50
- response.status.should eq(200)
50
+ expect(response.status).to eq(200)
51
51
  end
52
52
  end
53
53
  end
@@ -55,19 +55,19 @@ describe 'Parameter Validations' do
55
55
  describe 'format' do
56
56
  it 'returns 200 on requests when value matches the param regex' do
57
57
  get('/validation/format/hello', arg: 'hello world') do |response|
58
- response.status.should eq(200)
58
+ expect(response.status).to eq(200)
59
59
  end
60
60
  end
61
61
 
62
62
  it 'returns 400 on requests when value does not match the param regex' do
63
63
  get('/validation/format/hello', arg: 'world') do |response|
64
- response.status.should eq(400)
64
+ expect(response.status).to eq(400)
65
65
  end
66
66
  end
67
67
 
68
68
  it 'returns 400 on requests when value is not a string' do
69
69
  get('/validation/format/9000', arg: 9000) do |response|
70
- response.status.should eq(400)
70
+ expect(response.status).to eq(400)
71
71
  end
72
72
  end
73
73
  end
@@ -75,14 +75,14 @@ describe 'Parameter Validations' do
75
75
  describe 'is' do
76
76
  it 'returns 400 on requests when value is other than defined' do
77
77
  get('/validation/is', arg: 'bar') do |response|
78
- response.status.should eq(400)
79
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
78
+ expect(response.status).to eq(400)
79
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
80
80
  end
81
81
  end
82
82
 
83
83
  it 'returns 200 on requests with a value is other than defined' do
84
84
  get('/validation/is', arg: 'foo') do |response|
85
- response.status.should eq(200)
85
+ expect(response.status).to eq(200)
86
86
  end
87
87
  end
88
88
  end
@@ -90,14 +90,14 @@ describe 'Parameter Validations' do
90
90
  describe 'in' do
91
91
  it 'returns 400 on requests with a value not in the set' do
92
92
  get('/validation/in', arg: 'MISC') do |response|
93
- response.status.should eq(400)
94
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
93
+ expect(response.status).to eq(400)
94
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
95
95
  end
96
96
  end
97
97
 
98
98
  it 'returns 200 on requests with a value in the set' do
99
99
  get('/validation/in', arg: 'ASC') do |response|
100
- response.status.should eq(200)
100
+ expect(response.status).to eq(200)
101
101
  end
102
102
  end
103
103
  end
@@ -105,14 +105,14 @@ describe 'Parameter Validations' do
105
105
  describe 'within' do
106
106
  it 'returns 400 on requests with a value outside the range' do
107
107
  get('/validation/within', arg: 20) do |response|
108
- response.status.should eq(400)
109
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
108
+ expect(response.status).to eq(400)
109
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
110
110
  end
111
111
  end
112
112
 
113
113
  it 'returns 200 on requests with a value within the range' do
114
114
  get('/validation/within', arg: 5) do |response|
115
- response.status.should eq(200)
115
+ expect(response.status).to eq(200)
116
116
  end
117
117
  end
118
118
  end
@@ -120,14 +120,14 @@ describe 'Parameter Validations' do
120
120
  describe 'range' do
121
121
  it 'returns 400 on requests with a value outside the range' do
122
122
  get('/validation/range', arg: 20) do |response|
123
- response.status.should eq(400)
124
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
123
+ expect(response.status).to eq(400)
124
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
125
125
  end
126
126
  end
127
127
 
128
128
  it 'returns 200 on requests within the range' do
129
129
  get('/validation/range', arg: 10) do |response|
130
- response.status.should eq(200)
130
+ expect(response.status).to eq(200)
131
131
  end
132
132
  end
133
133
  end
@@ -135,14 +135,14 @@ describe 'Parameter Validations' do
135
135
  describe 'min' do
136
136
  it 'returns 400 on requests with a value smaller than min' do
137
137
  get('/validation/min', arg: 5) do |response|
138
- response.status.should eq(400)
139
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
138
+ expect(response.status).to eq(400)
139
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
140
140
  end
141
141
  end
142
142
 
143
143
  it 'returns 200 on requests with a value larger than min' do
144
144
  get('/validation/min', arg: 200) do |response|
145
- response.status.should eq(200)
145
+ expect(response.status).to eq(200)
146
146
  end
147
147
  end
148
148
  end
@@ -150,14 +150,14 @@ describe 'Parameter Validations' do
150
150
  describe 'max' do
151
151
  it 'returns 400 on requests with a value larger than max' do
152
152
  get('/validation/max', arg: 100) do |response|
153
- response.status.should eq(400)
154
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
153
+ expect(response.status).to eq(400)
154
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
155
155
  end
156
156
  end
157
157
 
158
158
  it 'returns 200 on requests with a value smaller than max' do
159
159
  get('/validation/max', arg: 2) do |response|
160
- response.status.should eq(200)
160
+ expect(response.status).to eq(200)
161
161
  end
162
162
  end
163
163
  end
@@ -165,14 +165,14 @@ describe 'Parameter Validations' do
165
165
  describe 'min_length' do
166
166
  it 'returns 400 on requests with a string shorter than min_length' do
167
167
  get('/validation/min_length', arg: 'hi') do |response|
168
- response.status.should eq(400)
169
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
168
+ expect(response.status).to eq(400)
169
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
170
170
  end
171
171
  end
172
172
 
173
173
  it 'returns 200 on requests with a string longer than min_length' do
174
174
  get('/validation/max_length', arg: 'longer') do |response|
175
- response.status.should eq(200)
175
+ expect(response.status).to eq(200)
176
176
  end
177
177
  end
178
178
  end
@@ -180,14 +180,14 @@ describe 'Parameter Validations' do
180
180
  describe 'max_length' do
181
181
  it 'returns 400 on requests with a string longer than max_length' do
182
182
  get('/validation/max_length', arg: 'reallylongstringlongerthanmax') do |response|
183
- response.status.should eq(400)
184
- JSON.parse(response.body)['message'].should eq('Invalid Parameter: arg')
183
+ expect(response.status).to eq(400)
184
+ expect(JSON.parse(response.body)['message']).to eq('Invalid Parameter: arg')
185
185
  end
186
186
  end
187
187
 
188
188
  it 'returns 200 on requests with a string shorter than max_length' do
189
189
  get('/validation/max_length', arg: 'short') do |response|
190
- response.status.should eq(200)
190
+ expect(response.status).to eq(200)
191
191
  end
192
192
  end
193
193
  end