Merge in ability to ignore comments

This commit is contained in:
Jeremy McAnally 2010-02-05 21:57:42 -06:00
commit 366d1393c5
2 changed files with 16 additions and 3 deletions

View File

@ -208,11 +208,16 @@ module Rails
# If they're on Windows, they probably don't have grep.
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
if @probably_has_grep
lines = if @probably_has_grep
find_with_grep(text, base_path + where, double_quote)
else
find_with_rak(text, base_path + where, double_quote)
end
# ignore comments
lines.gsub! /^\s*#.+$/m, ""
lines
end
# Sets a base path for finding files; mostly for testing
@ -260,9 +265,10 @@ module Rails
def extract_filenames_from_grep(output)
return nil if output.empty?
# I hate rescue nil as much as the next guy but I have a reason here at least...
fnames = output.split("\n").map do |fn|
fn.match(/^(.+?):/)[1] rescue nil
if m = fn.match(/^(.+?):/)
m[1]
end
end.compact
fnames.uniq

View File

@ -140,6 +140,13 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
assert @checker.alerts.has_key?("Known broken plugins")
end
def test_ignoring_comments
make_file("config/", "routes.rb", "# map.connect 'fail'")
@checker.check_routes
assert !@checker.alerts.has_key?("Old router API")
end
def teardown
clear_files