From 3f4034ab3479da23088174ad8cf56828b3cda9ad Mon Sep 17 00:00:00 2001 From: Shane Lattanzio Date: Wed, 12 Feb 2020 16:40:39 -0500 Subject: [PATCH] [CHANGED] Uses correct package management command for pip based on options that are passed in Signed-off-by: Debbie Chen --- Rakefile | 2 +- lib/license_finder/package_manager.rb | 34 +++++++++---------- lib/license_finder/package_managers/bower.rb | 4 +-- .../package_managers/bundler.rb | 2 +- lib/license_finder/package_managers/cargo.rb | 4 +-- .../package_managers/carthage.rb | 2 +- .../package_managers/cocoa_pods.rb | 2 +- .../package_managers/composer.rb | 2 +- lib/license_finder/package_managers/dep.rb | 2 +- lib/license_finder/package_managers/dotnet.rb | 4 +-- lib/license_finder/package_managers/glide.rb | 2 +- .../package_managers/go_15vendorexperiment.rb | 2 +- lib/license_finder/package_managers/go_dep.rb | 2 +- .../package_managers/go_workspace.rb | 2 +- .../package_managers/govendor.rb | 2 +- lib/license_finder/package_managers/gvt.rb | 2 +- lib/license_finder/package_managers/mix.rb | 12 +++---- lib/license_finder/package_managers/npm.rb | 4 +-- lib/license_finder/package_managers/nuget.rb | 12 +++---- lib/license_finder/package_managers/pip.rb | 12 +++---- lib/license_finder/package_managers/rebar.rb | 4 +-- lib/license_finder/package_managers/yarn.rb | 2 +- lib/license_finder/scanner.rb | 2 +- .../license_finder/package_manager_spec.rb | 22 ++++++------ .../package_managers/dep_spec.rb | 2 +- .../package_managers/dotnet_spec.rb | 3 +- .../package_managers/glide_spec.rb | 2 +- .../go_15vendorexperiment_spec.rb | 8 ++--- .../package_managers/go_workspace_spec.rb | 8 ++--- .../package_managers/govendor_spec.rb | 2 +- .../package_managers/gvt_spec.rb | 2 +- .../package_managers/nuget_spec.rb | 9 +++-- .../package_managers/yarn_spec.rb | 2 +- spec/lib/license_finder/scanner_spec.rb | 10 +++--- 34 files changed, 96 insertions(+), 92 deletions(-) diff --git a/Rakefile b/Rakefile index 444a9423c..f1880c401 100644 --- a/Rakefile +++ b/Rakefile @@ -47,7 +47,7 @@ task :check_dependencies do require './lib/license_finder' satisfied = true LicenseFinder::Scanner::PACKAGE_MANAGERS.each do |package_manager| - satisfied = false unless package_manager.installed?(LicenseFinder::Logger.new(LicenseFinder::Logger::MODE_INFO)) + satisfied = false unless package_manager.new(project_path: Pathname.new('')).installed?(LicenseFinder::Logger.new(LicenseFinder::Logger::MODE_INFO)) end STDOUT.flush exit 1 unless satisfied diff --git a/lib/license_finder/package_manager.rb b/lib/license_finder/package_manager.rb index c428f68c6..2140f8c95 100644 --- a/lib/license_finder/package_manager.rb +++ b/lib/license_finder/package_manager.rb @@ -22,24 +22,24 @@ class << self def takes_priority_over nil end + end - def installed?(logger = Core.default_logger) - if package_management_command.nil? - logger.debug self, 'no command defined' # TODO: comment me out - true - elsif command_exists?(package_management_command) - logger.debug self, 'is installed', color: :green - true - else - logger.info self, 'is not installed', color: :red - false - end + def installed?(logger = Core.default_logger) + if package_management_command.nil? + logger.debug self.class, 'no command defined' # TODO: comment me out + true + elsif command_exists?(package_management_command) + logger.debug self.class, 'is installed', color: :green + true + else + logger.info self.class, 'is not installed', color: :red + false end + end - # see class description - def package_management_command - nil - end + # see class description + def package_management_command + nil end # see class description @@ -47,7 +47,7 @@ def prepare_command nil end - def self.command_exists?(command) + def command_exists?(command) _stdout, _stderr, status = if LicenseFinder::Platform.windows? Cmd.run("where #{command}") @@ -128,7 +128,7 @@ def log_to_file(contents) FileUtils.mkdir_p @log_directory # replace whitespace with underscores and remove slashes - log_file_name = self.class.package_management_command&.gsub(/\s/, '_')&.gsub(%r{/}, '') + log_file_name = package_management_command&.gsub(/\s/, '_')&.gsub(%r{/}, '') log_file = File.join(@log_directory, "prepare_#{log_file_name || 'errors'}.log") File.open(log_file, 'w') do |f| diff --git a/lib/license_finder/package_managers/bower.rb b/lib/license_finder/package_managers/bower.rb index f9058bcba..64d0d43aa 100644 --- a/lib/license_finder/package_managers/bower.rb +++ b/lib/license_finder/package_managers/bower.rb @@ -10,7 +10,7 @@ def current_packages end end - def self.package_management_command + def package_management_command 'bower' end @@ -25,7 +25,7 @@ def possible_package_paths private def bower_output - command = "#{Bower.package_management_command} list --json -l action --allow-root" + command = "#{package_management_command} list --json -l action --allow-root" stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) } raise "Command '#{command}' failed to execute: #{stderr}" unless status.success? diff --git a/lib/license_finder/package_managers/bundler.rb b/lib/license_finder/package_managers/bundler.rb index 08364d06d..1c552939d 100644 --- a/lib/license_finder/package_managers/bundler.rb +++ b/lib/license_finder/package_managers/bundler.rb @@ -19,7 +19,7 @@ def current_packages end end - def self.package_management_command + def package_management_command 'bundle' end diff --git a/lib/license_finder/package_managers/cargo.rb b/lib/license_finder/package_managers/cargo.rb index 255849a2a..36489a9f8 100644 --- a/lib/license_finder/package_managers/cargo.rb +++ b/lib/license_finder/package_managers/cargo.rb @@ -10,7 +10,7 @@ def current_packages end end - def self.package_management_command + def package_management_command 'cargo' end @@ -25,7 +25,7 @@ def possible_package_paths private def cargo_output - command = "#{Cargo.package_management_command} metadata --format-version=1" + command = "#{package_management_command} metadata --format-version=1" stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) } raise "Command '#{command}' failed to execute: #{stderr}" unless status.success? diff --git a/lib/license_finder/package_managers/carthage.rb b/lib/license_finder/package_managers/carthage.rb index 5a2850d9a..5fe6e6030 100644 --- a/lib/license_finder/package_managers/carthage.rb +++ b/lib/license_finder/package_managers/carthage.rb @@ -20,7 +20,7 @@ def current_packages end end - def self.package_management_command + def package_management_command LicenseFinder::Platform.darwin? ? 'carthage' : nil end diff --git a/lib/license_finder/package_managers/cocoa_pods.rb b/lib/license_finder/package_managers/cocoa_pods.rb index 850381910..52baf4a42 100644 --- a/lib/license_finder/package_managers/cocoa_pods.rb +++ b/lib/license_finder/package_managers/cocoa_pods.rb @@ -21,7 +21,7 @@ def current_packages end end - def self.package_management_command + def package_management_command LicenseFinder::Platform.darwin? ? 'pod' : nil end diff --git a/lib/license_finder/package_managers/composer.rb b/lib/license_finder/package_managers/composer.rb index 6dcf5fc27..d2039799f 100644 --- a/lib/license_finder/package_managers/composer.rb +++ b/lib/license_finder/package_managers/composer.rb @@ -24,7 +24,7 @@ def prepare raise "Prepare command '#{Composer.prepare_command}' failed" unless @prepare_no_fail end - def self.package_management_command + def package_management_command 'composer' end diff --git a/lib/license_finder/package_managers/dep.rb b/lib/license_finder/package_managers/dep.rb index 000ad20f0..8e5faf765 100644 --- a/lib/license_finder/package_managers/dep.rb +++ b/lib/license_finder/package_managers/dep.rb @@ -31,7 +31,7 @@ def prepare_command 'dep ensure -vendor-only' end - def self.package_management_command + def package_management_command 'dep' end end diff --git a/lib/license_finder/package_managers/dotnet.rb b/lib/license_finder/package_managers/dotnet.rb index ecd8c5112..55496a4ea 100644 --- a/lib/license_finder/package_managers/dotnet.rb +++ b/lib/license_finder/package_managers/dotnet.rb @@ -71,12 +71,12 @@ def asset_files Dir[project_path.join('**/project.assets.json')] end - def self.package_management_command + def package_management_command 'dotnet' end def prepare_command - "#{Dotnet.package_management_command} restore" + "#{package_management_command} restore" end end end diff --git a/lib/license_finder/package_managers/glide.rb b/lib/license_finder/package_managers/glide.rb index 79f992879..34de9cbf1 100644 --- a/lib/license_finder/package_managers/glide.rb +++ b/lib/license_finder/package_managers/glide.rb @@ -30,7 +30,7 @@ def self.takes_priority_over Go15VendorExperiment end - def self.package_management_command + def package_management_command 'glide' end diff --git a/lib/license_finder/package_managers/go_15vendorexperiment.rb b/lib/license_finder/package_managers/go_15vendorexperiment.rb index 576ff1173..5e75b697c 100644 --- a/lib/license_finder/package_managers/go_15vendorexperiment.rb +++ b/lib/license_finder/package_managers/go_15vendorexperiment.rb @@ -42,7 +42,7 @@ def current_packages end end - def self.package_management_command + def package_management_command 'go' end diff --git a/lib/license_finder/package_managers/go_dep.rb b/lib/license_finder/package_managers/go_dep.rb index 6e6a90f27..b22403de2 100644 --- a/lib/license_finder/package_managers/go_dep.rb +++ b/lib/license_finder/package_managers/go_dep.rb @@ -22,7 +22,7 @@ def possible_package_paths [project_path.join('Godeps/Godeps.json')] end - def self.package_management_command + def package_management_command 'godep' end diff --git a/lib/license_finder/package_managers/go_workspace.rb b/lib/license_finder/package_managers/go_workspace.rb index 40535aca8..42a3826f8 100644 --- a/lib/license_finder/package_managers/go_workspace.rb +++ b/lib/license_finder/package_managers/go_workspace.rb @@ -15,7 +15,7 @@ def initialize(options = {}) @strict_matching = options[:strict_matching] end - def self.package_management_command + def package_management_command 'go' end diff --git a/lib/license_finder/package_managers/govendor.rb b/lib/license_finder/package_managers/govendor.rb index 5bd6123bb..6815f142f 100644 --- a/lib/license_finder/package_managers/govendor.rb +++ b/lib/license_finder/package_managers/govendor.rb @@ -25,7 +25,7 @@ def self.takes_priority_over Go15VendorExperiment end - def self.package_management_command + def package_management_command 'govendor' end diff --git a/lib/license_finder/package_managers/gvt.rb b/lib/license_finder/package_managers/gvt.rb index 14d1bcd50..4b1c91d3a 100644 --- a/lib/license_finder/package_managers/gvt.rb +++ b/lib/license_finder/package_managers/gvt.rb @@ -9,7 +9,7 @@ def possible_package_paths [Pathname(potential_path)] end - def self.package_management_command + def package_management_command 'gvt' end diff --git a/lib/license_finder/package_managers/mix.rb b/lib/license_finder/package_managers/mix.rb index 61b79371d..34324b21f 100644 --- a/lib/license_finder/package_managers/mix.rb +++ b/lib/license_finder/package_managers/mix.rb @@ -4,7 +4,7 @@ module LicenseFinder class Mix < PackageManager def initialize(options = {}) super - @command = options[:mix_command] || Mix.package_management_command + @command = options[:mix_command] || package_management_command @elixir_command = options[:elixir_command] || 'elixir' @deps_path = Pathname(options[:mix_deps_dir] || 'deps') end @@ -26,7 +26,7 @@ def licenses(name) licenses_by_package.fetch(name, ['license is not in deps']) end - def self.package_management_command + def package_management_command 'mix' end @@ -42,15 +42,15 @@ def possible_package_paths [project_path.join('mix.exs')] end - def self.installed?(logger = Core.default_logger) + def installed?(logger = Core.default_logger) if package_management_command.nil? - logger.debug self, 'no command defined' + logger.debug self.class, 'no command defined' true elsif command_exists?('elixir') && command_exists?('mix') - logger.debug self, 'is installed', color: :green + logger.debug self.class, 'is installed', color: :green true else - logger.info self, '(elixir) is not installed', color: :red + logger.info self.class, '(elixir) is not installed', color: :red false end end diff --git a/lib/license_finder/package_managers/npm.rb b/lib/license_finder/package_managers/npm.rb index d98bb7704..4788d3177 100644 --- a/lib/license_finder/package_managers/npm.rb +++ b/lib/license_finder/package_managers/npm.rb @@ -9,7 +9,7 @@ def current_packages NpmPackage.packages_from_json(npm_json, detected_package_path) end - def self.package_management_command + def package_management_command 'npm' end @@ -34,7 +34,7 @@ def prepare private def npm_json - command = "#{NPM.package_management_command} list --json --long#{production_flag}" + command = "#{package_management_command} list --json --long#{production_flag}" stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) } # we can try and continue if we got an exit status 1 - unmet peer dependency raise "Command '#{command}' failed to execute: #{stderr}" if !status.success? && status.exitstatus != 1 diff --git a/lib/license_finder/package_managers/nuget.rb b/lib/license_finder/package_managers/nuget.rb index 8d42021b2..53845f897 100644 --- a/lib/license_finder/package_managers/nuget.rb +++ b/lib/license_finder/package_managers/nuget.rb @@ -71,27 +71,27 @@ def dependencies assemblies.flat_map(&:dependencies) end - def self.package_management_command + def package_management_command return 'nuget' if LicenseFinder::Platform.windows? 'mono /usr/local/bin/nuget.exe' end def prepare_command - "#{Nuget.package_management_command} restore" + "#{package_management_command} restore" end - def self.installed?(logger = Core.default_logger) + def installed?(logger = Core.default_logger) _stdout, _stderr, status = Cmd.run(nuget_check) if status.success? - logger.debug self, 'is installed', color: :green + logger.debug self.class, 'is installed', color: :green else - logger.info self, 'is not installed', color: :red + logger.info self.class, 'is not installed', color: :red end status.success? end - def self.nuget_check + def nuget_check return 'where nuget' if LicenseFinder::Platform.windows? 'which mono && ls /usr/local/bin/nuget.exe' diff --git a/lib/license_finder/package_managers/pip.rb b/lib/license_finder/package_managers/pip.rb index 4cd09ec32..a4199bfca 100644 --- a/lib/license_finder/package_managers/pip.rb +++ b/lib/license_finder/package_managers/pip.rb @@ -4,10 +4,12 @@ module LicenseFinder class Pip < PackageManager + DEFAULT_VERSION = '2' + def initialize(options = {}) super @requirements_path = options[:pip_requirements_path] || Pathname('requirements.txt') - @python_version = options[:python_version] || '2' + @python_version = options[:python_version] || DEFAULT_VERSION raise "Invalid python version \'#{@python_version}\'. Valid versions are '2' or '3'." unless %w[2 3].include?(@python_version) end @@ -24,12 +26,8 @@ def current_packages end end - # Used to detect if installed, but this is a static method and the options aren't passed - # so we don't know which python version was specified. Will fail later if the expected version - # isn't installed. The Dockerfile now installs both versions so using the image is safe. - # TODO: Refactor PackageManager.installed?() to pass in the options? - def self.package_management_command - 'pip2' + def package_management_command + "pip#{@python_version}" end def prepare_command diff --git a/lib/license_finder/package_managers/rebar.rb b/lib/license_finder/package_managers/rebar.rb index 6cd2a0266..15e57e2b7 100644 --- a/lib/license_finder/package_managers/rebar.rb +++ b/lib/license_finder/package_managers/rebar.rb @@ -4,7 +4,7 @@ module LicenseFinder class Rebar < PackageManager def initialize(options = {}) super - @command = options[:rebar_command] || Rebar.package_management_command + @command = options[:rebar_command] || package_management_command @deps_path = Pathname(options[:rebar_deps_dir] || 'deps') end @@ -20,7 +20,7 @@ def current_packages end end - def self.package_management_command + def package_management_command 'rebar' end diff --git a/lib/license_finder/package_managers/yarn.rb b/lib/license_finder/package_managers/yarn.rb index e9ab5649d..cf98a8533 100644 --- a/lib/license_finder/package_managers/yarn.rb +++ b/lib/license_finder/package_managers/yarn.rb @@ -51,7 +51,7 @@ def self.takes_priority_over NPM end - def self.package_management_command + def package_management_command 'yarn' end diff --git a/lib/license_finder/scanner.rb b/lib/license_finder/scanner.rb index 4b3f03a8d..39fcc1162 100644 --- a/lib/license_finder/scanner.rb +++ b/lib/license_finder/scanner.rb @@ -32,7 +32,7 @@ def initialize(config = { project_path: Pathname.new('') }) def active_packages package_managers = active_package_managers - installed_package_managers = package_managers.select { |pm| pm.class.installed?(@logger) } + installed_package_managers = package_managers.select { |pm| pm.installed?(@logger) } installed_package_managers.flat_map(&:current_packages_with_relations) end diff --git a/spec/lib/license_finder/package_manager_spec.rb b/spec/lib/license_finder/package_manager_spec.rb index 2a695d2e8..ffa69206f 100644 --- a/spec/lib/license_finder/package_manager_spec.rb +++ b/spec/lib/license_finder/package_manager_spec.rb @@ -35,40 +35,40 @@ module LicenseFinder describe '.package_management_command' do it 'defaults to nil' do - expect(LicenseFinder::PackageManager.package_management_command).to be_nil + expect(subject.package_management_command).to be_nil end end describe '.installed?' do context 'package_management_command is nil' do before do - allow(LicenseFinder::PackageManager).to receive(:package_management_command).and_return(nil) + allow(subject).to receive(:package_management_command).and_return(nil) end it 'returns true' do - expect(LicenseFinder::PackageManager.installed?).to be_truthy + expect(subject.installed?).to be_truthy end end context 'package_management_command exists' do before do - allow(LicenseFinder::PackageManager).to receive(:package_management_command).and_return('foobar') - allow(LicenseFinder::PackageManager).to receive(:command_exists?).with('foobar').and_return(true) + allow(subject).to receive(:package_management_command).and_return('foobar') + allow(subject).to receive(:command_exists?).with('foobar').and_return(true) end it 'returns true' do - expect(LicenseFinder::PackageManager.installed?).to be_truthy + expect(subject.installed?).to be_truthy end end context 'package_management_command does not exist' do before do - allow(LicenseFinder::PackageManager).to receive(:package_management_command).and_return('foobar') - allow(LicenseFinder::PackageManager).to receive(:command_exists?).with('foobar').and_return(false) + allow(subject).to receive(:package_management_command).and_return('foobar') + allow(subject).to receive(:command_exists?).with('foobar').and_return(false) end it 'returns false' do - expect(LicenseFinder::PackageManager.installed?(logger)).to be_falsey + expect(subject.installed?(logger)).to be_falsey end end end @@ -133,14 +133,14 @@ module LicenseFinder end it 'uses defined package_management_command as the file name' do - allow(LicenseFinder::PackageManager).to receive(:package_management_command).and_return('foobar') + allow(subject).to receive(:package_management_command).and_return('foobar') expect { subject.prepare }.to raise_error(prepare_error) expect(File.exist?(File.join(log_directory, 'prepare_foobar.log'))).to be_truthy end context 'when prepare command has whitespaces and slashes in it' do before do - allow(described_class).to receive(:package_management_command) + allow(subject).to receive(:package_management_command) .and_return('mono /usr/local/bin/nuget.exe') end diff --git a/spec/lib/license_finder/package_managers/dep_spec.rb b/spec/lib/license_finder/package_managers/dep_spec.rb index f10f2515e..057a68902 100644 --- a/spec/lib/license_finder/package_managers/dep_spec.rb +++ b/spec/lib/license_finder/package_managers/dep_spec.rb @@ -51,7 +51,7 @@ module LicenseFinder describe '.package_management_command' do it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq('dep') + expect(subject.package_management_command).to eq('dep') end end end diff --git a/spec/lib/license_finder/package_managers/dotnet_spec.rb b/spec/lib/license_finder/package_managers/dotnet_spec.rb index 93a45a387..caeb5032c 100644 --- a/spec/lib/license_finder/package_managers/dotnet_spec.rb +++ b/spec/lib/license_finder/package_managers/dotnet_spec.rb @@ -9,8 +9,9 @@ module LicenseFinder it_behaves_like 'a PackageManager' describe '.package_management_command' do + subject { Dotnet.new project_path: Pathname.new('app') } it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq('dotnet') + expect(subject.package_management_command).to eq('dotnet') end end diff --git a/spec/lib/license_finder/package_managers/glide_spec.rb b/spec/lib/license_finder/package_managers/glide_spec.rb index 9de2f6a24..9f8285269 100644 --- a/spec/lib/license_finder/package_managers/glide_spec.rb +++ b/spec/lib/license_finder/package_managers/glide_spec.rb @@ -84,7 +84,7 @@ module LicenseFinder describe '.package_management_command' do it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq('glide') + expect(subject.package_management_command).to eq('glide') end end end diff --git a/spec/lib/license_finder/package_managers/go_15vendorexperiment_spec.rb b/spec/lib/license_finder/package_managers/go_15vendorexperiment_spec.rb index 82b0a830e..2b867ef48 100644 --- a/spec/lib/license_finder/package_managers/go_15vendorexperiment_spec.rb +++ b/spec/lib/license_finder/package_managers/go_15vendorexperiment_spec.rb @@ -18,13 +18,13 @@ module LicenseFinder it_behaves_like 'a PackageManager' it 'installed? should be true if go exists on the path' do - allow(PackageManager).to receive(:command_exists?).with('go').and_return true - expect(described_class.installed?).to eq(true) + allow(subject).to receive(:command_exists?).with('go').and_return true + expect(subject.installed?).to eq(true) end it 'installed? should be false if go does not exists on the path' do - allow(PackageManager).to receive(:command_exists?).with('go').and_return false - expect(described_class.installed?(logger)).to eq(false) + allow(subject).to receive(:command_exists?).with('go').and_return false + expect(subject.installed?(logger)).to eq(false) end end diff --git a/spec/lib/license_finder/package_managers/go_workspace_spec.rb b/spec/lib/license_finder/package_managers/go_workspace_spec.rb index 8abe048a9..20a27ea23 100644 --- a/spec/lib/license_finder/package_managers/go_workspace_spec.rb +++ b/spec/lib/license_finder/package_managers/go_workspace_spec.rb @@ -15,13 +15,13 @@ module LicenseFinder end it 'installed? should be true if go exists on the path' do - allow(PackageManager).to receive(:command_exists?).with('go').and_return true - expect(described_class.installed?).to eq(true) + allow(subject).to receive(:command_exists?).with('go').and_return true + expect(subject.installed?).to eq(true) end it 'installed? should be false if go does not exists on the path' do - allow(PackageManager).to receive(:command_exists?).with('go').and_return false - expect(described_class.installed?(logger)).to eq(false) + allow(subject).to receive(:command_exists?).with('go').and_return false + expect(subject.installed?(logger)).to eq(false) end end diff --git a/spec/lib/license_finder/package_managers/govendor_spec.rb b/spec/lib/license_finder/package_managers/govendor_spec.rb index 8ae696694..7a9ca0419 100644 --- a/spec/lib/license_finder/package_managers/govendor_spec.rb +++ b/spec/lib/license_finder/package_managers/govendor_spec.rb @@ -126,7 +126,7 @@ module LicenseFinder describe '.package_management_command' do it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq('govendor') + expect(subject.package_management_command).to eq('govendor') end end end diff --git a/spec/lib/license_finder/package_managers/gvt_spec.rb b/spec/lib/license_finder/package_managers/gvt_spec.rb index 69dbf6c85..c9efeafcb 100644 --- a/spec/lib/license_finder/package_managers/gvt_spec.rb +++ b/spec/lib/license_finder/package_managers/gvt_spec.rb @@ -120,7 +120,7 @@ module LicenseFinder describe '.package_management_command' do it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq('gvt') + expect(subject.package_management_command).to eq('gvt') end end end diff --git a/spec/lib/license_finder/package_managers/nuget_spec.rb b/spec/lib/license_finder/package_managers/nuget_spec.rb index 6d84973b4..bdf438c12 100644 --- a/spec/lib/license_finder/package_managers/nuget_spec.rb +++ b/spec/lib/license_finder/package_managers/nuget_spec.rb @@ -190,19 +190,22 @@ module LicenseFinder describe '.package_management_command' do it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq(nuget_cmd) + nuget = Nuget.new project_path: Pathname.new('app') + expect(nuget.package_management_command).to eq(nuget_cmd) end end describe '.installed?' do it 'returns true if nuget installed' do + nuget = Nuget.new project_path: Pathname.new('app') expect(SharedHelpers::Cmd).to receive(:run).with(nuget_check).and_return([nuget_location, '', cmd_success]) - expect(Nuget.installed?).to eq(true) + expect(nuget.installed?).to eq(true) end it 'returns false if no nuget' do + nuget = Nuget.new project_path: Pathname.new('app') expect(SharedHelpers::Cmd).to receive(:run).with(nuget_check).and_return(['', '', cmd_failure]) - expect(Nuget.installed?).to eq(false) + expect(nuget.installed?).to eq(false) end end diff --git a/spec/lib/license_finder/package_managers/yarn_spec.rb b/spec/lib/license_finder/package_managers/yarn_spec.rb index 3a5283bd8..339151a3f 100644 --- a/spec/lib/license_finder/package_managers/yarn_spec.rb +++ b/spec/lib/license_finder/package_managers/yarn_spec.rb @@ -128,7 +128,7 @@ module LicenseFinder describe '.package_management_command' do it 'returns the correct package management command' do - expect(described_class.package_management_command).to eq('yarn') + expect(subject.package_management_command).to eq('yarn') end end end diff --git a/spec/lib/license_finder/scanner_spec.rb b/spec/lib/license_finder/scanner_spec.rb index 307ed0942..d919ef76d 100644 --- a/spec/lib/license_finder/scanner_spec.rb +++ b/spec/lib/license_finder/scanner_spec.rb @@ -8,16 +8,18 @@ module LicenseFinder let(:subject) { described_class.new(logger: logger, project_path: Pathname.new('')) } describe '#active_packages' do + let(:bundler) { Bundler.new(ignored_groups: Set.new, definition: double(:definition, groups: [])) } + before do - bundler = double(:bundler, active?: true, class: Bundler) allow(Bundler).to receive(:new).and_return bundler allow(bundler).to receive(:current_packages_with_relations) - allow(Bundler).to receive(:package_management_command).and_return 'command' + allow(bundler).to receive(:active?).and_return true + allow(bundler).to receive(:package_management_command).and_return 'command' end context 'when package manager is installed' do it 'should log all active packages' do - allow(Bundler).to receive(:command_exists?).and_return true + allow(bundler).to receive(:command_exists?).and_return true expect(logger).to receive(:debug).with(Bundler, 'is installed', color: :green) expect(subject.active_packages).to_not be_nil end @@ -25,7 +27,7 @@ module LicenseFinder context 'when package manager is NOT installed' do it 'should log all active packages' do - allow(Bundler).to receive(:command_exists?).and_return false + allow(bundler).to receive(:command_exists?).and_return false expect(logger).to receive(:info).with(Bundler, 'is active', color: :green) expect(logger).to receive(:info).with(Bundler, 'is not installed', color: :red) expect(subject.active_packages).to_not be_nil