license_finder 1.1.1-java → 1.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.rdoc +10 -0
  4. data/Gemfile +1 -1
  5. data/README.md +363 -0
  6. data/Rakefile +30 -1
  7. data/TODO.md +28 -0
  8. data/bin/license_finder_pip.py +18 -0
  9. data/db/migrate/201410031451_rename_dependency_license_name.rb +6 -0
  10. data/features/multiple_licenses.feature +9 -0
  11. data/features/step_definitions/cli_steps.rb +9 -9
  12. data/features/step_definitions/cocoapod_steps.rb +1 -1
  13. data/features/step_definitions/configure_bundler_groups_steps.rb +3 -3
  14. data/features/step_definitions/configure_whitelist_steps.rb +4 -4
  15. data/features/step_definitions/gradle_steps.rb +1 -1
  16. data/features/step_definitions/manually_added_steps.rb +3 -3
  17. data/features/step_definitions/manually_approved_steps.rb +5 -5
  18. data/features/step_definitions/manually_assigned_license_steps.rb +4 -4
  19. data/features/step_definitions/maven_steps.rb +1 -1
  20. data/features/step_definitions/multiple_licenses_steps.rb +14 -0
  21. data/features/step_definitions/node_steps.rb +1 -1
  22. data/features/step_definitions/python_steps.rb +1 -1
  23. data/features/step_definitions/report_csv_steps.rb +3 -3
  24. data/features/step_definitions/report_html_steps.rb +5 -5
  25. data/features/step_definitions/shared_steps.rb +23 -6
  26. data/lib/license_finder.rb +3 -0
  27. data/lib/license_finder/cli.rb +13 -34
  28. data/lib/license_finder/configuration.rb +8 -4
  29. data/lib/license_finder/dependency_manager.rb +25 -15
  30. data/lib/license_finder/license.rb +8 -0
  31. data/lib/license_finder/logger.rb +59 -0
  32. data/lib/license_finder/package.rb +37 -30
  33. data/lib/license_finder/package_manager.rb +20 -0
  34. data/lib/license_finder/package_managers/bower.rb +4 -9
  35. data/lib/license_finder/package_managers/bower_package.rb +2 -1
  36. data/lib/license_finder/package_managers/bundler.rb +26 -41
  37. data/lib/license_finder/package_managers/bundler_package.rb +6 -3
  38. data/lib/license_finder/package_managers/cocoa_pods.rb +18 -10
  39. data/lib/license_finder/package_managers/cocoa_pods_package.rb +4 -3
  40. data/lib/license_finder/package_managers/gradle.rb +7 -11
  41. data/lib/license_finder/package_managers/gradle_package.rb +2 -7
  42. data/lib/license_finder/package_managers/maven.rb +5 -9
  43. data/lib/license_finder/package_managers/maven_package.rb +4 -8
  44. data/lib/license_finder/package_managers/npm.rb +6 -10
  45. data/lib/license_finder/package_managers/npm_package.rb +2 -1
  46. data/lib/license_finder/package_managers/pip.rb +11 -24
  47. data/lib/license_finder/package_managers/pip_package.rb +2 -1
  48. data/lib/license_finder/package_saver.rb +2 -2
  49. data/lib/license_finder/platform.rb +4 -0
  50. data/lib/license_finder/possible_license_file.rb +4 -0
  51. data/lib/license_finder/possible_license_files.rb +2 -1
  52. data/lib/license_finder/reports/detailed_text_report.rb +1 -1
  53. data/lib/license_finder/reports/formatted_report.rb +1 -1
  54. data/lib/license_finder/tables/dependency.rb +22 -12
  55. data/lib/license_finder/yml_to_sql.rb +1 -1
  56. data/lib/templates/html_report.erb +4 -4
  57. data/lib/templates/markdown_report.erb +4 -4
  58. data/lib/templates/text_report.erb +1 -1
  59. data/license_finder.gemspec +28 -12
  60. data/spec/lib/license_finder/cli_spec.rb +193 -185
  61. data/spec/lib/license_finder/configuration_spec.rb +46 -47
  62. data/spec/lib/license_finder/dependency_manager_spec.rb +48 -44
  63. data/spec/lib/license_finder/license/definitions_spec.rb +26 -26
  64. data/spec/lib/license_finder/license_spec.rb +25 -25
  65. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -17
  66. data/spec/lib/license_finder/package_managers/bower_spec.rb +35 -35
  67. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +20 -15
  68. data/spec/lib/license_finder/package_managers/bundler_spec.rb +12 -19
  69. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -5
  70. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +20 -22
  71. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +8 -5
  72. data/spec/lib/license_finder/package_managers/gradle_spec.rb +20 -20
  73. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +8 -5
  74. data/spec/lib/license_finder/package_managers/maven_spec.rb +18 -18
  75. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +36 -17
  76. data/spec/lib/license_finder/package_managers/npm_spec.rb +17 -17
  77. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +16 -10
  78. data/spec/lib/license_finder/package_managers/pip_spec.rb +21 -18
  79. data/spec/lib/license_finder/package_saver_spec.rb +15 -25
  80. data/spec/lib/license_finder/possible_license_file_spec.rb +5 -4
  81. data/spec/lib/license_finder/possible_license_files_spec.rb +11 -5
  82. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +3 -3
  83. data/spec/lib/license_finder/reports/html_report_spec.rb +23 -23
  84. data/spec/lib/license_finder/reports/markdown_report_spec.rb +12 -12
  85. data/spec/lib/license_finder/reports/reporter_spec.rb +11 -11
  86. data/spec/lib/license_finder/reports/text_report_spec.rb +3 -3
  87. data/spec/lib/license_finder/tables/dependency_spec.rb +59 -41
  88. data/spec/lib/license_finder/yml_to_sql_spec.rb +21 -21
  89. data/spec/lib/license_finder_spec.rb +1 -1
  90. data/spec/spec_helper.rb +0 -13
  91. data/spec/support/shared_examples_for_package.rb +46 -0
  92. data/spec/support/shared_examples_for_package_manager.rb +15 -0
  93. metadata +19 -100
  94. data/readme.md +0 -259
