Merge pull request #47313 from gregmolnar/stats

move directory existence check for code statistics task inside of the…
This commit is contained in:
Rafael Mendonça França 2023-03-25 12:21:46 -04:00 committed by GitHub
commit 0de99e92fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

@ -26,12 +26,13 @@ STATS_DIRECTORIES ||= [
%w(Channel\ tests test/channels),
%w(Integration\ tests test/integration),
%w(System\ tests test/system),
].collect do |name, dir|
[ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
end.select { |name, dir| File.directory?(dir) }
]
desc "Report code statistics (KLOCs, etc) from the application or engine"
task :stats do
require "rails/code_statistics"
CodeStatistics.new(*STATS_DIRECTORIES).to_s
stat_directories = STATS_DIRECTORIES.collect do |name, dir|
[ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
end.select { |name, dir| File.directory?(dir) }
CodeStatistics.new(*stat_directories).to_s
end

@ -0,0 +1,25 @@
# frozen_string_literal: true
require "isolation/abstract_unit"
require "rails/command"
class Rails::Command::DevTest < ActiveSupport::TestCase
setup :build_app
teardown :teardown_app
test "`bin/rails stats` handles non-existing directories added by third parties" do
Dir.chdir(app_path) do
app_file("lib/tasks/custom.rake", <<~CODE
task stats: "custom:statsetup"
namespace :custom do
task statsetup: :environment do
require "rails/code_statistics"
::STATS_DIRECTORIES << ["app/non_existing"]
end
end
CODE
)
assert rails "stats"
end
end
end