Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move directory existence check for code statistics task inside of the… #47313

Merged
merged 1 commit into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions railties/lib/rails/tasks/statistics.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions railties/test/commands/statistics_test.rb
Original file line number Diff line number Diff line change
@@ -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