@@ -7,7 +7,7 @@ module LicenseFinder
7
7
  end
8
8
  let(:license_text) { nil }
9
9
 
10
- it_behaves_like "it conforms to interface required by PackageSaver"
10
+ it_behaves_like "a Package"
11
11
 
12
12
  its(:name) { should == "Name" }
13
13
  its(:version) { should == "1.0.0" }
@@ -17,7 +17,7 @@ module LicenseFinder
17
17
  its(:groups) { should == [] }
18
18
  its(:children) { should == [] }
19
19
 
20
- describe '#license' do
20
+ describe '#licenses' do
21
21
  context "when there's a license" do
22
22
  let(:license_text) { "LicenseText" }
23
23
 
@@ -25,18 +25,21 @@ module LicenseFinder
25
25
  license = double(:license, name: "LicenseName")
26
26
  allow(License).to receive(:find_by_text).with(license_text).and_return(license)
27
27
 
28
- expect(subject.license.name).to eq "LicenseName"
28
+ expect(subject.licenses.length).to eq 1
29
+ expect(subject.licenses.first.name).to eq "LicenseName"
29
30
  end
30
31
 
31
32
  it "returns other if the license can't be found by text" do
32
33
  allow(License).to receive(:find_by_text).with(license_text).and_return(nil)
33
34
 
34
- expect(subject.license.name).to eq "other"
35
+ expect(subject.licenses.length).to eq 1
36
+ expect(subject.licenses.first.name).to eq "other"
35
37
  end
36
38
  end
37
39
 
38
40
  it "returns other when there's no license" do
39
- expect(subject.license.name).to eq "other"
41
+ expect(subject.licenses.length).to eq 1
42
+ expect(subject.licenses.first.name).to eq "other"
40
43
  end
41
44
  end
42
45
  end
@@ -2,19 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe CocoaPods do
5
+ let(:cocoa_pods) { CocoaPods.new }
6
+ it_behaves_like "a PackageManager"
7
+
5
8
  def stub_acknowledgments(hash = {})
