spec/integration_spec.rb in licensee-8.9.2 vs spec/integration_spec.rb in licensee-9.0.0.beta.1

- old
+ new

@@ -1,10 +1,14 @@ RSpec.describe 'integration test' do - [Licensee::FSProject, Licensee::GitProject].each do |project_type| + [ + Licensee::Projects::FSProject, + Licensee::Projects::GitProject + ].each do |project_type| context "with a #{project_type} project" do let(:filename) { 'LICENSE' } let(:license) { Licensee::License.find('mit') } + let(:other_license) { Licensee::License.find('other') } let(:content) { license.content } let(:license_path) { File.expand_path(filename, project_path) } let(:arguments) { {} } subject { project_type.new(project_path, arguments) } @@ -12,11 +16,11 @@ context 'fixtures' do let(:fixture) { 'mit' } let(:project_path) { fixture_path(fixture) } let(:git_path) { File.expand_path('.git', project_path) } - if project_type == Licensee::GitProject + if project_type == Licensee::Projects::GitProject before { git_init(project_path) } after { FileUtils.rm_rf(git_path) } end context 'with a folder named license' do @@ -25,49 +29,79 @@ it "doesn't match" do expect(subject.license).to be_nil end end + context 'with no license files' do + let(:project_path) { Dir.mktmpdir } + let(:file_path) { File.expand_path('foo.md', project_path) } + + before do + File.write(file_path, 'bar') + if project_type == Licensee::Projects::GitProject + git_init(project_path) + end + end + + after { FileUtils.rm_rf(project_path) } + + it 'returns nil' do + expect(subject.license).to be_nil + expect(subject.license_files).to be_empty + + expect(subject.matched_file).to be_nil + expect(subject.matched_files).to be_empty + end + end + context 'with LICENSE.lesser' do let(:license) { Licensee::License.find('lgpl-3.0') } let(:fixture) { 'lgpl' } it 'matches to LGPL' do expect(subject.license).to eql(license) expect(subject.license_file.path).to eql('COPYING.lesser') end end + context 'with multiple license files' do + let(:fixture) { 'multiple-license-files' } + + it 'matches other' do + expect(subject.license).to eql(other_license) + end + end + context 'with CC-BY-NC-SA' do let(:fixture) { 'cc-by-nc-sa' } - it 'matches nothing' do - expect(subject.license).to eql(nil) + it 'matches other' do + expect(subject.license).to eql(other_license) end end context 'with CC-BY-ND' do let(:fixture) { 'cc-by-nd' } - it 'matches nothing' do - expect(subject.license).to eql(nil) + it 'matches other' do + expect(subject.license).to eql(other_license) end end context 'with WRK Modified Apache 2.0.1' do let(:fixture) { 'wrk-modified-apache' } - it 'matches nothing' do - expect(subject.license).to eql(nil) + it 'matches other' do + expect(subject.license).to eql(other_license) end end context 'with FCPL Modified MPL' do let(:fixture) { 'fcpl-modified-mpl' } - it 'matches nothing' do - expect(subject.license).to eql(nil) + it 'matches other' do + expect(subject.license).to eql(other_license) end end context 'MPL with HRs removed' do let(:license) { Licensee::License.find('mpl-2.0') } @@ -86,27 +120,37 @@ expect(subject.license).to eql(license) end end context 'DESCRIPTION file with a LICENSE file' do - let(:license) { Licensee::License.find('mit') } let(:fixture) { 'description-license' } let(:arguments) { { detect_packages: true } } + it 'matches other' do + expect(subject.license).to eql(other_license) + expect(subject.package_file.path).to eql('DESCRIPTION') + end + end + + context 'A license with CRLF line-endings' do + let(:license) { Licensee::License.find('gpl-3.0') } + let(:fixture) { 'crlf-license' } + it 'matches' do expect(subject.license).to eql(license) - expect(subject.package_file.path).to eql('DESCRIPTION') end end end context 'with the license file stubbed' do let(:project_path) { Dir.mktmpdir } before do File.write(license_path, content) - git_init(project_path) if project_type == Licensee::GitProject + if project_type == Licensee::Projects::GitProject + git_init(project_path) + end end after { FileUtils.rm_rf(project_path) } [ @@ -118,18 +162,9 @@ it 'matches the license file' do expect(subject.license).to eql(license) expect(subject.license_file.path).to eql(filename) end - end - end - - context 'an unlicensed project' do - let(:content) { '' } - - it "doesn't match" do - expect(subject.license).to be_nil - expect(subject.license_file.path).to eql('LICENSE') end end context 'a package.json file' do let(:content) { '{"license": "mit"}' }