Sha256: 20807f897d98cae3df1f9fca15d359326c0df142e1c887d2880f040671865d33

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

RSpec.describe Licensee::Matchers::Cargo do
  subject { described_class.new(file) }

  let(:mit) { Licensee::License.find('mit') }
  let(:content) { 'license = "MIT"' }
  let(:file) { Licensee::ProjectFiles::LicenseFile.new(content, 'Cargo.toml') }

  it 'stores the file' do
    expect(subject.file).to eql(file)
  end

  it 'has confidence' do
    expect(subject.confidence).to be(90)
  end

  it 'matches' do
    expect(subject.match).to eql(mit)
  end

  {
    'spdx name'                => ['license = "MIT"', 'mit'],
    'single quotes'            => ["license = 'mit'", 'mit'],
    'quoted key'               => ["'license' = 'mit'", 'mit'],
    'double quoted key'        => ['"license"="mit"', 'mit'],
    'no whitespace'            => ["license='mit'", 'mit'],
    'leading whitespace'       => [" license = 'mit'", 'mit'],
    'other license'            => ['license = "Foo"', 'other'],
    'multiple licenses /'      => ['license = "Apache-2.0/MIT"', 'other'],
    'multiple licenses OR'     => ['license = "Apache-2.0 OR MIT"', 'other'],
    'multiple licenses parens' => ['license = "(Apache-2.0 OR MIT)"', 'other']
  }.each do |description, license_declaration_and_key|
    context "with a #{description}" do
      let(:content) { license_declaration_and_key[0] }
      let(:license) { Licensee::License.find(license_declaration_and_key[1]) }

      it 'matches' do
        expect(subject.match).to eql(license)
      end
    end
  end

  context 'no license field' do
    let(:content) { 'foo = "bar"' }

    it 'returns nil' do
      expect(subject.match).to be_nil
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
licensee-9.18.0 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.17.1 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.17.0 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.16.1 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.16.0 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.15.3 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.15.2 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.15.1 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.15.0 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.14.1 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.14.0 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.13.2 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.13.1 spec/licensee/matchers/cargo_matcher_spec.rb
licensee-9.13.0 spec/licensee/matchers/cargo_matcher_spec.rb