Add tests for unless build.without?
This commit is contained in:
parent
6dad9d8b44
commit
f968776e84
@ -274,13 +274,13 @@ module RuboCop
|
|||||||
if find_method_def(@processed_source.ast)
|
if find_method_def(@processed_source.ast)
|
||||||
problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
|
problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
|
||||||
end
|
end
|
||||||
#
|
|
||||||
# find_instance_method_call(body_node, :build, :without?) do |m|
|
find_instance_method_call(body_node, :build, :without?) do |m|
|
||||||
# next unless unless_modifier?(m.parent)
|
next unless unless_modifier?(m.parent)
|
||||||
# correct = m.source.gsub("out?", "?").gsub("unless", "if")
|
correct = m.source.gsub("out?", "?")
|
||||||
# problem "Use #{correct} instead of unless #{m.source}"
|
problem "Use if #{correct} instead of unless #{m.source}"
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# find_instance_method_call(body_node, :build, :with?) do |m|
|
# find_instance_method_call(body_node, :build, :with?) do |m|
|
||||||
# next unless unless_modifier?(m.parent)
|
# next unless unless_modifier?(m.parent)
|
||||||
# correct = m.source.gsub("?", "out?").gsub("unless", "if")
|
# correct = m.source.gsub("?", "out?").gsub("unless", "if")
|
||||||
|
|||||||
@ -619,6 +619,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|||||||
expect_offense(expected, actual)
|
expect_offense(expected, actual)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "with unless build.without?" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
def post_install
|
||||||
|
return unless build.without? "bar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: 'Use if build.with? "bar" instead of unless build.without? "bar"',
|
||||||
|
severity: :convention,
|
||||||
|
line: 5,
|
||||||
|
column: 18,
|
||||||
|
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