6
- plist_json = %{
7
- {
8
- "PreferenceSpecifiers": [
9
- {
10
- "FooterText": "#{hash[:license]}",
11
- "Title": "#{hash[:name]}"
12
- }
13
- ]
14
- }
9
+ plist = {
10
+ "PreferenceSpecifiers" => [
11
+ {
12
+ "FooterText" => hash[:license],
13
+ "Title" => hash[:name]
14
+ }
15
+ ]
15
16
  }
16
17
 
17
- expect(described_class).to receive(:`).with(/plutil/).and_return(plist_json)
18
+ expect(cocoa_pods).to receive(:read_plist).and_return(plist)
18
19
  end
19
20
 
20
21
  def stub_lockfile(pods)
@@ -34,7 +35,7 @@ module LicenseFinder
34
35
  expect(CocoaPodsPackage).to receive(:new).with("JSONKit", "1.5pre", anything)
35
36
  expect(CocoaPodsPackage).to receive(:new).with("OpenUDID", "1.0.0", anything)
36
37
 
37
- current_packages = CocoaPods.current_packages
38
+ current_packages = cocoa_pods.current_packages
38
39
 
39
40
  expect(current_packages.size).to eq(3)
40
41
  end
@@ -45,7 +46,7 @@ module LicenseFinder
45
46
 
46
47
  expect(CocoaPodsPackage).to receive(:new).with("Dependency Name", "1.0", "License Text")
47
48
 
48
- CocoaPods.current_packages
49
+ cocoa_pods.current_packages
49
50
  end
50
51
 
51
52
  it "handles no licenses" do
@@ -54,25 +55,22 @@ module LicenseFinder
54
55
 
55
56
  expect(CocoaPodsPackage).to receive(:new).with("Dependency Name", "1.0", nil)
56
57
 
57
- CocoaPods.current_packages
58
+ cocoa_pods.current_packages
58
59
  end
59
60
  end
60
61
 
61
62
  describe '.active?' do
62
- let(:package) { double(:package_file) }
63
-
64
- before do
65
- CocoaPods.stub(package_path: package)
66
- end
63
+ let(:package_path) { double(:package_file) }
64
+ let(:cocoa_pods) { CocoaPods.new package_path: package_path }
67
65
 
68
66
  it 'is true with a Podfile file' do
69
- package.stub(:exist? => true)
70
- expect(CocoaPods).to be_active
67
+ allow(package_path).to receive_messages(:exist? => true)
68
+ expect(cocoa_pods).to be_active
71
69
  end
72
70
 
73
71
  it 'is false without a Podfile file' do
74
- package.stub(:exist? => false)
75
- expect(CocoaPods).to_not be_active
72
+ allow(package_path).to receive_messages(:exist? => false)
73
+ expect(cocoa_pods).to_not be_active
76
74
  end
77
75
  end
78
76
  end
@@ -14,15 +14,16 @@ module LicenseFinder
14
14
  )
15
15
  end
16
16
 
17
- it_behaves_like "it conforms to interface required by PackageSaver"
17
+ it_behaves_like "a Package"
18
18
 
19
19
  its(:name) { should == "logback-classic" }
20
20
  its(:version) { should == "1.1.1" }
21
21
  its(:description) { should == "" }
22
22
 
23
- describe "#license" do
23
+ describe "#licenses" do
24
24
  it "returns the license if found" do
25
- subject.license.name.should == "Eclipse Public License - v 1.0"
25
+ expect(subject.licenses.length).to eq 1
26
+ expect(subject.licenses.first.name).to eq "Eclipse Public License - v 1.0"
26
27
  end
27
28
 
28
29
  context "when there are multiple licenses" do
@@ -40,7 +41,8 @@ module LicenseFinder
40
41
  end
41
42
 
42
43
  it "returns 'multiple licenses'" do
43
- subject.license.name.should == 'multiple licenses: Eclipse Public License - v 1.0, GNU Lesser General Public License'
44
+ expect(subject.licenses.length).to eq 2
45
+ expect(subject.licenses.map(&:name)).to eq ['Eclipse Public License - v 1.0', 'GNU Lesser General Public License']
44
46
  end
45
47
  end
46
48
 
@@ -56,7 +58,8 @@ module LicenseFinder
56
58
  end
57
59
 
58
60
  it "returns 'other' otherwise" do
59
- subject.license.name.should == "other"
61
+ expect(subject.licenses.length).to eq 1
62
+ expect(subject.licenses.first.name).to eq "other"
60
63
  end
61
64
  end
62
65
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe Gradle do
5
+ let(:gradle) { Gradle.new }
6
+ it_behaves_like "a PackageManager"
7
+
5
8
  def license_xml(xml)
6
9
  <<-resp
7
10
  <dependencies>
@@ -13,7 +16,7 @@ module LicenseFinder
13
16
  describe '.current_packages' do
14
17
  before do
15
18
  allow(LicenseFinder.config).to receive(:gradle_command) { 'gradlefoo' }
16
- expect(described_class).to receive(:`).with(/gradlefoo downloadLicenses/)
19
+ expect(gradle).to receive('`').with(/gradlefoo downloadLicenses/)
17
20
  end
18
21
 
19
22
  it 'lists all the current packages' do
@@ -28,9 +31,9 @@ module LicenseFinder
28
31
  </dependency>
29
32
  """)
30
33
  fake_file = double(:license_report, read: license_xml)
31
- allow(Gradle).to receive(:license_report).and_return(fake_file)
34
+ allow(gradle).to receive(:license_report).and_return(fake_file)
32
35
 
33
- current_packages = described_class.current_packages
36
+ current_packages = gradle.current_packages
34
37
 
35
38
  expect(current_packages.size).to eq(2)
36
39
  expect(current_packages.first).to be_a(Package)
@@ -45,10 +48,10 @@ module LicenseFinder
45
48
  """)
