From 3cf67bd9dcf0c2a1e906dfa89777beda82ee095d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 11:49:47 +0900 Subject: [PATCH] Style/BlockDelimiters-20240216233125 (#917) * :police_car: regenerate rubocop todo * :police_car: Style/BlockDelimiters * :police_car: regenerate rubocop todo --------- Co-authored-by: Rubocop Challenger Co-authored-by: Mathieu Jobin <99191+mathieujobin@users.noreply.github.com> --- .rubocop_todo.yml | 24 +-------- lib/tasks/apipie.rake | 8 +-- spec/controllers/users_controller_spec.rb | 49 ++++++++++--------- .../pets_using_auto_views_controller.rb | 4 +- spec/lib/apipie/extractor/writer_spec.rb | 8 +-- spec/lib/swagger/swagger_dsl_spec.rb | 4 +- 6 files changed, 39 insertions(+), 58 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5b1442815..d9167e65e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -498,7 +498,7 @@ Layout/SpaceAroundOperators: - 'spec/lib/swagger/rake_swagger_spec.rb' - 'spec/lib/swagger/swagger_dsl_spec.rb' -# Offense count: 32 +# Offense count: 29 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space @@ -511,9 +511,6 @@ Layout/SpaceBeforeBlockBraces: - 'lib/apipie/param_description.rb' - 'lib/apipie/response_description.rb' - 'lib/apipie/routes_formatter.rb' - - 'lib/tasks/apipie.rake' - - 'spec/controllers/users_controller_spec.rb' - - 'spec/dummy/app/controllers/pets_using_auto_views_controller.rb' - 'spec/lib/swagger/swagger_dsl_spec.rb' # Offense count: 4 @@ -533,7 +530,7 @@ Layout/SpaceInsideArrayLiteralBrackets: - 'lib/apipie/generator/swagger/param_description/composite.rb' - 'spec/controllers/users_controller_spec.rb' -# Offense count: 63 +# Offense count: 60 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. # SupportedStyles: space, no_space @@ -546,9 +543,7 @@ Layout/SpaceInsideBlockBraces: - 'lib/apipie/response_description.rb' - 'lib/apipie/routes_formatter.rb' - 'lib/apipie/validator.rb' - - 'lib/tasks/apipie.rake' - 'spec/controllers/users_controller_spec.rb' - - 'spec/dummy/app/controllers/pets_using_auto_views_controller.rb' - 'spec/lib/apipie/application_spec.rb' - 'spec/lib/apipie/generator/swagger/operation_id_spec.rb' - 'spec/lib/apipie/generator/swagger/warning_spec.rb' @@ -1354,21 +1349,6 @@ Style/AndOr: Exclude: - 'lib/apipie/param_description.rb' -# Offense count: 18 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# AllowedMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'lib/tasks/apipie.rake' - - 'spec/controllers/users_controller_spec.rb' - - 'spec/dummy/app/controllers/pets_using_auto_views_controller.rb' - - 'spec/lib/apipie/extractor/writer_spec.rb' - - 'spec/lib/swagger/swagger_dsl_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowOnConstant, AllowOnSelfClass. diff --git a/lib/tasks/apipie.rake b/lib/tasks/apipie.rake index be7e3a2ec..f95342d41 100644 --- a/lib/tasks/apipie.rake +++ b/lib/tasks/apipie.rake @@ -70,17 +70,17 @@ namespace :apipie do with_loaded_documentation do out = ENV["OUT_REF"] || File.join(Rails.root, Apipie.configuration.doc_path, 'apidoc_ref') paths = generate_swagger_using_args(args, out) - paths.each {|path| + paths.each do |path| existing_files_in_dir = Pathname(out).children(true) make_reference = false # reference filenames have the format ..swagger_ref - reference_files = existing_files_in_dir.select{|f| + reference_files = existing_files_in_dir.select do |f| f.extname == '.swagger_ref' && f.basename.sub_ext("").extname.delete('.').to_i > 0 && f.basename.sub_ext("").sub_ext("") == path.basename.sub_ext("") - } + end if reference_files.empty? print "Reference file does not exist for [#{path}]\n" counter = 1 @@ -111,7 +111,7 @@ namespace :apipie do if reference_files.length > num_refs_to_keep (reference_files - reference_files[-num_refs_to_keep..-1]).each(&:delete) end - } + end end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 3ac743d52..44704fa9a 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -166,9 +166,9 @@ def reload_controllers end it "should work with nil value for a required hash param" do - expect { + expect do get :show, :params => { :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil} } - }.to raise_error(Apipie::ParamInvalid, /dummy_hash/) + end.to raise_error(Apipie::ParamInvalid, /dummy_hash/) assert_response :success end @@ -177,21 +177,22 @@ def reload_controllers end it "should work with custom Type validator" do - expect { + # old-style error rather than ParamInvalid + expect do get :show, :params => { :id => "not a number", :session => "secret_hash" } - }.to raise_error(Apipie::ParamError, /id/) # old-style error rather than ParamInvalid + end.to raise_error(Apipie::ParamError, /id/) end it "should work with Regexp validator" do get :show, :params => { :id => 5, :session => "secret_hash", :regexp_param => "24 years" } assert_response :success - expect { + expect do get :show, :params => { :id => 5, :session => "secret_hash", :regexp_param => "ten years" } - }.to raise_error(Apipie::ParamInvalid, /regexp_param/) + end.to raise_error(Apipie::ParamInvalid, /regexp_param/) end it "should work with Array validator" do @@ -202,28 +203,28 @@ def reload_controllers get :show, :params => { :id => 5, :session => "secret_hash", :array_param => '1' } assert_response :success - expect { + expect do get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "blabla" } - }.to raise_error(Apipie::ParamInvalid, /array_param/) + end.to raise_error(Apipie::ParamInvalid, /array_param/) - expect { + expect do get :show, :params => { :id => 5, :session => "secret_hash", :array_param => 3 } - }.to raise_error(Apipie::ParamInvalid, /array_param/) + end.to raise_error(Apipie::ParamInvalid, /array_param/) end it "should work with Proc validator" do - expect { + expect do get :show, :params => { :id => 5, :session => "secret_hash", :proc_param => "asdgsag" } - }.to raise_error(Apipie::ParamInvalid, /proc_param/) + end.to raise_error(Apipie::ParamInvalid, /proc_param/) get :show, :params => { @@ -247,22 +248,22 @@ def reload_controllers hash_params[1].name == :pass hash_params[2].name == :membership - expect { + expect do post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } } - }.to raise_error(Apipie::ParamInvalid, /membership/) + end.to raise_error(Apipie::ParamInvalid, /membership/) # Should include both pass and name - expect { + expect do post :create, :params => { :user => { :membership => "standard" } } - }.to raise_error(Apipie::ParamMultipleMissing, /pass.*\n.*name|name.*\n.*pass/) + end.to raise_error(Apipie::ParamMultipleMissing, /pass.*\n.*name|name.*\n.*pass/) - expect { + expect do post :create, :params => { :user => { :name => "root" } } - }.to raise_error(Apipie::ParamMissing, /pass/) + end.to raise_error(Apipie::ParamMissing, /pass/) - expect { + expect do post :create, :params => { :user => "a string is not a hash" } - }.to raise_error(Apipie::ParamInvalid, /user/) + end.to raise_error(Apipie::ParamInvalid, /user/) post :create, :params => { :user => { :name => "root", :pass => "pwd" } } assert_response :success @@ -336,7 +337,7 @@ def reload_controllers end context "with bad input" do it "should raise an error" do - expect{ + expect do put :update, :params => { :id => 5, @@ -353,7 +354,7 @@ def reload_controllers } ] } - }.to raise_error(Apipie::ParamInvalid) + end.to raise_error(Apipie::ParamInvalid) end end it "should work with empty array" do @@ -467,9 +468,9 @@ def reload_controllers it "should raise exception" do api = Apipie[UsersController, :see_another] api.instance_variable_set :@see, [Apipie::SeeDescription.new(['doesnot#exist'])] - expect { + expect do api.see.first.see_url - }.to raise_error(ArgumentError, /does not exist/) + end.to raise_error(ArgumentError, /does not exist/) api.instance_variable_set :@see, [] end end diff --git a/spec/dummy/app/controllers/pets_using_auto_views_controller.rb b/spec/dummy/app/controllers/pets_using_auto_views_controller.rb index ecc6f268c..3d05103c4 100644 --- a/spec/dummy/app/controllers/pets_using_auto_views_controller.rb +++ b/spec/dummy/app/controllers/pets_using_auto_views_controller.rb @@ -22,11 +22,11 @@ class SelfDocumentingView # self.describe_own_properties (a class method) generates the meta-data # (i.e., the type description) for the subclass. def self.describe_own_properties - (self.instance_methods - self.class.instance_methods).map{|m| + (self.instance_methods - self.class.instance_methods).map do |m| if matchdata = /^v_(\w+)__(\w+)$/.match(m) Apipie::prop(matchdata[1], matchdata[2]) end - }.compact + end.compact end # to_json (an instance method) generates the actual view diff --git a/spec/lib/apipie/extractor/writer_spec.rb b/spec/lib/apipie/extractor/writer_spec.rb index 780cd1730..3bcf512d5 100644 --- a/spec/lib/apipie/extractor/writer_spec.rb +++ b/spec/lib/apipie/extractor/writer_spec.rb @@ -6,7 +6,7 @@ let(:writer_class) { Apipie::Extractor::Writer } let(:writer) { writer_class.new(collector) } let(:test_examples_file) { File.join(Rails.root, "doc", "apipie_examples_test.json") } - let(:records) { + let(:records) do { "concern_resources#show" => [{ @@ -31,8 +31,8 @@ :code=>"200" }] } - } - let(:loaded_records) { + end + let(:loaded_records) do { "concern_resources#show" => [{ @@ -57,7 +57,7 @@ "recorded"=>true }] } - } + end context 'with doc_path overridden in configuration' do around(:each) do |example| diff --git a/spec/lib/swagger/swagger_dsl_spec.rb b/spec/lib/swagger/swagger_dsl_spec.rb index 563c1b631..4a5a9da2d 100644 --- a/spec/lib/swagger/swagger_dsl_spec.rb +++ b/spec/lib/swagger/swagger_dsl_spec.rb @@ -5,10 +5,10 @@ describe "Swagger Responses" do let(:desc) { Apipie.get_resource_description(controller_class, Apipie.configuration.default_version) } - let(:swagger) { + let(:swagger) do Apipie.configuration.generator.swagger.suppress_warnings = true Apipie.to_swagger_json(Apipie.configuration.default_version, controller_class.to_s.underscore.sub("_controller", "")) - } + end let(:controller_class ) { described_class }