Skip to content

Commit

Permalink
Adjust test expectations to conform to rack 3 (#2346)
Browse files Browse the repository at this point in the history
* Adjust test expectations to conform to rack 3
  • Loading branch information
kbarrette authored Aug 21, 2023
1 parent 8e1488d commit df3b3c8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2']
gemfile: [rack_2_0, rails_6_0, rails_6_1, rails_7_0]
gemfile: [rack_2_0, rack_3_0, rails_6_0, rails_6_1, rails_7_0]
include:
- ruby: '2.6'
gemfile: rails_5_2
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ end
appraise 'rack2' do
gem 'rack', '~> 2.0.0'
end

appraise 'rack3' do
gem 'rack', '~> 3.0.0'
end
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [#2339](https://github.com/ruby-grape/grape/pull/2339): Documentation and specs for remountable configuration in params - [@myxoh](https://github.com/myxoh).
* [#2328](https://github.com/ruby-grape/grape/pull/2328): Don't cache Class.instance_methods - [@byroot](https://github.com/byroot).
* [#2337](https://github.com/ruby-grape/grape/pull/2337): Fix: allow custom validators that do not end with _validator - [@ericproulx](https://github.com/ericproulx).
* [#2346](https://github.com/ruby-grape/grape/pull/2346): Adjust test expectations to conform to rack 3 - [@kbarrette](https://github.com/kbarrette).
* Your contribution here.

## 1.7.1 (2023/05/14)
Expand Down
2 changes: 1 addition & 1 deletion grape.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'builder'
s.add_runtime_dependency 'dry-types', '>= 1.1'
s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0'
s.add_runtime_dependency 'rack', '>= 1.3.0', '< 3'
s.add_runtime_dependency 'rack', '>= 1.3.0'
s.add_runtime_dependency 'rack-accept'

s.files = %w[CHANGELOG.md CONTRIBUTING.md README.md grape.png UPGRADING.md LICENSE]
Expand Down
16 changes: 8 additions & 8 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ def app

it 'includes request headers' do
get '/headers'
expect(JSON.parse(last_response.body)).to eq(
expect(JSON.parse(last_response.body)).to include(
'Host' => 'example.org',
'Cookie' => '',
'Version' => 'HTTP/1.0'
'Cookie' => ''
)
end

Expand Down Expand Up @@ -174,7 +173,7 @@ def app

get('/get/cookies')

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

it 'deletes cookie' do
Expand All @@ -214,7 +214,7 @@ def app
end
get '/test', {}, 'HTTP_COOKIE' => 'delete_this_cookie=1; and_this=2'
expect(last_response.body).to eq('3')
cookies = last_response.headers['Set-Cookie'].split("\n").to_h do |set_cookie|
cookies = Array(last_response.headers['Set-Cookie']).flat_map { |h| h.split("\n") }.to_h do |set_cookie|
cookie = CookieJar::Cookie.from_set_cookie 'http://localhost/test', set_cookie
[cookie.name, cookie]
end
Expand All @@ -238,7 +238,7 @@ def app
end
get('/test', {}, 'HTTP_COOKIE' => 'delete_this_cookie=1; and_this=2')
expect(last_response.body).to eq('3')
cookies = last_response.headers['Set-Cookie'].split("\n").to_h do |set_cookie|
cookies = Array(last_response.headers['Set-Cookie']).flat_map { |h| h.split("\n") }.to_h do |set_cookie|
cookie = CookieJar::Cookie.from_set_cookie 'http://localhost/test', set_cookie
[cookie.name, cookie]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/middleware/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def to_xml
env = { 'PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json' }
status, headers, body = subject.call(env)
expect(status).to be == 200
expect(headers).to be == { 'Content-Type' => 'application/json' }
expect(headers.transform_keys(&:downcase)).to be == { 'content-type' => 'application/json' }
expect(read_chunks(body)).to be == ['data']
end
end
Expand Down

0 comments on commit df3b3c8

Please sign in to comment.