Merge pull request #47313 from gregmolnar/stats
move directory existence check for code statistics task inside of the…
This commit is contained in:
commit
0de99e92fd
@ -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
railties/test/commands/statistics_test.rb
Normal file
25
railties/test/commands/statistics_test.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user