From 5f981a8722487dd9ee127a59f4f0471fa35c3c4c Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Wed, 15 Aug 2018 19:43:57 -0400 Subject: [PATCH] tests: add test for test calls audit cop --- .../Homebrew/test/rubocops/class_cop_spec.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Library/Homebrew/test/rubocops/class_cop_spec.rb b/Library/Homebrew/test/rubocops/class_cop_spec.rb index 6314978b45..469fbe8e5b 100644 --- a/Library/Homebrew/test/rubocops/class_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/class_cop_spec.rb @@ -48,6 +48,36 @@ describe RuboCop::Cop::FormulaAudit::ClassName do end end +describe RuboCop::Cop::FormulaAudit::TestCalls do + subject(:cop) { described_class.new } + + it "reports an offense when /usr/local/bin is found in test calls" do + expect_offense(<<~RUBY) + class Foo < Formula + url 'https://example.com/foo-1.0.tgz' + + test do + system "/usr/local/bin/test" + ^^^^^^^^^^^^^^^^^^^^^ use \#{bin} instead of /usr/local/bin in system + end + end + RUBY + end + + it "reports an offense when passing 0 as the second parameter to shell_output" do + expect_offense(<<~RUBY) + class Foo < Formula + url 'https://example.com/foo-1.0.tgz' + + test do + shell_output("\#{bin}/test", 0) + ^ Passing 0 to shell_output() is redundant + end + end + RUBY + end +end + describe RuboCop::Cop::FormulaAuditStrict::Test do subject(:cop) { described_class.new }