diff --git a/.rubocop.yml b/.rubocop.yml index a58cedd15c..8dfa0311a9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -83,3 +83,6 @@ RSpec/MultipleMemoizedHelpers: RSpec/ContextWording: Enabled: false + +RSpecRails/HaveHttpStatus: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index faac38752a..f8f44abc88 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by -# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 5000` -# on 2024-04-15 16:22:26 UTC using RuboCop version 1.59.0. +# `rubocop --auto-gen-config` +# on 2024-04-17 16:26:06 UTC using RuboCop version 1.63.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -261,11 +261,9 @@ Style/FormatStringToken: # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowedReceivers. -# AllowedReceivers: Thread.current -Style/HashEachMethods: +Style/MapIntoArray: Exclude: - - 'lib/grape/middleware/stack.rb' + - 'spec/support/chunks.rb' # Offense count: 12 # Configuration parameters: AllowedMethods. diff --git a/Appraisals b/Appraisals deleted file mode 100644 index e9a6f2a42e..0000000000 --- a/Appraisals +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -customize_gemfiles do - { - single_quotes: true, - heading: "frozen_string_literal: true - -This file was generated by Appraisal" - } -end - -appraise 'rails-6-0' do - gem 'rails', '~> 6.0.0' -end - -appraise 'rails-6-1' do - gem 'rails', '~> 6.1' -end - -appraise 'rails-7-0' do - gem 'rails', '~> 7.0.0' -end - -appraise 'rails-7-1' do - gem 'rails', '~> 7.1.0' -end - -appraise 'rails-edge' do - gem 'rails', github: 'rails/rails' -end - -appraise 'rack-edge' do - gem 'rack', github: 'rack/rack' -end - -appraise 'multi_json' do - gem 'multi_json', require: 'multi_json' -end - -appraise 'multi_xml' do - gem 'multi_xml', require: 'multi_xml' -end - -appraise 'rack_1_0' do - gem 'rack', '~> 1.0' -end - -appraise 'rack_2_0' do - gem 'rack', '~> 2.0' -end - -appraise 'rack_3_0' do - gem 'rack', '~> 3.0.0' -end - -appraise 'dry_validation' do - group :development, :test do - remove_gem 'dry-validation' - end -end diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d41d4e6d..963ad514aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ * [#2363](https://github.com/ruby-grape/grape/pull/2363): Replace autoload by zeitwerk - [@ericproulx](https://github.com/ericproulx). * [#2425](https://github.com/ruby-grape/grape/pull/2425): Replace `{}` with `Rack::Header` or `Rack::Utils::HeaderHash` - [@dhruvCW](https://github.com/dhruvCW). * [#2430](https://github.com/ruby-grape/grape/pull/2430): Isolate extensions within specific gemfile - [@ericproulx](https://github.com/ericproulx). +* [#2431](https://github.com/ruby-grape/grape/pull/2431): Drop appraisals in favor of eval_gemfile - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes diff --git a/Gemfile b/Gemfile index fe90b51e84..cf63280c51 100644 --- a/Gemfile +++ b/Gemfile @@ -9,13 +9,12 @@ gemspec group :development, :test do gem 'bundler' gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false + gem 'rubocop', '1.63.2', require: false + gem 'rubocop-performance', '1.21.0', require: false + gem 'rubocop-rspec', '2.29.1', require: false end group :development do - gem 'appraisal' gem 'benchmark-ips' gem 'benchmark-memory' gem 'guard' @@ -25,11 +24,11 @@ end group :test do gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' + gem 'rack-test', '~> 2.1' + gem 'rspec', '~> 3.13' + gem 'ruby-grape-danger', '~> 0.2', require: false + gem 'simplecov', '~> 0.21' + gem 'simplecov-lcov', '~> 0.8' gem 'test-prof', require: false end diff --git a/docker-compose.yml b/docker-compose.yml index 2b293708b1..a86e58625f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,3 +15,5 @@ services: volumes: - .:/var/grape - gems:/usr/local/bundle + environment: + GEMFILE: multi_xml diff --git a/gemfiles/dry_validation.gemfile b/gemfiles/dry_validation.gemfile index 65231ea800..ad526a00f2 100644 --- a/gemfiles/dry_validation.gemfile +++ b/gemfiles/dry_validation.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'dry-validation' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/grape_entity.gemfile b/gemfiles/grape_entity.gemfile index 241e0adb1d..6baf20174d 100644 --- a/gemfiles/grape_entity.gemfile +++ b/gemfiles/grape_entity.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'grape-entity' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/hashie.gemfile b/gemfiles/hashie.gemfile index 7bf7b2bbcd..c45181b01f 100644 --- a/gemfiles/hashie.gemfile +++ b/gemfiles/hashie.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'hashie' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/multi_json.gemfile b/gemfiles/multi_json.gemfile index 20e5e98cb0..014c2f9c65 100644 --- a/gemfiles/multi_json.gemfile +++ b/gemfiles/multi_json.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal +gem 'multi_json' -source 'https://rubygems.org' - -gem 'multi_json', require: 'multi_json' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' +eval_gemfile '../Gemfile' diff --git a/gemfiles/multi_xml.gemfile b/gemfiles/multi_xml.gemfile index c4f147df16..3cd7774f99 100644 --- a/gemfiles/multi_xml.gemfile +++ b/gemfiles/multi_xml.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal +gem 'multi_xml' -source 'https://rubygems.org' - -gem 'multi_xml', require: 'multi_xml' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' +eval_gemfile '../Gemfile' diff --git a/gemfiles/rack_2_0.gemfile b/gemfiles/rack_2_0.gemfile index 323b23ce72..f43035ba62 100644 --- a/gemfiles/rack_2_0.gemfile +++ b/gemfiles/rack_2_0.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rack', '~> 2.0' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rack_3_0.gemfile b/gemfiles/rack_3_0.gemfile index 55188980dc..4025f3cc25 100644 --- a/gemfiles/rack_3_0.gemfile +++ b/gemfiles/rack_3_0.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rack', '~> 3.0.0' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rack_edge.gemfile b/gemfiles/rack_edge.gemfile index 53ea7d831d..975ceedbf1 100644 --- a/gemfiles/rack_edge.gemfile +++ b/gemfiles/rack_edge.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rack', github: 'rack/rack' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_6_0.gemfile b/gemfiles/rails_6_0.gemfile index ae6ae7c42b..8a9e3b2475 100644 --- a/gemfiles/rails_6_0.gemfile +++ b/gemfiles/rails_6_0.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rails', '~> 6.0.0' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile index b7553c7522..ad33d3a3e4 100644 --- a/gemfiles/rails_6_1.gemfile +++ b/gemfiles/rails_6_1.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rails', '~> 6.1' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile index 118579d80d..43db352ec4 100644 --- a/gemfiles/rails_7_0.gemfile +++ b/gemfiles/rails_7_0.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rails', '~> 7.0.0' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile index 610d0b6cf1..babb65fd70 100644 --- a/gemfiles/rails_7_1.gemfile +++ b/gemfiles/rails_7_1.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rails', '~> 7.1.0' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile index bc18d40f62..80b01d94e1 100644 --- a/gemfiles/rails_edge.gemfile +++ b/gemfiles/rails_edge.gemfile @@ -1,40 +1,5 @@ # frozen_string_literal: true -# This file was generated by Appraisal - -source 'https://rubygems.org' +eval_gemfile '../Gemfile' gem 'rails', github: 'rails/rails' - -group :development, :test do - gem 'bundler' - gem 'rake' - gem 'rubocop', '1.59.0', require: false - gem 'rubocop-performance', '1.20.1', require: false - gem 'rubocop-rspec', '2.25.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'rack-contrib', require: false - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/spec/grape/api_remount_spec.rb b/spec/grape/api_remount_spec.rb index 40b5505157..2c6c6ae4bb 100644 --- a/spec/grape/api_remount_spec.rb +++ b/spec/grape/api_remount_spec.rb @@ -7,9 +7,7 @@ let(:root_api) { Class.new(described_class) } - def app - root_api - end + let(:app) { root_api } describe 'remounting an API' do context 'with a defined route' do @@ -95,7 +93,7 @@ def app expect(last_response.body).to eq 'success' get '/without_conditional/sometimes' - expect(last_response.status).to eq 404 + expect(last_response).to be_not_found end end @@ -167,18 +165,18 @@ def app endpoint: 'test' } get 'test?another_attr=1' - expect(last_response.status).to eq 400 + expect(last_response).to be_bad_request get 'test?my_attr=1' - expect(last_response.status).to eq 200 + expect(last_response).to be_successful root_api.mount a_remounted_api, with: { required_attr_name: 'another_attr', endpoint: 'test_b' } get 'test_b?another_attr=1' - expect(last_response.status).to eq 200 + expect(last_response).to be_successful get 'test_b?my_attr=1' - expect(last_response.status).to eq 400 + expect(last_response).to be_bad_request end end end @@ -264,7 +262,7 @@ def app expect(last_response.body).to eq 'success' get '/different_location' - expect(last_response.status).to eq 404 + expect(last_response).to be_not_found root_api.mount a_remounted_api, with: { endpoint_name: 'new_location' } get '/new_location' @@ -339,13 +337,13 @@ def app expect(last_response.body).to eq 'success' get '/string/location', param_integer: 1 - expect(last_response.status).to eq 400 + expect(last_response).to be_bad_request get '/integer/location', param_integer: 1 expect(last_response.body).to eq 'success' get '/integer/location', param_integer: 'a' - expect(last_response.status).to eq 400 + expect(last_response).to be_bad_request end context 'on dynamic checks' do @@ -368,7 +366,7 @@ def app get '/location', restricted_values: 'sometimes' expect(last_response.body).to eq 'success' get '/location', restricted_values: 'never' - expect(last_response.status).to eq 400 + expect(last_response).to be_bad_request end end end @@ -387,13 +385,13 @@ def app root_api.mount a_remounted_api, with: { path: 'scores', required_param: 'param_key' } end - it 'will use the dynamic configuration on all routes' do + it 'uses the dynamic configuration on all routes' do get 'api/votes', param_key: 'a' expect(last_response.body).to eql '10 votes' get 'api/scores', param_key: 'a' expect(last_response.body).to eql '10 votes' get 'api/votes' - expect(last_response.status).to eq 400 + expect(last_response).to be_bad_request end end @@ -480,7 +478,7 @@ def printed_response end end - it 'will use the dynamic configuration on all routes' do + it 'uses the dynamic configuration on all routes' do root_api.mount(a_remounted_api, with: { some_value: 'response value' }) get '/location' @@ -497,7 +495,7 @@ def printed_response end end - it 'will use the dynamic configuration on all routes' do + it 'uses the dynamic configuration on all routes' do root_api.mount(a_remounted_api, with: { some_value: 'response value' }) get '/location' diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index fcf66ab635..f8aec1c488 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -4285,12 +4285,12 @@ def uniqe_id_route it 'returns an error when the id is bad' do get '/v1/orders/abc' - expect(last_response.body).to be_eql('id is invalid') + expect(last_response.body).to eq('id is invalid') end it 'returns the given id when it is valid' do get '/v1/orders/1-2' - expect(last_response.body).to be_eql('1-2') + expect(last_response.body).to eq('1-2') end end diff --git a/spec/grape/exceptions/validation_errors_spec.rb b/spec/grape/exceptions/validation_errors_spec.rb index 831ad80d7c..4bba43d657 100644 --- a/spec/grape/exceptions/validation_errors_spec.rb +++ b/spec/grape/exceptions/validation_errors_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'ostruct' - describe Grape::Exceptions::ValidationErrors do let(:validation_message) { 'FooBar is invalid' } let(:validation_error) { instance_double Grape::Exceptions::Validation, params: [validation_message], message: '' } @@ -80,7 +78,7 @@ def app 'exactly_one_of works!' end get '/exactly_one_of', beer: 'string', wine: 'anotherstring' - expect(last_response.status).to eq(400) + expect(last_response).to be_bad_request expect(JSON.parse(last_response.body)).to eq( [ 'params' => %w[beer wine], diff --git a/spec/grape/middleware/auth/base_spec.rb b/spec/grape/middleware/auth/base_spec.rb index 1bc888f11e..7ff7d0ad43 100644 --- a/spec/grape/middleware/auth/base_spec.rb +++ b/spec/grape/middleware/auth/base_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'base64' - describe Grape::Middleware::Auth::Base do subject do Class.new(Grape::API) do @@ -14,18 +12,16 @@ end end - def app - subject - end + let(:app) { subject } it 'authenticates if given valid creds' do get '/authorized', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'admin') - expect(last_response.status).to eq(200) + expect(last_response).to be_successful expect(last_response.body).to eq('DONE') end it 'throws a 401 is wrong auth is given' do get '/authorized', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'wrong') - expect(last_response.status).to eq(401) + expect(last_response).to be_unauthorized end end diff --git a/spec/grape/middleware/auth/strategies_spec.rb b/spec/grape/middleware/auth/strategies_spec.rb index f6996695b8..48c62d3d07 100644 --- a/spec/grape/middleware/auth/strategies_spec.rb +++ b/spec/grape/middleware/auth/strategies_spec.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -require 'base64' - describe Grape::Middleware::Auth::Strategies do - context 'Basic Auth' do - def app + describe 'Basic Auth' do + let(:app) do proc = ->(u, p) { u && p && u == p } Rack::Builder.new do |b| b.use Grape::Middleware::Error @@ -14,19 +12,18 @@ def app end it 'throws a 401 if no auth is given' do - @proc = -> { false } get '/whatever' - expect(last_response.status).to eq(401) + expect(last_response).to be_unauthorized end it 'authenticates if given valid creds' do get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'admin') - expect(last_response.status).to eq(200) + expect(last_response).to be_successful end it 'throws a 401 is wrong auth is given' do get '/whatever', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'wrong') - expect(last_response.status).to eq(401) + expect(last_response).to be_unauthorized end end end diff --git a/spec/support/basic_auth_encode_helpers.rb b/spec/support/basic_auth_encode_helpers.rb index 00c3c61497..78e21e6c80 100644 --- a/spec/support/basic_auth_encode_helpers.rb +++ b/spec/support/basic_auth_encode_helpers.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'base64' - module Spec module Support module Helpers