diff options
| author | Gautham Goli | 2017-08-14 01:55:47 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-08-14 01:55:47 +0530 |
| commit | ec2b0df10e62152529386cf2a696f9aaece405ea (patch) | |
| tree | 50d9d8601e2bc57d86237e4faec9c4b2f4d821b6 /Library | |
| parent | f968776e8460d7b6a0a3199d9c92c945cda0738d (diff) | |
| download | brew-ec2b0df10e62152529386cf2a696f9aaece405ea.tar.bz2 | |
Add tests for unless build.with?
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/rubocops/lines_cop.rb | 12 | ||||
| -rw-r--r-- | Library/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 6c79e1fca..2b146b79e 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -281,12 +281,12 @@ module RuboCop problem "Use if #{correct} instead of unless #{m.source}" end - # find_instance_method_call(body_node, :build, :with?) do |m| - # next unless unless_modifier?(m.parent) - # correct = m.source.gsub("?", "out?").gsub("unless", "if") - # problem "Use #{correct} instead of unless #{m.source}" - # end - # + find_instance_method_call(body_node, :build, :with?) do |m| + next unless unless_modifier?(m.parent) + correct = m.source.gsub("?", "out?") + problem "Use if #{correct} instead of unless #{m.source}" + end + # find_instance_method_call(body_node, :build, :with?) do |m| # next unless negation?(m) # problem "Don't negate 'build.with?': use 'build.without?'" diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 352dc8219..dda1b96e6 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -643,6 +643,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with unless build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return unless build.with? "bar" + end + end + EOS + + expected_offenses = [{ message: 'Use if build.without? "bar" instead of unless build.with? "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 def expect_offense(expected, actual) expect(actual.message).to eq(expected[:message]) |
