Skip to content

Commit df3b3c8

Browse files
authored
Adjust test expectations to conform to rack 3 (#2346)
* Adjust test expectations to conform to rack 3
1 parent 8e1488d commit df3b3c8

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
ruby: ['2.7', '3.0', '3.1', '3.2']
27-
gemfile: [rack_2_0, rails_6_0, rails_6_1, rails_7_0]
27+
gemfile: [rack_2_0, rack_3_0, rails_6_0, rails_6_1, rails_7_0]
2828
include:
2929
- ruby: '2.6'
3030
gemfile: rails_5_2

Appraisals

+4
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ end
3939
appraise 'rack2' do
4040
gem 'rack', '~> 2.0.0'
4141
end
42+
43+
appraise 'rack3' do
44+
gem 'rack', '~> 3.0.0'
45+
end

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [#2339](https://github.com/ruby-grape/grape/pull/2339): Documentation and specs for remountable configuration in params - [@myxoh](https://github.com/myxoh).
1919
* [#2328](https://github.com/ruby-grape/grape/pull/2328): Don't cache Class.instance_methods - [@byroot](https://github.com/byroot).
2020
* [#2337](https://github.com/ruby-grape/grape/pull/2337): Fix: allow custom validators that do not end with _validator - [@ericproulx](https://github.com/ericproulx).
21+
* [#2346](https://github.com/ruby-grape/grape/pull/2346): Adjust test expectations to conform to rack 3 - [@kbarrette](https://github.com/kbarrette).
2122
* Your contribution here.
2223

2324
## 1.7.1 (2023/05/14)

grape.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
2424
s.add_runtime_dependency 'builder'
2525
s.add_runtime_dependency 'dry-types', '>= 1.1'
2626
s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0'
27-
s.add_runtime_dependency 'rack', '>= 1.3.0', '< 3'
27+
s.add_runtime_dependency 'rack', '>= 1.3.0'
2828
s.add_runtime_dependency 'rack-accept'
2929

3030
s.files = %w[CHANGELOG.md CONTRIBUTING.md README.md grape.png UPGRADING.md LICENSE]

spec/grape/endpoint_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ def app
138138

139139
it 'includes request headers' do
140140
get '/headers'
141-
expect(JSON.parse(last_response.body)).to eq(
141+
expect(JSON.parse(last_response.body)).to include(
142142
'Host' => 'example.org',
143-
'Cookie' => '',
144-
'Version' => 'HTTP/1.0'
143+
'Cookie' => ''
145144
)
146145
end
147146

@@ -174,7 +173,7 @@ def app
174173

175174
get('/get/cookies')
176175

177-
expect(last_response.headers['Set-Cookie'].split("\n").sort).to eql [
176+
expect(Array(last_response.headers['Set-Cookie']).flat_map { |h| h.split("\n") }.sort).to eql [
178177
'cookie3=symbol',
179178
'cookie4=secret+code+here',
180179
'my-awesome-cookie1=is+cool',
@@ -199,8 +198,9 @@ def app
199198
end
200199
get('/username', {}, 'HTTP_COOKIE' => 'username=user; sandbox=false')
201200
expect(last_response.body).to eq('user_test')
202-
expect(last_response.headers['Set-Cookie']).to match(/username=user_test/)
203-
expect(last_response.headers['Set-Cookie']).to match(/sandbox=true/)
201+
cookies = Array(last_response.headers['Set-Cookie']).flat_map { |h| h.split("\n") }
202+
expect(cookies.first).to match(/username=user_test/)
203+
expect(cookies.second).to match(/sandbox=true/)
204204
end
205205

206206
it 'deletes cookie' do
@@ -214,7 +214,7 @@ def app
214214
end
215215
get '/test', {}, 'HTTP_COOKIE' => 'delete_this_cookie=1; and_this=2'
216216
expect(last_response.body).to eq('3')
217-
cookies = last_response.headers['Set-Cookie'].split("\n").to_h do |set_cookie|
217+
cookies = Array(last_response.headers['Set-Cookie']).flat_map { |h| h.split("\n") }.to_h do |set_cookie|
218218
cookie = CookieJar::Cookie.from_set_cookie 'http://localhost/test', set_cookie
219219
[cookie.name, cookie]
220220
end
@@ -238,7 +238,7 @@ def app
238238
end
239239
get('/test', {}, 'HTTP_COOKIE' => 'delete_this_cookie=1; and_this=2')
240240
expect(last_response.body).to eq('3')
241-
cookies = last_response.headers['Set-Cookie'].split("\n").to_h do |set_cookie|
241+
cookies = Array(last_response.headers['Set-Cookie']).flat_map { |h| h.split("\n") }.to_h do |set_cookie|
242242
cookie = CookieJar::Cookie.from_set_cookie 'http://localhost/test', set_cookie
243243
[cookie.name, cookie]
244244
end

spec/grape/middleware/formatter_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def to_xml
405405
env = { 'PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json' }
406406
status, headers, body = subject.call(env)
407407
expect(status).to be == 200
408-
expect(headers).to be == { 'Content-Type' => 'application/json' }
408+
expect(headers.transform_keys(&:downcase)).to be == { 'content-type' => 'application/json' }
409409
expect(read_chunks(body)).to be == ['data']
410410
end
411411
end

0 commit comments

Comments
 (0)