license_finder 2.0.4 → 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -4
  3. data/.travis/install_godep.sh +6 -0
  4. data/.travis/install_gradle.sh +1 -1
  5. data/.travis/install_rebar.sh +7 -5
  6. data/CHANGELOG.rdoc +13 -0
  7. data/CONTRIBUTING.md +16 -2
  8. data/README.md +41 -4
  9. data/Rakefile +8 -2
  10. data/features/features/{cli_spec.rb → cli/cli_spec.rb} +24 -18
  11. data/features/features/configure/add_dependencies_spec.rb +18 -1
  12. data/features/features/configure/approve_dependencies_spec.rb +31 -1
  13. data/features/features/configure/assign_licenses_spec.rb +18 -3
  14. data/features/features/configure/blacklist_licenses_spec.rb +30 -0
  15. data/features/features/configure/ignore_dependencies_spec.rb +1 -1
  16. data/features/features/configure/ignore_groups_spec.rb +16 -1
  17. data/features/features/configure/name_project_spec.rb +1 -1
  18. data/features/features/configure/set_project_path_spec.rb +1 -1
  19. data/features/features/configure/whitelist_licenses_spec.rb +1 -3
  20. data/features/features/package_managers/bower_spec.rb +1 -1
  21. data/features/features/package_managers/cocoapods_spec.rb +1 -1
  22. data/features/features/package_managers/godep_spec.rb +17 -0
  23. data/features/features/package_managers/gradle_spec.rb +18 -4
  24. data/features/features/package_managers/maven_spec.rb +1 -1
  25. data/features/features/package_managers/npm_spec.rb +1 -1
  26. data/features/features/package_managers/nuget_spec.rb +14 -0
  27. data/features/features/package_managers/pip_spec.rb +1 -1
  28. data/features/features/package_managers/rebar_spec.rb +1 -1
  29. data/features/features/report/composite_spec.rb +15 -0
  30. data/features/features/report/csv_spec.rb +1 -1
  31. data/features/features/report/diff_spec.rb +190 -0
  32. data/features/features/report/html_spec.rb +1 -1
  33. data/features/features/report/subproject_spec.rb +52 -0
  34. data/features/fixtures/file-based-libs-gradle/build.gradle +18 -0
  35. data/features/fixtures/file-based-libs-gradle/libs/data.json-0.2.3.jar +0 -0
  36. data/features/fixtures/gopath/src/github.com/pivotal/foo/Godeps/Godeps.json +16 -0
  37. data/features/fixtures/gopath/src/github.com/pivotal/foo/Godeps/Readme +5 -0
  38. data/features/fixtures/gopath/src/github.com/pivotal/foo/foo.go +6 -0
  39. data/features/fixtures/multi-module-gradle/build.gradle +18 -0
  40. data/features/fixtures/multi-module-gradle/module1/build.gradle +3 -0
  41. data/features/fixtures/multi-module-gradle/module2/build.gradle +3 -0
  42. data/features/fixtures/multi-module-gradle/settings.gradle +1 -0
  43. data/features/fixtures/nuget/Fun.Test/packages.config +4 -0
  44. data/features/fixtures/nuget/Fun/packages.config +5 -0
  45. data/features/fixtures/nuget/packages/Microsoft.AspNet.Mvc.4.0.30506.0/.keep +0 -0
  46. data/features/fixtures/nuget/packages/NUnit.2.6.4/.keep +0 -0
  47. data/features/fixtures/nuget/packages/Ninject.MVC4.3.2.1.0/.keep +0 -0
  48. data/features/fixtures/nuget/packages/repositories.config +6 -0
  49. data/features/fixtures/{build.gradle → single-module-gradle/build.gradle} +0 -0
  50. data/{spec → features/support}/feature_helper.rb +5 -1
  51. data/features/support/testing_dsl.rb +297 -212
  52. data/lib/license_finder/cli.rb +1 -0
  53. data/lib/license_finder/cli/base.rb +16 -3
  54. data/lib/license_finder/cli/blacklist.rb +30 -0
  55. data/lib/license_finder/cli/main.rb +62 -4
  56. data/lib/license_finder/configuration.rb +39 -8
  57. data/lib/license_finder/core.rb +13 -10
  58. data/lib/license_finder/decision_applier.rb +14 -9
  59. data/lib/license_finder/decisions.rb +24 -6
  60. data/lib/license_finder/diff.rb +47 -0
  61. data/lib/license_finder/license_aggregator.rb +25 -0
  62. data/lib/license_finder/package.rb +39 -6
  63. data/lib/license_finder/package_delta.rb +65 -0
  64. data/lib/license_finder/package_manager.rb +10 -3
  65. data/lib/license_finder/package_managers/bower.rb +3 -1
  66. data/lib/license_finder/package_managers/bundler.rb +18 -9
  67. data/lib/license_finder/package_managers/bundler_package.rb +6 -2
  68. data/lib/license_finder/package_managers/go_dep.rb +25 -0
  69. data/lib/license_finder/package_managers/go_package.rb +19 -0
  70. data/lib/license_finder/package_managers/go_workspace.rb +35 -0
  71. data/lib/license_finder/package_managers/gradle.rb +16 -17
  72. data/lib/license_finder/package_managers/gradle_dependency_finder.rb +13 -0
  73. data/lib/license_finder/package_managers/gradle_package.rb +6 -1
  74. data/lib/license_finder/package_managers/maven.rb +3 -1
  75. data/lib/license_finder/package_managers/merged_package.rb +43 -0
  76. data/lib/license_finder/package_managers/npm.rb +42 -24
  77. data/lib/license_finder/package_managers/nuget.rb +50 -0
  78. data/lib/license_finder/package_managers/nuget_package.rb +4 -0
  79. data/lib/license_finder/package_managers/pip_package.rb +1 -0
  80. data/lib/license_finder/package_managers/rebar.rb +2 -6
  81. data/lib/license_finder/platform.rb +4 -1
  82. data/lib/license_finder/project_finder.rb +56 -0
  83. data/lib/license_finder/report.rb +3 -2
  84. data/lib/license_finder/reports/csv_report.rb +6 -2
  85. data/lib/license_finder/reports/diff_report.rb +33 -0
  86. data/lib/license_finder/reports/merged_report.rb +13 -0
  87. data/lib/license_finder/version.rb +1 -1
  88. data/license_finder.gemspec +6 -2
  89. data/spec/dummy_app/Gemfile +6 -0
  90. data/spec/fixtures/all_pms/.envrc +0 -0
  91. data/spec/fixtures/all_pms/Godeps/Godeps.json +0 -0
  92. data/spec/fixtures/all_pms/packages/.keep +0 -0
  93. data/spec/fixtures/composite/Gemfile +0 -0
  94. data/spec/fixtures/composite/nested_project/.envrc +8 -0
  95. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Godeps.json +16 -0
  96. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Readme +5 -0
  97. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/foo.go +6 -0
  98. data/spec/fixtures/composite/not_a_project/DONTREADME.md +0 -0
  99. data/spec/fixtures/composite/project1/Gemfile +0 -0
  100. data/spec/fixtures/composite/project2/package.json +0 -0
  101. data/spec/lib/license_finder/cli/approvals_spec.rb +1 -1
  102. data/spec/lib/license_finder/cli/blacklist_spec.rb +58 -0
  103. data/spec/lib/license_finder/cli/dependencies_spec.rb +1 -1
  104. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +1 -1
  105. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +1 -1
  106. data/spec/lib/license_finder/cli/licenses_spec.rb +1 -1
  107. data/spec/lib/license_finder/cli/main_spec.rb +113 -7
  108. data/spec/lib/license_finder/cli/project_name_spec.rb +1 -1
  109. data/spec/lib/license_finder/cli/whitelist_spec.rb +1 -1
  110. data/spec/lib/license_finder/configuration_spec.rb +63 -4
  111. data/spec/lib/license_finder/core_spec.rb +49 -0
  112. data/spec/lib/license_finder/decision_applier_spec.rb +101 -1
  113. data/spec/lib/license_finder/decisions_spec.rb +62 -0
  114. data/spec/lib/license_finder/diff_spec.rb +106 -0
  115. data/spec/lib/license_finder/license_aggregator_spec.rb +61 -0
  116. data/spec/lib/license_finder/package_delta_spec.rb +18 -0
  117. data/spec/lib/license_finder/package_managers/bower_spec.rb +8 -6
  118. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +4 -2
  119. data/spec/lib/license_finder/package_managers/go_dep_spec.rb +72 -0
  120. data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +69 -0
  121. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +9 -0
  122. data/spec/lib/license_finder/package_managers/gradle_spec.rb +94 -44
  123. data/spec/lib/license_finder/package_managers/maven_spec.rb +8 -6
  124. data/spec/lib/license_finder/package_managers/merged_package_spec.rb +52 -0
  125. data/spec/lib/license_finder/package_managers/npm_spec.rb +59 -20
  126. data/spec/lib/license_finder/package_managers/nuget_spec.rb +82 -0
  127. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +1 -0
  128. data/spec/lib/license_finder/package_managers/rebar_spec.rb +12 -12
  129. data/spec/lib/license_finder/package_spec.rb +59 -2
  130. data/spec/lib/license_finder/project_finder_spec.rb +33 -0
  131. data/spec/lib/license_finder/reports/csv_report_spec.rb +9 -3
  132. data/spec/lib/license_finder/reports/diff_report_spec.rb +56 -0
  133. data/spec/lib/license_finder/reports/merged_report_spec.rb +21 -0
  134. metadata +82 -9
  135. data/.travis/install_virtualenv.sh +0 -9
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ describe Core do
5
+ let(:options) { {} }
6
+ let(:license_finder) { described_class.new(options) }
7
+ let(:logger) { Logger.new(options[:logger]) }
8
+ let(:configuration) { LicenseFinder::Configuration.new(options, {})}
9
+ let(:pathname) { Pathname.pwd + Pathname(options[:project_path]) }
10
+
11
+ before do
12
+ allow(Logger).to receive(:new).and_return(logger)
13
+ end
14
+
15
+ describe "#unapproved" do
16
+ let(:options) {
17
+ {
18
+ logger: {},
19
+ project_path: 'other_directory',
20
+ gradle_command: 'just_do_it',
21
+ rebar_command: 'do_it',
22
+ rebar_deps_dir: 'nowhere/deps'
23
+ }
24
+ }
25
+ let(:package_options) {
26
+ {
27
+ logger: logger,
28
+ project_path: configuration.project_path,
29
+ ignore_groups: Set.new,
30
+ gradle_command: configuration.gradle_command,
31
+ rebar_command: configuration.rebar_command,
32
+ rebar_deps_dir: configuration.rebar_deps_dir
33
+ }
34
+ }
35
+
36
+ it "delegates to the decision_applier" do
37
+ decision_applier = double(:decision_applier)
38
+ allow(license_finder).to receive(:decision_applier).and_return(decision_applier)
39
+ expect(decision_applier).to receive(:unapproved)
40
+ license_finder.unapproved
41
+ end
42
+
43
+ it "passes through options when fetching current packages" do
44
+ expect(PackageManager).to receive(:current_packages).with(package_options).and_return([])
45
+ license_finder.unapproved
46
+ end
47
+ end
48
+ end
49
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe DecisionApplier do
5
- describe ".acknowledged" do
5
+ describe "#acknowledged" do
6
6
  it "combines manual and system packages" do
