Sha256: d6afd6de689781b4c7ffe0524a27f7f564c36cb4b603f7eaf64d026a674de013

Contents?: true

Size: 1.48 KB

Versions: 14

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

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

  let(:mit) { Licensee::License.find('mit') }
  let(:content) { "s.license = 'mit'" }
  let(:file) do
    Licensee::ProjectFiles::LicenseFile.new(content, 'project.gemspec')
  end

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

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

  {
    'as spec.'      => "spec.license = 'mit'",
    'double quotes' => 's.license = "mit"',
    'no whitespace' => "s.license='mit'",
    'uppercase'     => "s.license = 'MIT'",
    'array'         => "s.licenses = ['mit']",
    'frozen'        => "s.license = 'mit'.freeze"
  }.each do |description, license_declaration|
    context "with a #{description} declaration" do
      let(:content) { license_declaration }

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

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

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

  context 'an unknown license' do
    let(:content) { "s.license = 'foo'" }

    it 'returns other' do
      expect(subject.match).to eql(Licensee::License.find('other'))
    end
  end

  context 'a licenses property with multiple licenses' do
    let(:content) { "s.licenses = ['mit', 'bsd-3-clause']" }

    it 'returns other' do
      expect(subject.match).to eql(Licensee::License.find('other'))
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

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