From fccd2cd6ee967fa2973ebdc14e58b9bd4bafccec Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Mon, 9 Sep 2024 18:35:53 -0400 Subject: [PATCH] Fix CI, upgrade RuboCop. --- .rubocop.yml | 4 + .rubocop_todo.yml | 126 ++++++++++++------ Gemfile | 2 + grape-swagger-entity.gemspec | 4 +- .../entities/response_model_spec.rb | 22 +-- .../entity/attribute_parser_spec.rb | 28 ++-- spec/grape-swagger/entity/parser_spec.rb | 3 +- spec/grape-swagger/entity_spec.rb | 2 +- 8 files changed, 124 insertions(+), 67 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 709b6f7..1f5d9a8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,6 +7,10 @@ AllCops: inherit_from: .rubocop_todo.yml +require: + - rubocop-rake + - rubocop-rspec + Naming/FileName: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 75eaa76..7552afe 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 2023-07-06 20:16:40 UTC using RuboCop version 1.42.0. +# `rubocop --auto-gen-config` +# on 2024-09-09 22:35:29 UTC using RuboCop version 1.66.1. # 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 @@ -28,7 +28,7 @@ Lint/EmptyBlock: Exclude: - 'spec/grape-swagger/entity/attribute_parser_spec.rb' -# Offense count: 1 +# Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedMethods. # AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal? @@ -37,59 +37,109 @@ Lint/RedundantSafeNavigation: - 'lib/grape-swagger/entity/attribute_parser.rb' # Offense count: 4 -# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes, Max. +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Exclude: - - 'lib/grape-swagger/entity/attribute_parser.rb' - - 'lib/grape-swagger/entity/parser.rb' - -# Offense count: 13 -# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods. -# AllowedMethods: refine -Metrics/BlockLength: - Exclude: - - '**/*.gemspec' - - 'spec/grape-swagger/entities/response_model_spec.rb' - - 'spec/grape-swagger/entity/attribute_parser_spec.rb' - - 'spec/grape-swagger/entity/parser_spec.rb' - - 'spec/support/shared_contexts/this_api.rb' + Max: 34 -# Offense count: 1 -# Configuration parameters: CountComments, Max, CountAsOne. +# Offense count: 2 +# Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Exclude: - - 'lib/grape-swagger/entity/attribute_parser.rb' - - 'lib/grape-swagger/entity/parser.rb' + Max: 112 # Offense count: 2 -# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: - Exclude: - - 'lib/grape-swagger/entity/attribute_parser.rb' - - 'lib/grape-swagger/entity/parser.rb' + Max: 11 -# Offense count: 5 -# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods. +# Offense count: 7 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Exclude: - - 'lib/grape-swagger/entity/attribute_parser.rb' - - 'lib/grape-swagger/entity/parser.rb' + Max: 28 # Offense count: 2 -# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Exclude: - - 'lib/grape-swagger/entity/attribute_parser.rb' - - 'lib/grape-swagger/entity/parser.rb' + Max: 13 -# Offense count: 2 +# Offense count: 5 # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. # SupportedStyles: snake_case, normalcase, non_integer -# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339 +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 Naming/VariableNumber: Exclude: - 'spec/grape-swagger/entities/response_model_spec.rb' +# Offense count: 1 +RSpec/BeforeAfterAll: + Exclude: + - '**/spec/spec_helper.rb' + - '**/spec/rails_helper.rb' + - '**/spec/support/**/*.rb' + - 'spec/grape-swagger/entities/response_model_spec.rb' + +# Offense count: 4 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/grape-swagger/entity/parser_spec.rb' + - 'spec/support/shared_contexts/inheritance_api.rb' + - 'spec/support/shared_contexts/this_api.rb' + +# Offense count: 2 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Exclude: + - '**/spec/features/**/*' + - '**/spec/requests/**/*' + - '**/spec/routing/**/*' + - '**/spec/system/**/*' + - '**/spec/views/**/*' + - 'spec/grape-swagger/entities/response_model_spec.rb' + +# Offense count: 4 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 172 + +# Offense count: 24 +RSpec/LeakyConstantDeclaration: + Exclude: + - 'spec/grape-swagger/entities/response_model_spec.rb' + - 'spec/support/shared_contexts/inheritance_api.rb' + - 'spec/support/shared_contexts/this_api.rb' + +# Offense count: 1 +RSpec/MultipleDescribes: + Exclude: + - 'spec/grape-swagger/entities/response_model_spec.rb' + +# Offense count: 5 +RSpec/MultipleExpectations: + Max: 11 + +# Offense count: 20 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/grape-swagger/entities/response_model_spec.rb' + +# Offense count: 39 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 5 + +# Offense count: 3 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. +# Include: **/*_spec.rb +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/grape-swagger/entity/attribute_parser_spec.rb' + - 'spec/grape-swagger/entity/parser_spec.rb' + - 'spec/grape-swagger/entity_spec.rb' + # Offense count: 4 # Configuration parameters: AllowedConstants. Style/Documentation: diff --git a/Gemfile b/Gemfile index f0986e9..96923db 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,8 @@ group :development, :test do gem 'rdoc' gem 'rspec' gem 'rubocop' + gem 'rubocop-rake' + gem 'rubocop-rspec' end gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git' diff --git a/grape-swagger-entity.gemspec b/grape-swagger-entity.gemspec index 83f615e..77af423 100644 --- a/grape-swagger-entity.gemspec +++ b/grape-swagger-entity.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.required_ruby_version = '>= 3.0' - s.add_runtime_dependency 'grape-entity', '~> 1' - s.add_runtime_dependency 'grape-swagger', '~> 2' + s.add_dependency 'grape-entity', '~> 1' + s.add_dependency 'grape-swagger', '~> 2' s.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/grape-swagger/entities/response_model_spec.rb b/spec/grape-swagger/entities/response_model_spec.rb index aaf4e84..298457c 100644 --- a/spec/grape-swagger/entities/response_model_spec.rb +++ b/spec/grape-swagger/entities/response_model_spec.rb @@ -3,17 +3,17 @@ require 'spec_helper' describe 'responseModel' do + subject do + get '/swagger_doc/something' + JSON.parse(last_response.body) + end + include_context 'this api' def app ThisApi::ResponseModelApi end - subject do - get '/swagger_doc/something' - JSON.parse(last_response.body) - end - it 'documents index action' do expect(subject['paths']['/something']['get']['responses']).to eq( '200' => { @@ -26,7 +26,7 @@ def app ) end - it 'should document specified models as show action' do + it 'documents specified models as show action' do expect(subject['paths']['/something/{id}']['get']['responses']).to eq( '200' => { 'description' => 'OK', @@ -88,6 +88,11 @@ def app end describe 'building definitions from given entities' do + subject do + get '/swagger_doc' + JSON.parse(last_response.body)['definitions'] + end + before :all do module TheseApi module Entities @@ -209,11 +214,6 @@ def app TheseApi::ResponseEntityApi end - subject do - get '/swagger_doc' - JSON.parse(last_response.body)['definitions'] - end - it 'prefers entity over other `using` values' do expect(subject['TheseApi_Entities_Values']).to eql( 'type' => 'object', diff --git a/spec/grape-swagger/entity/attribute_parser_spec.rb b/spec/grape-swagger/entity/attribute_parser_spec.rb index 064803a..99f9d71 100644 --- a/spec/grape-swagger/entity/attribute_parser_spec.rb +++ b/spec/grape-swagger/entity/attribute_parser_spec.rb @@ -7,10 +7,10 @@ include_context 'this api' describe '#call' do - let(:endpoint) {} - subject { described_class.new(endpoint).call(entity_options) } + let(:endpoint) {} + context 'when the entity is a model' do context 'when it is exposed as an array' do let(:entity_options) { { using: ThisApi::Entities::Tag, documentation: { is_array: true } } } @@ -62,7 +62,7 @@ documentation: { type: 'ThisApi::Kind', desc: 'The kind of this something.' } } end - it { is_expected.to_not include('type') } + it { is_expected.not_to include('type') } it { is_expected.to include('$ref' => '#/definitions/Kind') } end end @@ -88,15 +88,15 @@ context 'when it contains values array' do let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', values: %w[red blue] } } } - it { is_expected.to_not include('minimum') } - it { is_expected.to_not include('maximum') } + it { is_expected.not_to include('minimum') } + it { is_expected.not_to include('maximum') } end context 'when it contains values range' do let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', values: 'a'...'c' } } } - it { is_expected.to_not include('minimum') } - it { is_expected.to_not include('maximum') } + it { is_expected.not_to include('minimum') } + it { is_expected.not_to include('maximum') } end context 'when it contains extensions' do @@ -126,8 +126,8 @@ context 'when it contains values array' do let(:entity_options) { { documentation: { type: 'number', desc: 'Solution pH', values: [6.0, 7.0, 8.0] } } } - it { is_expected.to_not include('minimum') } - it { is_expected.to_not include('maximum') } + it { is_expected.not_to include('minimum') } + it { is_expected.not_to include('maximum') } end context 'when it contains values range' do @@ -139,14 +139,14 @@ context 'when it contains values range with no minimum' do let(:entity_options) { { documentation: { type: 'number', desc: 'Solution pH', values: ..14.0 } } } - it { is_expected.to_not include('minimum') } + it { is_expected.not_to include('minimum') } it { is_expected.to include(maximum: 14.0) } end context 'when it contains values range with no maximum' do let(:entity_options) { { documentation: { type: 'number', desc: 'Solution pH', values: 0.0.. } } } - it { is_expected.to_not include('maximum') } + it { is_expected.not_to include('maximum') } it { is_expected.to include(minimum: 0.0) } end @@ -177,8 +177,8 @@ context 'when it contains values array' do let(:entity_options) { { documentation: { type: 'integer', desc: 'Count', values: 1..10 } } } - it { is_expected.to_not include('minimum') } - it { is_expected.to_not include('maximum') } + it { is_expected.not_to include('minimum') } + it { is_expected.not_to include('maximum') } end context 'when it contains values range' do @@ -241,7 +241,7 @@ let(:entity_options) { { documentation: { type: 'string', desc: 'Content of something.' } } } it { is_expected.to include(type: 'string') } - it { is_expected.to_not include('$ref') } + it { is_expected.not_to include('$ref') } end context 'when it is exposed as a boolean' do diff --git a/spec/grape-swagger/entity/parser_spec.rb b/spec/grape-swagger/entity/parser_spec.rb index 6ac581f..4e09c19 100644 --- a/spec/grape-swagger/entity/parser_spec.rb +++ b/spec/grape-swagger/entity/parser_spec.rb @@ -29,11 +29,12 @@ end it 'hides hidden attributes' do - expect(properties).to_not include(:hidden_attr) + expect(properties).not_to include(:hidden_attr) end end end end + context 'inheritance api' do include_context 'inheritance api' diff --git a/spec/grape-swagger/entity_spec.rb b/spec/grape-swagger/entity_spec.rb index 04b1c7a..be74eb9 100644 --- a/spec/grape-swagger/entity_spec.rb +++ b/spec/grape-swagger/entity_spec.rb @@ -4,7 +4,7 @@ describe GrapeSwagger::Entity do it 'has a version number' do - expect(GrapeSwagger::Entity::VERSION).not_to be nil + expect(GrapeSwagger::Entity::VERSION).not_to be_nil end it 'parser should be registred' do