Check for deprecated require for 'test_help'
This commit is contained in:
parent
28b809bc01
commit
23cf363cd5
@ -66,6 +66,29 @@ module Rails
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check for deprecated test_help require
|
||||||
|
def check_test_help
|
||||||
|
files = []
|
||||||
|
|
||||||
|
# Hate to duplicate code, but we have to double quote this one...
|
||||||
|
lines = grep_for("\'test_help\'", "test/", true)
|
||||||
|
files += extract_filenames(lines) || []
|
||||||
|
|
||||||
|
lines = grep_for("\"test_help\"", "test/")
|
||||||
|
files += extract_filenames(lines) || []
|
||||||
|
|
||||||
|
files.uniq!
|
||||||
|
|
||||||
|
unless files.empty?
|
||||||
|
alert(
|
||||||
|
"Deprecated test_help path",
|
||||||
|
"You now must require 'rails/test_help' not just 'test_help'.",
|
||||||
|
"http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices",
|
||||||
|
files
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Check for old (pre-application.rb) environment.rb file
|
# Check for old (pre-application.rb) environment.rb file
|
||||||
def check_environment
|
def check_environment
|
||||||
unless File.exist?("config/application.rb")
|
unless File.exist?("config/application.rb")
|
||||||
@ -181,14 +204,14 @@ module Rails
|
|||||||
# depending on platform.
|
# depending on platform.
|
||||||
#
|
#
|
||||||
# TODO: Figure out if this works on Windows.
|
# TODO: Figure out if this works on Windows.
|
||||||
def grep_for(text, where = "./")
|
def grep_for(text, where = "./", double_quote = false)
|
||||||
# If they're on Windows, they probably don't have grep.
|
# If they're on Windows, they probably don't have grep.
|
||||||
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
|
@probably_has_grep ||= (Config::CONFIG['host_os'].downcase =~ /mswin|windows|mingw/).nil?
|
||||||
|
|
||||||
if @probably_has_grep
|
if @probably_has_grep
|
||||||
find_with_grep(text, base_path + where)
|
find_with_grep(text, base_path + where, double_quote)
|
||||||
else
|
else
|
||||||
find_with_rak(text, base_path + where)
|
find_with_rak(text, base_path + where, double_quote)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -198,10 +221,16 @@ module Rails
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Use the grep utility to find a string in a set of files
|
# Use the grep utility to find a string in a set of files
|
||||||
def find_with_grep(text, where)
|
def find_with_grep(text, where, double_quote)
|
||||||
value = ""
|
value = ""
|
||||||
|
# Specifically double quote for finding 'test_help'
|
||||||
Open3.popen3("grep -r '#{text}' #{where}") do |stdin, stdout, stderr|
|
command = if double_quote
|
||||||
|
"grep -r \"#{text}\" #{where}"
|
||||||
|
else
|
||||||
|
"grep -r '#{text}' #{where}"
|
||||||
|
end
|
||||||
|
|
||||||
|
Open3.popen3(command) do |stdin, stdout, stderr|
|
||||||
value = stdout.read
|
value = stdout.read
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -209,7 +238,7 @@ module Rails
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Use the rak gem to grep the files (not yet implemented)
|
# Use the rak gem to grep the files (not yet implemented)
|
||||||
def find_with_rak(text, where)
|
def find_with_rak(text, where, double_quote)
|
||||||
value = ""
|
value = ""
|
||||||
|
|
||||||
Open3.popen3("rak --nogroup -l '#{Regexp.escape(text)}' #{where}") do |stdin, stdout, stderr|
|
Open3.popen3("rak --nogroup -l '#{Regexp.escape(text)}' #{where}") do |stdin, stdout, stderr|
|
||||||
|
@ -71,6 +71,27 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
|
|||||||
assert @checker.alerts.has_key?("Old router API")
|
assert @checker.alerts.has_key?("Old router API")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_check_for_old_test_help
|
||||||
|
make_file("test/", "test_helper.rb", " require 'test_help'")
|
||||||
|
@checker.check_test_help
|
||||||
|
|
||||||
|
assert @checker.alerts.has_key?("Deprecated test_help path")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_check_for_old_test_help_with_double_quotes
|
||||||
|
make_file("test/", "test_helper.rb", " require \"test_help\"")
|
||||||
|
@checker.check_test_help
|
||||||
|
|
||||||
|
assert @checker.alerts.has_key?("Deprecated test_help path")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_check_for_old_test_help_doesnt_see_test_helper
|
||||||
|
make_file("test/", "test_helper.rb", " require 'test_helper'")
|
||||||
|
@checker.check_test_help
|
||||||
|
|
||||||
|
assert !@checker.alerts.has_key?("Deprecated test_help path")
|
||||||
|
end
|
||||||
|
|
||||||
def test_check_lack_of_app_dot_rb
|
def test_check_lack_of_app_dot_rb
|
||||||
@checker.check_environment
|
@checker.check_environment
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user