add tests for formula path string 1

This commit is contained in:
Gautham Goli 2017-08-14 21:34:01 +05:30
parent 65ae6bacd8
commit 9c9c280c8a
2 changed files with 43 additions and 19 deletions

View File

@ -118,24 +118,24 @@ module RuboCop
end end
end end
# # Prefer formula path shortcuts in strings # Prefer formula path shortcuts in strings
# formula_path_strings(body_node, :prefix) do |p| formula_path_strings(body_node, :share) do |p|
# next unless match = regex_match_group(p, %r{(/(man))[/'"]}) next unless match = regex_match_group(p, %r{(/(man))/?})
# problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\"" problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\""
# end end
#
# formula_path_strings(body_node, :share) do |p| formula_path_strings(body_node, :share) do |p|
# if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i) if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i)
# problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\"" problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\""
# end end
# if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))}) if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))})
# problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\"" problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
# end end
# if match = regex_match_group(p, %r{(/share/(info|man))}) if match = regex_match_group(p, %r{(/share/(info|man))})
# problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\"" problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
# end end
# end end
#
# find_every_method_call_by_name(body_node, :depends_on) do |m| # find_every_method_call_by_name(body_node, :depends_on) do |m|
# key, value = destructure_hash(paramters(m).first) # key, value = destructure_hash(paramters(m).first)
# next unless key.str_type? # next unless key.str_type?
@ -349,7 +349,7 @@ module RuboCop
(hash (pair $_ $_)) (hash (pair $_ $_))
EOS EOS
def_node_matcher :formula_path_strings, <<-EOS.undent def_node_search :formula_path_strings, <<-EOS.undent
(dstr (begin (send nil %1)) $(str _ )) (dstr (begin (send nil %1)) $(str _ ))
EOS EOS

View File

@ -955,6 +955,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
expect_offense(expected, actual) expect_offense(expected, actual)
end end
end end
it "with formula path shortcut long form" do
source = <<-EOS.undent
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
def install
mv "\#{share}/man", share
end
end
EOS
expected_offenses = [{ message: "\"\#\{share}/man\" should be \"\#{man}\"",
severity: :convention,
line: 5,
column: 17,
source: source }]
inspect_source(cop, source)
expected_offenses.zip(cop.offenses).each do |expected, actual|
expect_offense(expected, actual)
end
end
end end
def expect_offense(expected, actual) def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) expect(actual.message).to eq(expected[:message])