|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "rubocops/lines" |
| 4 | + |
| 5 | +RSpec.describe RuboCop::Cop::FormulaAudit::StdNpmArgs do |
| 6 | + subject(:cop) { described_class.new } |
| 7 | + |
| 8 | + context "when auditing node formulae" do |
| 9 | + it "reports an offense when `npm install` is called without std_npm_args arguments" do |
| 10 | + expect_offense(<<~RUBY) |
| 11 | + class Foo < Formula |
| 12 | + def install |
| 13 | + system "npm", "install" |
| 14 | + ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use `std_npm_args` for npm install |
| 15 | + end |
| 16 | + end |
| 17 | + RUBY |
| 18 | + end |
| 19 | + |
| 20 | + it "reports and corrects an offense when using local_npm_install_args" do |
| 21 | + expect_offense(<<~RUBY) |
| 22 | + class Foo < Formula |
| 23 | + def install |
| 24 | + system "npm", "install", *Language::Node.local_npm_install_args, "--production" |
| 25 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use 'std_npm_args' instead of 'local_npm_install_args'. |
| 26 | + end |
| 27 | + end |
| 28 | + RUBY |
| 29 | + |
| 30 | + expect_correction(<<~RUBY) |
| 31 | + class Foo < Formula |
| 32 | + def install |
| 33 | + system "npm", "install", *std_npm_args(prefix: false), "--production" |
| 34 | + end |
| 35 | + end |
| 36 | + RUBY |
| 37 | + end |
| 38 | + |
| 39 | + it "reports and corrects an offense when using std_npm_install_args with libexec" do |
| 40 | + expect_offense(<<~RUBY) |
| 41 | + class Foo < Formula |
| 42 | + def install |
| 43 | + system "npm", "install", *Language::Node.std_npm_install_args(libexec), "--production" |
| 44 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use 'std_npm_args' instead of 'std_npm_install_args'. |
| 45 | + end |
| 46 | + end |
| 47 | + RUBY |
| 48 | + |
| 49 | + expect_correction(<<~RUBY) |
| 50 | + class Foo < Formula |
| 51 | + def install |
| 52 | + system "npm", "install", *std_npm_args, "--production" |
| 53 | + end |
| 54 | + end |
| 55 | + RUBY |
| 56 | + end |
| 57 | + |
| 58 | + it "reports and corrects an offense when using std_npm_install_args without libexec" do |
| 59 | + expect_offense(<<~RUBY) |
| 60 | + class Foo < Formula |
| 61 | + def install |
| 62 | + system "npm", "install", *Language::Node.std_npm_install_args(buildpath), "--production" |
| 63 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/StdNpmArgs: Use 'std_npm_args' instead of 'std_npm_install_args'. |
| 64 | + end |
| 65 | + end |
| 66 | + RUBY |
| 67 | + |
| 68 | + expect_correction(<<~RUBY) |
| 69 | + class Foo < Formula |
| 70 | + def install |
| 71 | + system "npm", "install", *std_npm_args(prefix: buildpath), "--production" |
| 72 | + end |
| 73 | + end |
| 74 | + RUBY |
| 75 | + end |
| 76 | + |
| 77 | + it "does not report an offense when using std_npm_args" do |
| 78 | + expect_no_offenses(<<~RUBY) |
| 79 | + class Foo < Formula |
| 80 | + def install |
| 81 | + system "npm", "install", *std_npm_args |
| 82 | + end |
| 83 | + end |
| 84 | + RUBY |
| 85 | + end |
| 86 | + end |
| 87 | +end |
0 commit comments