46
49
 
47
50
  fake_file = double(:license_report, read: license_xml)
48
- allow(Gradle).to receive(:license_report).and_return(fake_file)
51
+ allow(gradle).to receive(:license_report).and_return(fake_file)
49
52
 
50
- GradlePackage.should_receive(:new).with("license" => [{"name" => "License 1"}, {"name" => "License 2"}])
51
- Gradle.current_packages
53
+ expect(GradlePackage).to receive(:new).with({"license" => [{"name" => "License 1"}, {"name" => "License 2"}]}, anything)
54
+ gradle.current_packages
52
55
  end
53
56
 
54
57
  it "handles no licenses" do
@@ -59,36 +62,33 @@ module LicenseFinder
59
62
  """)
60
63
 
61
64
  fake_file = double(:license_report, read: license_xml)
62
- allow(Gradle).to receive(:license_report).and_return(fake_file)
65
+ allow(gradle).to receive(:license_report).and_return(fake_file)
63
66
 
64
- GradlePackage.should_receive(:new).with("license" => [])
65
- Gradle.current_packages
67
+ expect(GradlePackage).to receive(:new).with({"license" => []}, anything)
68
+ gradle.current_packages
66
69
  end
67
70
 
68
71
  it "handles an empty list of licenses" do
69
72
  license_xml = license_xml("")
70
73
 
71
74
  fake_file = double(:license_report, read: license_xml)
72
- allow(Gradle).to receive(:license_report).and_return(fake_file)
73
- Gradle.current_packages
75
+ allow(gradle).to receive(:license_report).and_return(fake_file)
76
+ gradle.current_packages
74
77
  end
75
78
  end
76
79
 
77
80
  describe '.active?' do
78
- let(:package) { double(:package_file) }
79
-
80
- before do
81
- Gradle.stub(package_path: package)
82
- end
81
+ let(:package_path) { double(:package_file) }
82
+ let(:gradle) { Gradle.new package_path: package_path }
83
83
 
84
84
  it 'is true with a build.gradle file' do
85
- package.stub(:exist? => true)
86
- expect(Gradle).to be_active
85
+ allow(package_path).to receive_messages(:exist? => true)
86
+ expect(gradle).to be_active
87
87
  end
88
88
 
89
89
  it 'is false without a build.gradle file' do
90
- package.stub(:exist? => false)
91
- expect(Gradle).to_not be_active
90
+ allow(package_path).to receive_messages(:exist? => false)
91
+ expect(gradle).to_not be_active
92
92
  end
93
93
  end
94
94
  end
@@ -16,15 +16,16 @@ module LicenseFinder
16
16
  )
17
17
  end
18
18
 
19
- it_behaves_like "it conforms to interface required by PackageSaver"
19
+ it_behaves_like "a Package"
20
20
 
21
21
  its(:name) { should == "hamcrest-core" }
22
22
  its(:version) { should == "4.11" }
23
23
  its(:description) { should == "" }
24
24
 
25
- describe "#license" do
25
+ describe "#licenses" do
26
26
  it "returns the license if found" do
27
- subject.license.name.should == "Common Public License Version 1.0"
27
+ expect(subject.licenses.length).to eq 1
28
+ expect(subject.licenses.first.name).to eq "Common Public License Version 1.0"
28
29
  end
29
30
 
30
31
  context "when there are multiple licenses" do
@@ -46,7 +47,8 @@ module LicenseFinder
46
47
  end
47
48
 
48
49
  it "returns 'multiple licenses'" do
49
- subject.license.name.should == 'multiple licenses: Common Public License Version 1.0, Apache 2'
50
+ expect(subject.licenses.length).to eq 2
51
+ expect(subject.licenses.map(&:name)).to eq ['Common Public License Version 1.0', 'Apache 2']
50
52
  end
51
53
  end
52
54
 
@@ -62,7 +64,8 @@ module LicenseFinder
62
64
  end
63
65
 
64
66
  it "returns 'other' otherwise" do
65
- subject.license.name.should == "other"
67
+ expect(subject.licenses.length).to eq 1
68
+ expect(subject.licenses.first.name).to eq "other"
66
69
  end
67
70
  end
68
71
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe Maven do
5
+ let(:maven) { Maven.new }
6
+ it_behaves_like "a PackageManager"
7
+
5
8
  def license_xml(xml)
6
9
  <<-resp
7
10
  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
@@ -15,7 +18,7 @@ module LicenseFinder
15
18
 
16
19
  describe '.current_packages' do
17
20
  before do
18
- expect(described_class).to receive(:`).with(/mvn/)
21
+ expect(maven).to receive('`').with(/mvn/)
19
22
  end
20
23
 
21
24
  it 'lists all the current packages' do
@@ -45,9 +48,9 @@ module LicenseFinder
45
48
  </dependency>
46
49
  """)