7
7
  decision_applier = described_class.new(
8
8
  decisions: Decisions.new.add_package("manual", nil),
@@ -38,6 +38,29 @@ module LicenseFinder
38
38
  expect(decision_applier.acknowledged).to be_empty
39
39
  end
40
40
 
41
+ it "does not ignore packages if some of their groups are not ignored" do
42
+ decisions = Decisions.new
43
+ .ignore_group("development")
44
+ dev_and_prod_dep = Package.new("dev_and_prod_dep", nil, groups: ["development", "production"])
45
+ decision_applier = described_class.new(
46
+ decisions: decisions,
47
+ packages: [dev_and_prod_dep]
48
+ )
49
+ expect(decision_applier.acknowledged).to eq [dev_and_prod_dep]
50
+ end
51
+
52
+ it "does not ignore packages if they have no groups" do
53
+ decisions = Decisions.new
54
+ .ignore_group("development")
55
+ dep_with_no_group = Package.new("dep_with_no_group", nil, groups: [])
56
+ decision_applier = described_class.new(
57
+ decisions: decisions,
58
+ packages: [dep_with_no_group]
59
+ )
60
+ expect(decision_applier.acknowledged).to eq [dep_with_no_group]
61
+ end
62
+
63
+
41
64
  it "adds manual approvals to packages" do
42
65
  decisions = Decisions.new
43
66
  .add_package("manual", nil)
@@ -60,6 +83,83 @@ module LicenseFinder
60
83
  expect(dep).to be_approved
61
84
  expect(dep).to be_whitelisted
62
85
  end
86
+
87
+ it "forbids approval of packages with only blacklisted license" do
88
+ decisions = Decisions.new
89
+ .add_package("manual", nil)
90
+ .license("manual", "ABC")
91
+ .whitelist("ABC")
92
+ .approve("manual")
93
+ .blacklist("ABC")
94
+ decision_applier = described_class.new(decisions: decisions, packages: [])
95
+ dep = decision_applier.acknowledged.last
96
+ expect(dep).not_to be_approved
97
+ end
98
+
99
+ it "allows approval of packages if not all licenses are blacklisted" do
100
+ decisions = Decisions.new
101
+ .add_package("manual", nil)
102
+ .license("manual", "ABC")
103
+ .license("manual", "DEF")
104
+ .whitelist("ABC")
105
+ .blacklist("DEF")
106
+ decision_applier = described_class.new(decisions: decisions, packages: [])
107
+ dep = decision_applier.acknowledged.last
108
+ expect(dep).to be_approved
109
+ expect(dep).to be_whitelisted
110
+
111
+ decisions = Decisions.new
112
+ .add_package("manual", nil)
113
+ .license("manual", "ABC")
114
+ .license("manual", "DEF")
115
+ .approve("manual")
116
+ .blacklist("DEF")
117
+ decision_applier = described_class.new(decisions: decisions, packages: [])
118
+ dep = decision_applier.acknowledged.last
119
+ expect(dep).to be_approved
120
+ expect(dep).to be_approved_manually
121
+ end
122
+ end
123
+
124
+ describe '#unapproved' do
125
+ it 'returns all acknowledged packages that are not approved' do
126
+ packages = [
127
+ Package.new('foo', '0.0.1', spec_licenses: ['whitelist']),
128
+ Package.new('bar', '0.0.1', spec_licenses: ['blacklist'])
129
+ ]
130
+ decisions = Decisions.new
131
+ .add_package('baz', '0.0.1')
132
+ .whitelist('whitelist')
133
+ .blacklist('blacklist')
134
+ decision_applier = described_class.new(decisions: decisions, packages: packages)
135
+
136
+ expect(decision_applier.unapproved.map(&:name)).to include('baz')
137
+ expect(decision_applier.unapproved.map(&:name)).to include('bar')
138
+ expect(decision_applier.unapproved.map(&:name)).not_to include('foo')
139
+ end
140
+ end
141
+
142
+ describe '#blacklisted' do
143
+ it 'returns all packages that have blacklisted licenses' do
144
+ decision_applier = described_class.new(
145
+ decisions: Decisions.new.blacklist('GPLv3'),
146
+ packages: [Package.new('foo', '1.0', spec_licenses: ['GPLv3'])]
147
+ )
148
+
149
+ expect(decision_applier.blacklisted.map(&:name)).to eq(['foo'])
150
+ end
151
+
152
+ it 'does not report ignored packages' do
153
+ dev_dep = Package.new("dev_dep", nil, spec_licenses: ['GPLv3'], groups: ["development"])
154
+ decisions = Decisions.new
155
+ .ignore_group("development")
156
+ .add_package("manual", nil)
157
+ .ignore("manual")
158
+ .blacklist('GPLv3')
159
+ decision_applier = described_class.new(decisions: decisions, packages: [dev_dep])
160
+
161
+ expect(decision_applier.blacklisted).to be_empty
162
+ end
63
163
  end
64
164
  end
65
165
  end
@@ -158,6 +158,47 @@ module LicenseFinder
158
158
  end
159
159
  end
160
160
 
161
+ describe ".blacklist" do
162
+ it "will report the given license as blacklisted" do
163
+ decisions = subject.blacklist("MIT")
164
+ expect(decisions).to be_blacklisted(License.find_by_name("MIT"))
165
+ end
166
+
167
+ it "adapts names" do
168
+ decisions = subject.blacklist("Expat")
169
+ expect(decisions).to be_blacklisted(License.find_by_name("MIT"))
170
+ end
171
+
172
+ it "adds to list" do
173
+ decisions = subject.blacklist("MIT")
174
+ expect(decisions.blacklisted).to eq(Set.new([License.find_by_name("MIT")]))
175
+ end
176
+ end
177
+
178
+ describe ".unblacklist" do
179
+ it "will not report the given license as blacklisted" do
180
+ decisions = subject
181
+ .blacklist("MIT")
182
+ .unblacklist("MIT")
183
+ expect(decisions).not_to be_blacklisted(License.find_by_name("MIT"))
184
+ end
185
+
186
+ it "is cumulative" do
187
+ decisions = subject
188
+ .blacklist("MIT")
189
+ .unblacklist("MIT")
190
+ .blacklist("MIT")
191
+ expect(decisions).to be_blacklisted(License.find_by_name("MIT"))
192
+ end
193
+
194
+ it "adapts names" do
195
+ decisions = subject
196
+ .blacklist("MIT")
197
+ .unblacklist("Expat")
198
+ expect(decisions).not_to be_blacklisted(License.find_by_name("MIT"))
199
+ end
200
+ end
201
+
161
202
  describe ".ignore" do
162
203
  it "will report ignored dependencies" do
163
204
  decisions = subject.ignore("dep")
@@ -296,6 +337,22 @@ module LicenseFinder
296
337
  expect(decisions).not_to be_whitelisted(License.find_by_name("MIT"))
297
338
  end
298
339
 
340
+ it "can restore blacklists" do
341
+ decisions = roundtrip(
342
+ subject.blacklist("MIT")
343
+ )
344
+ expect(decisions).to be_blacklisted(License.find_by_name("MIT"))
345
+ end
346
+
347
+ it "can restore un-blacklists" do
348
+ decisions = roundtrip(
349
+ subject
350
+ .blacklist("MIT")
351
+ .unblacklist("MIT")
352
+ )
353
+ expect(decisions).not_to be_blacklisted(License.find_by_name("MIT"))
354
+ end
355
+
299
356
  it "can restore ignorals" do
300
357
  decisions = roundtrip(subject.ignore("dep"))
301
358
  expect(decisions).to be_ignored("dep")
@@ -341,6 +398,11 @@ module LicenseFinder
341
398
  )
