From ef233bba9a0770ada1ebb45c804a319777bbff45 Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Mon, 11 Jan 2016 02:42:23 -0500 Subject: CodeStatistic will now ignore hidden files: - Modify the default regex to not match hidden files --- railties/lib/rails/code_statistics.rb | 2 +- railties/test/code_statistics_test.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index 8e9097e1ef..0997414482 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -33,7 +33,7 @@ class CodeStatistics #:nodoc: Hash[@pairs.map{|pair| [pair.first, calculate_directory_statistics(pair.last)]}] end - def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|rake)$/) + def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|coffee|rake)$/) stats = CodeStatisticsCalculator.new Dir.foreach(directory) do |file_name| diff --git a/railties/test/code_statistics_test.rb b/railties/test/code_statistics_test.rb index 1b1ff80bc1..4d80901217 100644 --- a/railties/test/code_statistics_test.rb +++ b/railties/test/code_statistics_test.rb @@ -4,7 +4,7 @@ require 'rails/code_statistics' class CodeStatisticsTest < ActiveSupport::TestCase def setup @tmp_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'tmp')) - @dir_js = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'tmp', 'lib.js')) + @dir_js = File.join(@tmp_path, 'lib.js') FileUtils.mkdir_p(@dir_js) end @@ -17,4 +17,17 @@ class CodeStatisticsTest < ActiveSupport::TestCase @code_statistics = CodeStatistics.new(['tmp dir', @tmp_path]) end end + + test 'ignores hidden files' do + File.write File.join(@tmp_path, '.example.rb'), <<-CODE + def foo + puts 'foo' + end + CODE + + assert_nothing_raised do + CodeStatistics.new(['hidden file', @tmp_path]) + end + end + end -- cgit v1.2.3