47
50
  fake_file = double(:license_report, read: license_xml)
48
- allow(Maven).to receive(:license_report).and_return(fake_file)
51
+ allow(maven).to receive(:license_report).and_return(fake_file)
49
52
 
50
- current_packages = Maven.current_packages
53
+ current_packages = maven.current_packages
51
54
 
52
55
  expect(current_packages.size).to eq(2)
53
56
  expect(current_packages.first).to be_a(Package)
@@ -68,10 +71,10 @@ module LicenseFinder
68
71
  """)
69
72
 
70
73
  fake_file = double(:license_report, read: license_xml)
71
- allow(Maven).to receive(:license_report).and_return(fake_file)
74
+ allow(maven).to receive(:license_report).and_return(fake_file)
72
75
 
73
- MavenPackage.should_receive(:new).with("licenses" => [{"name" => "License 1"}, {"name" => "License 2"}])
74
- Maven.current_packages
76
+ expect(MavenPackage).to receive(:new).with({"licenses" => [{"name" => "License 1"}, {"name" => "License 2"}]}, anything)
77
+ maven.current_packages
75
78
  end
76
79
 
77
80
  it "handles no licenses" do
@@ -84,28 +87,25 @@ module LicenseFinder
84
87
  """)
85
88
 
86
89
  fake_file = double(:license_report, read: license_xml)
87
- allow(Maven).to receive(:license_report).and_return(fake_file)
90
+ allow(maven).to receive(:license_report).and_return(fake_file)
88
91
 
89
- MavenPackage.should_receive(:new).with("licenses" => {})
90
- Maven.current_packages
92
+ expect(MavenPackage).to receive(:new).with({"licenses" => {}}, anything)
93
+ maven.current_packages
91
94
  end
92
95
  end
93
96
 
94
97
  describe '.active?' do
95
- let(:package) { double(:package_file) }
96
-
97
- before do
98
- allow(Maven).to receive(:package_path).and_return(package)
99
- end
98
+ let(:package_path) { double(:package_file) }
99
+ let(:maven) { Maven.new package_path: package_path }
100
100
 
101
101
  it 'is true with a pom.xml file' do
102
- allow(package).to receive(:exist?).and_return(true)
103
- expect(Maven.active?).to eq(true)
102
+ allow(package_path).to receive(:exist?).and_return(true)
103
+ expect(maven.active?).to eq(true)
104
104
  end
105
105
 
106
106
  it 'is false without a pom.xml file' do
107
- allow(package).to receive(:exist?).and_return(false)
108
- expect(Maven.active?).to eq(false)
107
+ allow(package_path).to receive(:exist?).and_return(false)
108
+ expect(maven.active?).to eq(false)
109
109
  end
110
110
  end
111
111
  end
@@ -13,7 +13,7 @@ module LicenseFinder
13
13
  )
14
14
  end
15
15
 
16
- it_behaves_like "it conforms to interface required by PackageSaver"
16
+ it_behaves_like "a Package"
17
17
 
18
18
  its(:name) { should == "jasmine-node" }
19
19
  its(:version) { should == "1.3.1" }
@@ -23,9 +23,9 @@ module LicenseFinder
23
23
  its(:groups) { should == [] }
24
24
  its(:children) { should == [] }
25
25
 
26
- describe '#license' do
26
+ describe '#licenses' do
27
27
  def stub_license_files(license_files)
28
- PossibleLicenseFiles.stub(:find).with("some/node/package/path").and_return(license_files)
28
+ allow(PossibleLicenseFiles).to receive(:find).with("some/node/package/path").and_return(license_files)
29
29
  end