342
399
  expect(decisions.project_name).to be_nil
343
400
  end
401
+
402
+ it "ignores empty or missing persisted decisions" do
403
+ described_class.restore('')
404
+ described_class.restore(nil)
405
+ end
344
406
  end
345
407
  end
346
408
  end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe Diff do
5
+ subject { Diff }
6
+
7
+ let(:diff) { subject.compare(file1_content, file2_content) }
8
+
9
+ def find_package(name)
10
+ diff.find { |d| d.name == name }
11
+ end
12
+
13
+ describe '#compare' do
14
+ context 'when a dependency is added' do
15
+ let(:file1_content) { "nokogiri,1.6.6.2,MIT" }
16
+ let(:file2_content) { "nokogiri,1.6.6.2,MIT\nrspec,3.2.0,MIT" }
17
+
18
+ it 'should create and set packages with added diff state' do
19
+ rspec = find_package('rspec')
20
+ expect(rspec.status).to eq :added
21
+ end
22
+ end
23
+
24
+ context 'when a dependency is removed' do
25
+ let(:file1_content) { "nokogiri,1.6.6.2,MIT\nrspec,3.2.0,MIT" }
26
+ let(:file2_content) { "nokogiri,1.6.6.2,MIT" }
27
+
28
+ it 'should create and set packages with removed diff state' do
29
+ rspec = find_package('rspec')
30
+ expect(rspec.status).to eq :removed
31
+ end
32
+ end
33
+
34
+ context 'when a dependency is unchanged' do
35
+ let(:file1_content) { "nokogiri,1.6.6.2,MIT" }
36
+ let(:file2_content) { "nokogiri,1.6.6.2,MIT" }
37
+
38
+ it 'should create and set packages with unchanged diff state' do
39
+ nokogiri = find_package('nokogiri')
40
+ expect(nokogiri.status).to eq :unchanged
41
+ end
42
+ end
43
+
44
+ context 'when there are all types of changes' do
45
+ let(:file1_content) { "rspec,3.2.0,MIT\nnokogiri,1.6.6.2,MIT\nfakefs,0.6.7,MIT" }
46
+ let(:file2_content) { "nokogiri,1.6.6.2,MIT\nminitest,5.7.0,MIT\nfakefs,0.6.7,BSD" }
47
+
48
+ it 'should create and set packages diff states' do
49
+ expect(find_package('minitest').status).to eq :added
50
+ expect(find_package('rspec').status).to eq :removed
51
+ expect(find_package('nokogiri').status).to eq :unchanged
52
+ end
53
+ end
54
+
55
+ context 'when the version changes' do
56
+ let(:file1_content) { "rspec,3.2.0,MIT" }
57
+ let(:file2_content) { "rspec,3.3.0,MIT" }
58
+
59
+ it 'should set the state to unchanged and record the version change' do
60
+ rspec = find_package('rspec')
61
+
62
+ expect(rspec.status).to eq(:unchanged)
63
+ expect(rspec.current_version).to eq('3.3.0')
64
+ expect(rspec.previous_version).to eq('3.2.0')
65
+ end
66
+ end
67
+
68
+ context 'when the license changes' do
69
+ let(:file1_content) { "rspec,3.2.0,MIT" }
70
+ let(:file2_content) { "rspec,3.3.0,GPLv2" }
71
+
72
+ it 'should set the state to unchanged and record the version change' do
73
+ rspec_old = diff.find {|p| p.previous_version == '3.2.0'}
74
+ rspec_new = diff.find {|p| p.current_version == '3.3.0'}
75
+
76
+ expect(rspec_old.status).to eq(:removed)
77
+ expect(rspec_old.current_version).to eq(nil)
78
+ expect(rspec_old.previous_version).to eq('3.2.0')
79
+
80
+ expect(rspec_new.status).to eq(:added)
81
+ expect(rspec_new.current_version).to eq('3.3.0')
82
+ expect(rspec_new.previous_version).to eq(nil)
83
+ end
84
+ end
85
+
86
+ context 'when the files are merged reports' do
87
+ let(:file1_content) { "rspec,3.2.0,MIT,\"/path/to/project1,/path/to/project2\"" }
88
+ let(:file2_content) { "rspec,3.2.0,MIT,\"/path/to/project1,/path/to/project2\"\nrails,4.2.0,MIT,/path/to/project1" }
89
+
90
+ it 'should show the diff of the reports' do
91
+ rspec = find_package('rspec')
92
+ expect(rspec.status).to eq(:unchanged)
93
+ expect(rspec.current_version).to eq('3.2.0')
94
+ expect(rspec.previous_version).to eq('3.2.0')
95
+ expect(rspec.subproject_paths).to match_array(['/path/to/project1', '/path/to/project2'])
96
+
97
+ rails = find_package('rails')
98
+ expect(rails.status).to eq(:added)
99
+ expect(rails.current_version).to eq('4.2.0')
100
+ expect(rails.previous_version).to eq(nil)
101
+ expect(rails.subproject_paths).to match_array(['/path/to/project1'])
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe LicenseAggregator do
5
+ describe '#dependencies' do
6
+ let(:hammer) { Package.new('hammer', '1.0.0') }
7
+ let(:helmet) { Package.new('helmet', '3.0.0') }
8
+ let(:license_finder_1) { double(:license_finder, acknowledged: [hammer]) }
9
+ let(:license_finder_2) { double(:license_finder, acknowledged: [helmet]) }
10
+
11
+ before do
12
+ allow(Core).to receive(:new).and_return(license_finder_1, license_finder_2)
13
+ end
14
+
15
+ it 'returns an array of MergedPackage objects' do
16
+ aggregator = LicenseAggregator.new({}, ['path/to/subproject-1', 'path/to/subproject-2'])
17
+ results = aggregator.dependencies
18
+ expect(results.first).to be_a(MergedPackage)
19
+ expect(results.map(&:name)).to match_array ['hammer', 'helmet']
20
+ end
21
+
22
+ context 'when there are duplicates' do
23
+ let(:license_finder_2) { double(:license_finder, acknowledged: [helmet, hammer])}
24
+
25
+ it 'aggregates duplicate packages by package name' do
26
+ aggregator = LicenseAggregator.new({}, ['path/to/subproject-1', 'path/to/subproject-2'])
27
+ results = aggregator.dependencies
28
+
29
+ expect(results.count).to eq(2)
30
+
31
+ expect(results[1].name).to eq('helmet')
32
+ expect(results[1].subproject_paths[0]).to end_with('path/to/subproject-2')
33
+
34
+ expect(results[0].name).to eq('hammer')
35
+ expect(results[0].subproject_paths[0]).to end_with('path/to/subproject-1')
36
+ expect(results[0].subproject_paths[1]).to end_with('path/to/subproject-2')
37
+ end
38
+ end
39
+
40
+ context 'when there are duplicate packages with different versions' do
41
+ let(:hammer_new) { Package.new('hammer', '2.0.0') }
42
+ let(:license_finder_2) { double(:license_finder, acknowledged: [helmet, hammer_new])}
43
+
44
+ it 'does not aggregate packages with different versions' do
45
+ aggregator = LicenseAggregator.new({}, ['path/to/subproject-1', 'path/to/subproject-2'])
46
+ results = aggregator.dependencies
47
+
48
+ expect(results.count).to eq(3)
49
+ expect(results.map(&:name)).to match_array ['hammer', 'helmet', 'hammer']
50
+ expect(find_package(results, 'hammer', '1.0.0').subproject_paths[0]).to end_with('path/to/subproject-1')
51
+ expect(find_package(results, 'hammer', '2.0.0').subproject_paths[0]).to end_with('path/to/subproject-2')
52
+ expect(find_package(results, 'helmet', '3.0.0').subproject_paths[0]).to end_with('path/to/subproject-2')
53
+ end
54
+ end
55
+
56
+ def find_package(packages, name, version)
57
+ packages.find { |dep| dep.name == name && dep.version == version }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe PackageDelta do
5
+ describe '#<=>' do
6
+ let(:foo) { Package.new('foo') }
7
+ let(:bar) { Package.new('bar') }
8
+
9
+ it 'sorts by status (added, removed, unchanged)' do
10
+ p1 = PackageDelta.added(foo)
11
+ p2 = PackageDelta.removed(bar)
12
+ p3 = PackageDelta.unchanged(foo, bar)
13
+
14
+ expect([p3, p2, p1].sort).to eq([p1, p2, p3])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,8 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe Bower do
5
- let(:bower) { Bower.new }
6
- it_behaves_like "a PackageManager"
5
+ subject { Bower.new(project_path: Pathname('/fake/path')) }
6
+
7
+ it_behaves_like 'a PackageManager'
7
8
 
8
9
  describe '.current_packages' do
9
10
  it 'lists all the current packages' do
@@ -25,11 +26,12 @@ module LicenseFinder
25
26
  }
26
27
  }
27
28
  JSON
28
- allow(bower).to receive("`").with(/bower/).and_return(json)
29
29
 
30
- expect(bower.current_packages.map { |p| [p.name, p.install_path] }).to eq [
31
- ["dependency-library", "/path/to/thing"],
32
- ["another-dependency", "/path/to/thing2"]
30
+ allow(Dir).to receive(:chdir).with(Pathname('/fake/path')) { |&block| block.call }
31
+ allow(subject).to receive(:capture).with('bower list --json -l action').and_return([json, true])
32
+
33
+ expect(subject.current_packages.map { |p| [p.name, p.install_path] }).to eq [
34
+ %w(dependency-library /path/to/thing), %w(another-dependency /path/to/thing2)
33
35
  ]
34
36
  end
35
37
  end