add tests for dependencies
This commit is contained in:
parent
d2a7314f53
commit
cfc423e183
@ -148,13 +148,15 @@ module RuboCop
|
||||
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
|
||||
end
|
||||
|
||||
# find_every_method_call_by_name(body_node, :depends_on).each do |m|
|
||||
# next unless modifier?(m)
|
||||
# dep, option = hash_dep(m)
|
||||
# next if dep.nil? || option.nil?
|
||||
# problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
|
||||
# end
|
||||
#
|
||||
find_every_method_call_by_name(body_node, :depends_on).each do |m|
|
||||
next if modifier?(m.parent)
|
||||
param = parameters(m).first
|
||||
dep, option = hash_dep(param)
|
||||
next if dep.nil? || option.nil?
|
||||
offending_node(param)
|
||||
problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
|
||||
end
|
||||
|
||||
# find_instance_method_call(body_node, :version, :==) do |m|
|
||||
# next unless parameters_passed?(m, "HEAD")
|
||||
# problem "Use 'build.head?' instead of inspecting 'version'"
|
||||
@ -328,6 +330,7 @@ module RuboCop
|
||||
end
|
||||
|
||||
def modifier?(node)
|
||||
return false unless node.if_type?
|
||||
node.modifier_form?
|
||||
end
|
||||
|
||||
@ -340,9 +343,9 @@ module RuboCop
|
||||
EOS
|
||||
|
||||
# Match depends_on with hash as argument
|
||||
def_node_search :hash_dep, <<-EOS.undent
|
||||
{$(hash (pair $(str _) $(str _)))
|
||||
$(hash (pair $(str _) (array $(str _) ...)))}
|
||||
def_node_matcher :hash_dep, <<-EOS.undent
|
||||
{(hash (pair $(str _) $(str _)))
|
||||
(hash (pair $(str _) (array $(str _) ...)))}
|
||||
EOS
|
||||
|
||||
def_node_matcher :destructure_hash, <<-EOS.undent
|
||||
|
||||
@ -1095,6 +1095,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
end
|
||||
end
|
||||
|
||||
it "with dependencies with invalid options" do
|
||||
source = <<-EOS.undent
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
depends_on "foo" => "with-bar"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Dependency foo should not use option with-bar",
|
||||
severity: :convention,
|
||||
line: 4,
|
||||
column: 13,
|
||||
source: source }]
|
||||
|
||||
inspect_source(cop, source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user