add test for build.include?
This commit is contained in:
parent
5a7cbb762f
commit
3ff8be1216
@ -309,11 +309,11 @@ module RuboCop
|
|||||||
problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
|
problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
# find_instance_method_call(body_node, :build, :include?) do |m|
|
find_instance_method_call(body_node, :build, :include?) do |m|
|
||||||
# arg = parameters(m).first
|
arg = parameters(m).first
|
||||||
# next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
|
next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
|
||||||
# problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
|
problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
|
||||||
# end
|
end
|
||||||
#
|
#
|
||||||
# find_instance_method_call(body_node, :build, :include?) do |m|
|
# find_instance_method_call(body_node, :build, :include?) do |m|
|
||||||
# arg = parameters(m).first
|
# arg = parameters(m).first
|
||||||
|
|||||||
@ -763,6 +763,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|||||||
expect_offense(expected, actual)
|
expect_offense(expected, actual)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "with build.include?" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
def post_install
|
||||||
|
return if build.include? "without-bar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: "Use build.without? \"bar\" instead of build.include? 'without-bar'",
|
||||||
|
severity: :convention,
|
||||||
|
line: 5,
|
||||||
|
column: 30,
|
||||||
|
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])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user