From 02a1406a2e4c2d0506861248eb767d99f5ce4515 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:32:29 +0530 Subject: [PATCH] add test for build.without --without-foo --- Library/Homebrew/rubocops/lines_cop.rb | 12 +++++----- .../Homebrew/test/rubocops/lines_cop_spec.rb | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 6c0c3ec736..d6dba9061d 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -297,12 +297,12 @@ module RuboCop problem "Don't negate 'build.without?': use 'build.with?'" end - # find_instance_method_call(body_node, :build, :without?) do |m| - # arg = parameters(m).first - # next unless match = regex_match_group(arg, %r{-?-?without-(.*)}) - # problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\"" - # end - # + find_instance_method_call(body_node, :build, :without?) do |m| + arg = parameters(m).first + next unless match = regex_match_group(arg, %r{-?-?without-(.*)}) + problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\"" + end + # find_instance_method_call(body_node, :build, :with?) do |m| # arg = parameters(m).first # next unless match = regex_match_group(arg, %r{-?-?with-(.*)}) diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index e008349635..0c225a5b60 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -715,6 +715,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with negated build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if build.without? "--without-bar" + end + end + EOS + + expected_offenses = [{ message: "Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--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 def expect_offense(expected, actual) expect(actual.message).to eq(expected[:message])