Sha256: d828076a0d0f5642aa6b6037b129317ea661df6df43ffab0e49e257b3c1ae940

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

RSpec.describe Licensee::ProjectFiles::ProjectFile do
  let(:filename) { 'LICENSE.txt' }
  let(:mit) { Licensee::License.find('mit') }
  let(:content) { mit.content }
  let(:possible_matchers) { [Licensee::Matchers::Exact] }

  subject { Licensee::ProjectFiles::LicenseFile.new(content, filename) }
  before do
    allow(subject).to receive(:possible_matchers).and_return(possible_matchers)
  end
  before { allow(subject).to receive(:length).and_return(mit.length) }
  before { allow(subject).to receive(:wordset).and_return(mit.wordset) }

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

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

  it 'returns the matcher' do
    expect(subject.matcher).to be_a(Licensee::Matchers::Exact)
  end

  it 'returns the confidence' do
    expect(subject.confidence).to eql(100)
  end

  it 'returns the license' do
    expect(subject.license).to eql(mit)
  end

  context 'with additional metadata' do
    subject { described_class.new(content, name: filename, dir: Dir.pwd) }

    it 'stores the filename' do
      expect(subject.filename).to eql(filename)
      expect(subject[:name]).to eql(filename)
    end

    it 'stores additional metadata' do
      expect(subject[:dir]).to eql(Dir.pwd)
    end
  end

  context 'to_h' do
    let(:hash) { subject.to_h }
    let(:expected) do
      {
        filename:           'LICENSE.txt',
        content:            mit.content.to_s,
        content_hash:       subject.content_hash,
        content_normalized: subject.content_normalized,
        matcher:            {
          name:       :exact,
          confidence: 100
        },
        matched_license:    'MIT'
      }
    end

    it 'Converts to a hash' do
      expect(hash).to eql(expected)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
licensee-9.11.0 spec/licensee/project_files/project_file_spec.rb
licensee-9.10.1 spec/licensee/project_files/project_file_spec.rb
licensee-9.10.0 spec/licensee/project_files/project_file_spec.rb
licensee-9.9.4 spec/licensee/project_files/project_file_spec.rb
licensee-9.9.3 spec/licensee/project_files/project_file_spec.rb