Skip to content

Commit

Permalink
Style/BlockDelimiters-20240216233125 (#917)
Browse files Browse the repository at this point in the history
* 🚓 regenerate rubocop todo

* 🚓 Style/BlockDelimiters

* 🚓 regenerate rubocop todo

---------

Co-authored-by: Rubocop Challenger <[email protected]>
Co-authored-by: Mathieu Jobin <[email protected]>
  • Loading branch information
3 people authored May 30, 2024
1 parent 623a4d6 commit 3cf67bd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 58 deletions.
24 changes: 2 additions & 22 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions lib/tasks/apipie.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <basename>.<counter>.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
Expand Down Expand Up @@ -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

Expand Down
49 changes: 25 additions & 24 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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 => {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/apipie/extractor/writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" =>
[{
Expand All @@ -31,8 +31,8 @@
:code=>"200"
}]
}
}
let(:loaded_records) {
end
let(:loaded_records) do
{
"concern_resources#show" =>
[{
Expand All @@ -57,7 +57,7 @@
"recorded"=>true
}]
}
}
end

context 'with doc_path overridden in configuration' do
around(:each) do |example|
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/swagger/swagger_dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 3cf67bd

Please sign in to comment.