30
30
 
31
31
  let(:node_module1) { {"license" => "MIT", "path" => "/some/path"} }
@@ -35,11 +35,25 @@ module LicenseFinder
35
35
  let(:misdeclared_node_module) { {"licenses" => {"type" => "MIT"}} }
36
36
 
37
37
  it 'finds the license for both license structures' do
38
- NpmPackage.new(node_module1).license.name.should eq("MIT")
39
- NpmPackage.new(node_module2).license.name.should eq("BSD")
40
- NpmPackage.new(node_module3).license.name.should eq("Python Software Foundation License")
41
- NpmPackage.new(node_module4).license.name.should eq("MIT")
42
- NpmPackage.new(misdeclared_node_module).license.name.should eq("MIT")
38
+ package = NpmPackage.new(node_module1)
39
+ expect(package.licenses.length).to eq 1
40
+ expect(package.licenses.first.name).to eq("MIT")
41
+
42
+ package = NpmPackage.new(node_module2)
43
+ expect(package.licenses.length).to eq 1
44
+ expect(package.licenses.first.name).to eq("BSD")
45
+
46
+ package = NpmPackage.new(node_module3)
47
+ expect(package.licenses.length).to eq 1
48
+ expect(package.licenses.first.name).to eq("Python Software Foundation License")
49
+
50
+ package = NpmPackage.new(node_module4)
51
+ expect(package.licenses.length).to eq 1
52
+ expect(package.licenses.first.name).to eq("MIT")
53
+
54
+ package = NpmPackage.new(misdeclared_node_module)
55
+ expect(package.licenses.length).to eq 1
56
+ expect(package.licenses.first.name).to eq("MIT")
43
57
  end
44
58
 
45
59
  context "regardless of whether there are licenses in files" do
@@ -49,38 +63,43 @@ module LicenseFinder
49
63
 
50
64
  it "returns the license from the spec if there is only one unique license" do
51
65
  package = NpmPackage.new({ "licenses" => ["MIT", "Expat"], "path" => "/path/to/thing" })
52
- expect(package.license.name).to eq("MIT")
66
+ expect(package.licenses.length).to eq 1
67
+ expect(package.licenses.first.name).to eq("MIT")
53
68
  end
54
69
 
55
70
  it "returns 'multiple licenses' if there's more than one license" do
56
71
  package = NpmPackage.new({ "licenses" => ["MIT", "BSD"], "path" => "/some/path" })
57
- expect(package.license.name).to eq("multiple licenses: MIT, BSD")
72
+ expect(package.licenses.length).to eq 2
73
+ expect(package.licenses.map(&:name)).to eq %w(MIT BSD)
58
74
  end
59
75
  end
60
76
 
61
77
  context "when there is nothing in the spec" do
62
78
  it "returns a license in a file if only one unique license detected" do
63
79
  stub_license_files([
64
- double(:first_file, license: License.find_by_name('MIT')),
65
- double(:second_file, license: License.find_by_name('Expat'))
80
+ double(:first_file, license: License.find_by_name('MIT'), path: "/"),
81
+ double(:second_file, license: License.find_by_name('Expat'), path: "/")
66
82
  ])
67
83
 
68
- subject.license.name.should == "MIT"
84
+ expect(subject.licenses.length).to eq 1
85
+ expect(subject.licenses.first.name).to eq "MIT"
69
86
  end
70
87
 
71
88
  it "returns 'other' if there are no licenses in files" do
72
89
  stub_license_files []
73
90
 
74
- subject.license.name.should == "other"
91
+ expect(subject.licenses.length).to eq 1
92
+ expect(subject.licenses.first.name).to eq "other"
75
93
  end
76
94
 
77
95
  it "returns 'other' if there are many licenses in files" do
78
96
  stub_license_files([
79
- double(:first_file, license: License.find_by_name('First Detected License')),
80
- double(:second_file, license: License.find_by_name('Second Detected License'))
97
+ double(:first_file, license: License.find_by_name('First Detected License'), path: "/"),
98
+ double(:second_file, license: License.find_by_name('Second Detected License'), path: "/")
81
99
  ])
82
100
 
83
- subject.license.name.should == "multiple licenses: First Detected License, Second Detected License"
101
+ expect(subject.licenses.length).to eq 2
102
+ expect(subject.licenses.map(&:name)).to eq ["First Detected License", "Second Detected License"]
84
103
  end
85
104
  end
86
105
  end