Sha256: a27c2aa87cf242ed75ccf221c118d54277a9c96abbe77d7c70d45d1a5f339828

Contents?: true

Size: 1.84 KB

Versions: 5

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

module LicenseFinder
  describe Maven do
    let(:maven) { Maven.new }
    it_behaves_like "a PackageManager"

    def license_xml(xml)
      <<-resp
        <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <licenseSummary>
          <dependencies>
            #{xml}
          </dependencies>
        </licenseSummary>
      resp
    end

    describe '.current_packages' do
      before do
        allow(maven).to receive('`').with(/mvn/)
      end

      def stub_license_report(deps)
        fake_file = double(:license_report, read: license_xml(deps))
        allow(maven).to receive(:license_report).and_return(fake_file)
      end

      it 'lists all the current packages' do
        stub_license_report("
          <dependency>
            <artifactId>junit</artifactId>
            <version>4.11</version>
          </dependency>
          <dependency>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
           </dependency>
        ")

        expect(maven.current_packages.map { |p| [p.name, p.version] }).to eq [
          ["junit", "4.11"],
          ["hamcrest-core", "1.3"]
        ]
      end

      it "handles multiple licenses" do
        stub_license_report("
          <dependency>
            <licenses>
              <license>
                <name>License 1</name>
              </license>
              <license>
                <name>License 2</name>
              </license>
            </licenses>
          </dependency>
        ")

        expect(maven.current_packages.first.licenses.map(&:name)).to eq ['License 1', 'License 2']
      end

      it "handles no licenses" do
        stub_license_report("
          <dependency>
          </dependency>
        ")

        expect(maven.current_packages.first.licenses.map(&:name)).to eq ['unknown']
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
license_finder-2.0.4 spec/lib/license_finder/package_managers/maven_spec.rb
license_finder-2.0.3 spec/lib/license_finder/package_managers/maven_spec.rb
license_finder-2.0.2 spec/lib/license_finder/package_managers/maven_spec.rb
license_finder-2.0.1 spec/lib/license_finder/package_managers/maven_spec.rb
license_finder-2.0.0 spec/lib/license_finder/package_managers/maven_spec.rb