summaryrefslogtreecommitdiff
path: root/spec/unit/cli/scan_spec.rb
blob: a11842d6eff38df2fb70db601c971fa9721056d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

RSpec.describe Spandx::Cli::Commands::Scan do
  RSpec.shared_examples 'scan' do |path|
    context "when scanning #{path}" do
      subject { described_class.new(lockfile, options) }

      let(:lockfile) { fixture_file(path) }
      let(:output) { StringIO.new }
      let(:options) { { format: 'table', recursive: true } }

      before do
        stub_request(:get, Spandx::Spdx::Gateway::URL)
          .to_return(status: 200, body: fixture_file('spdx/json/licenses.json').read)
        VCR.use_cassette(lockfile.basename) do
          subject.execute(output: output)
        end
      end

      it { expect(output.string).to eql(IO.read("#{lockfile}.expected")) }
    end
  end

  include_examples 'scan', '.'
  include_examples 'scan', 'bundler/Gemfile.lock'
  include_examples 'scan', 'bundler/gems.lock'
  include_examples 'scan', 'pip/Pipfile.lock'
  include_examples 'scan', 'nuget/packages.config'
end