aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorGautham Goli2017-08-14 02:43:54 +0530
committerGautham Goli2017-08-14 02:43:54 +0530
commit5a7cbb762f1a9e715ae03e82eb6cb8ef4ac4a0bb (patch)
treef0fc617a0988b25ab646d639a00a2f212577301c /Library/Homebrew
parent02a1406a2e4c2d0506861248eb767d99f5ce4515 (diff)
downloadbrew-5a7cbb762f1a9e715ae03e82eb6cb8ef4ac4a0bb.tar.bz2
add test for build.with? "--with-foo"
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb12
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb26
2 files changed, 31 insertions, 7 deletions
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index d6dba9061..5ed9acc93 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -303,12 +303,12 @@ module RuboCop
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-(.*)})
- # problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{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-(.*)})
+ problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
+ end
+
# find_instance_method_call(body_node, :build, :include?) do |m|
# arg = parameters(m).first
# next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index 0c225a5b6..273014cf1 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -716,7 +716,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
end
end
- it "with negated build.with?" do
+ it "with duplicated build.without?" do
source = <<-EOS.undent
class Foo < Formula
desc "foo"
@@ -739,6 +739,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
expect_offense(expected, actual)
end
end
+
+ it "with duplicated 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.with? "--with-bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"",
+ severity: :convention,
+ line: 5,
+ column: 27,
+ 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])