license_finder 1.2 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.rdoc +27 -0
- data/CONTRIBUTING.md +38 -0
- data/README.md +139 -159
- data/Rakefile +17 -13
- data/features/features/cli_spec.rb +43 -0
- data/features/features/configure/add_dependencies_spec.rb +37 -0
- data/features/features/configure/approve_dependencies_spec.rb +30 -0
- data/features/features/configure/assign_licenses_spec.rb +20 -0
- data/features/features/configure/ignore_dependencies_spec.rb +35 -0
- data/features/features/configure/ignore_groups_spec.rb +31 -0
- data/features/features/configure/name_project_spec.rb +32 -0
- data/features/features/configure/whitelist_licenses_spec.rb +40 -0
- data/features/features/package_managers/bower_spec.rb +14 -0
- data/features/features/package_managers/cocoapods_spec.rb +14 -0
- data/features/features/package_managers/gradle_spec.rb +14 -0
- data/features/features/package_managers/maven_spec.rb +14 -0
- data/features/features/package_managers/npm_spec.rb +14 -0
- data/features/features/package_managers/pip_spec.rb +14 -0
- data/features/features/report/csv_spec.rb +17 -0
- data/features/features/report/html_spec.rb +50 -0
- data/{spec → features}/fixtures/Podfile +0 -0
- data/{spec → features}/fixtures/build.gradle +0 -0
- data/{spec → features}/fixtures/pom.xml +0 -0
- data/features/support/testing_dsl.rb +295 -0
- data/lib/license_finder.rb +16 -50
- data/lib/license_finder/cli.rb +13 -253
- data/lib/license_finder/cli/approvals.rb +26 -0
- data/lib/license_finder/cli/base.rb +20 -0
- data/lib/license_finder/cli/dependencies.rb +39 -0
- data/lib/license_finder/cli/ignored_dependencies.rb +30 -0
- data/lib/license_finder/cli/ignored_groups.rb +30 -0
- data/lib/license_finder/cli/licenses.rb +24 -0
- data/lib/license_finder/cli/main.rb +82 -0
- data/lib/license_finder/cli/makes_decisions.rb +48 -0
- data/lib/license_finder/cli/patched_thor.rb +34 -0
- data/lib/license_finder/cli/project_name.rb +31 -0
- data/lib/license_finder/cli/whitelist.rb +32 -0
- data/lib/license_finder/configuration.rb +14 -145
- data/lib/license_finder/decision_applier.rb +46 -0
- data/lib/license_finder/decisions.rb +174 -0
- data/lib/license_finder/license.rb +13 -32
- data/lib/license_finder/license/definitions.rb +15 -13
- data/lib/license_finder/license/template.rb +1 -1
- data/lib/{data/licenses → license_finder/license/templates}/Apache2.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/BSD.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/GPLv2.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/ISC.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/LGPL.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/MIT.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/NewBSD.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/Python.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/Ruby.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/SimplifiedBSD.txt +0 -0
- data/lib/license_finder/package.rb +77 -7
- data/lib/license_finder/package_manager.rb +43 -0
- data/lib/license_finder/package_managers/bower.rb +1 -1
- data/lib/license_finder/package_managers/bower_package.rb +23 -44
- data/lib/license_finder/package_managers/bundler.rb +4 -7
- data/lib/license_finder/package_managers/bundler_package.rb +14 -31
- data/lib/license_finder/package_managers/cocoa_pods.rb +1 -1
- data/lib/license_finder/package_managers/cocoa_pods_package.rb +2 -10
- data/lib/license_finder/package_managers/gradle.rb +6 -2
- data/lib/license_finder/package_managers/gradle_package.rb +6 -30
- data/lib/license_finder/package_managers/manual_package.rb +25 -0
- data/lib/license_finder/package_managers/maven_package.rb +8 -37
- data/lib/license_finder/package_managers/npm.rb +16 -4
- data/lib/license_finder/package_managers/npm_package.rb +12 -43
- data/lib/license_finder/package_managers/pip_package.rb +17 -37
- data/lib/license_finder/platform.rb +0 -16
- data/lib/license_finder/possible_license_file.rb +9 -14
- data/lib/license_finder/possible_license_files.rb +1 -5
- data/lib/license_finder/report.rb +26 -0
- data/lib/license_finder/reports/csv_report.rb +58 -0
- data/lib/license_finder/reports/erb_report.rb +61 -0
- data/lib/license_finder/reports/html_report.rb +10 -1
- data/lib/license_finder/reports/markdown_report.rb +7 -1
- data/lib/license_finder/reports/templates/bootstrap.css +9 -0
- data/lib/license_finder/reports/templates/html_report.erb +105 -0
- data/lib/{templates → license_finder/reports/templates}/markdown_report.erb +7 -7
- data/lib/license_finder/reports/text_report.rb +5 -3
- data/lib/license_finder/version.rb +3 -0
- data/license_finder.gemspec +2 -6
- data/release/instructions.md +8 -0
- data/spec/feature_helper.rb +11 -0
- data/spec/fixtures/config/license_finder.yml +3 -0
- data/spec/fixtures/{nested_readme/vendor/README → license_directory/LICENSE/Apache.txt} +0 -0
- data/spec/lib/license_finder/cli/approvals_spec.rb +63 -0
- data/spec/lib/license_finder/cli/dependencies_spec.rb +59 -0
- data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +47 -0
- data/spec/lib/license_finder/cli/ignored_groups_spec.rb +40 -0
- data/spec/lib/license_finder/cli/licenses_spec.rb +60 -0
- data/spec/lib/license_finder/cli/main_spec.rb +110 -0
- data/spec/lib/license_finder/cli/project_name_spec.rb +40 -0
- data/spec/lib/license_finder/cli/whitelist_spec.rb +58 -0
- data/spec/lib/license_finder/configuration_spec.rb +46 -191
- data/spec/lib/license_finder/decision_applier_spec.rb +65 -0
- data/spec/lib/license_finder/decisions_spec.rb +347 -0
- data/spec/lib/license_finder/license/definitions_spec.rb +1 -7
- data/spec/lib/license_finder/license_spec.rb +2 -30
- data/spec/lib/license_finder/package_manager_spec.rb +22 -0
- data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -66
- data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +7 -71
- data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -11
- data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +28 -32
- data/spec/lib/license_finder/package_managers/gradle_spec.rb +18 -23
- data/spec/lib/license_finder/package_managers/maven_package_spec.rb +20 -43
- data/spec/lib/license_finder/package_managers/npm_package_spec.rb +22 -73
- data/spec/lib/license_finder/package_managers/npm_spec.rb +18 -21
- data/spec/lib/license_finder/package_managers/pip_package_spec.rb +24 -63
- data/spec/lib/license_finder/package_spec.rb +121 -0
- data/spec/lib/license_finder/possible_license_file_spec.rb +2 -3
- data/spec/lib/license_finder/possible_license_files_spec.rb +18 -22
- data/spec/lib/license_finder/reports/csv_report_spec.rb +26 -0
- data/spec/lib/license_finder/reports/html_report_spec.rb +39 -22
- data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -16
- data/spec/lib/license_finder/reports/text_report_spec.rb +21 -12
- data/spec/spec_helper.rb +1 -4
- data/spec/support/shared_examples_for_package.rb +0 -11
- data/spec/support/shared_examples_for_package_manager.rb +1 -0
- data/spec/support/stdout_helpers.rb +4 -11
- metadata +73 -158
- data/db/migrate/201303290935_create_dependencies.rb +0 -14
- data/db/migrate/201303291155_create_licenses.rb +0 -13
- data/db/migrate/201303291402_create_approvals.rb +0 -13
- data/db/migrate/201303291456_create_ancestries.rb +0 -9
- data/db/migrate/201303291519_create_bundler_groups.rb +0 -13
- data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +0 -11
- data/db/migrate/201303291753_allow_null_license_names.rb +0 -7
- data/db/migrate/201304011027_allow_null_dependency_version.rb +0 -7
- data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +0 -5
- data/db/migrate/201304181524_add_manual_to_dependencies.rb +0 -7
- data/db/migrate/201307250917_add_license_manual_to_dependencies.rb +0 -7
- data/db/migrate/201307251004_data_fix_manual_licenses.rb +0 -15
- data/db/migrate/201307251107_reassociate_license.rb +0 -23
- data/db/migrate/201307251340_remove_manual_from_license_aliases.rb +0 -7
- data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +0 -7
- data/db/migrate/201311192003_reassociate_manual_approval.rb +0 -13
- data/db/migrate/201311192010_drop_approvals.rb +0 -5
- data/db/migrate/201401302113_re_reassociate_license.rb +0 -23
- data/db/migrate/201403181732_rename_manual_fields.rb +0 -10
- data/db/migrate/201403190028_add_manual_approvals.rb +0 -22
- data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +0 -15
- data/db/migrate/201403191645_remove_license_aliases.rb +0 -23
- data/db/migrate/201410031451_rename_dependency_license_name.rb +0 -6
- data/features/cli.feature +0 -37
- data/features/cocoapods_dependencies.feature +0 -10
- data/features/configure_bundler_groups.feature +0 -23
- data/features/configure_ignore_dependencies.feature +0 -16
- data/features/configure_project_name.feature +0 -10
- data/features/configure_whitelist.feature +0 -27
- data/features/gradle_dependencies.feature +0 -9
- data/features/manually_added.feature +0 -19
- data/features/manually_approved.feature +0 -10
- data/features/manually_assigned_license.feature +0 -16
- data/features/maven_dependencies.feature +0 -9
- data/features/multiple_licenses.feature +0 -9
- data/features/node_dependencies.feature +0 -9
- data/features/python_dependencies.feature +0 -9
- data/features/report_csv.feature +0 -15
- data/features/report_html.feature +0 -24
- data/features/step_definitions/cli_steps.rb +0 -51
- data/features/step_definitions/cocoapod_steps.rb +0 -8
- data/features/step_definitions/configure_bundler_groups_steps.rb +0 -30
- data/features/step_definitions/configure_ignore_dependencies.rb +0 -35
- data/features/step_definitions/configure_project_name_steps.rb +0 -3
- data/features/step_definitions/configure_whitelist_steps.rb +0 -45
- data/features/step_definitions/gradle_steps.rb +0 -8
- data/features/step_definitions/manually_added_steps.rb +0 -28
- data/features/step_definitions/manually_approved_steps.rb +0 -24
- data/features/step_definitions/manually_assigned_license_steps.rb +0 -34
- data/features/step_definitions/maven_steps.rb +0 -8
- data/features/step_definitions/multiple_licenses_steps.rb +0 -14
- data/features/step_definitions/node_steps.rb +0 -8
- data/features/step_definitions/python_steps.rb +0 -8
- data/features/step_definitions/report_csv_steps.rb +0 -20
- data/features/step_definitions/report_html_steps.rb +0 -60
- data/features/step_definitions/shared_steps.rb +0 -307
- data/lib/data/license_finder.example.yml +0 -12
- data/lib/license_finder/dependency_manager.rb +0 -92
- data/lib/license_finder/package_saver.rb +0 -44
- data/lib/license_finder/reports/dependency_report.rb +0 -34
- data/lib/license_finder/reports/detailed_text_report.rb +0 -19
- data/lib/license_finder/reports/formatted_report.rb +0 -40
- data/lib/license_finder/reports/reporter.rb +0 -27
- data/lib/license_finder/tables.rb +0 -9
- data/lib/license_finder/tables/bundler_group.rb +0 -7
- data/lib/license_finder/tables/dependency.rb +0 -113
- data/lib/license_finder/tables/manual_approval.rb +0 -13
- data/lib/license_finder/yml_to_sql.rb +0 -117
- data/lib/templates/html_report.erb +0 -117
- data/lib/templates/text_report.erb +0 -3
- data/release/gem_version.rb +0 -3
- data/release/manual_instructions.md +0 -29
- data/release/publish.sh +0 -32
- data/spec/fixtures/APACHE-2-LICENSE +0 -202
- data/spec/fixtures/GPLv2 +0 -339
- data/spec/fixtures/ISC-LICENSE +0 -10
- data/spec/fixtures/MIT-LICENSE +0 -22
- data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +0 -22
- data/spec/fixtures/README-with-MIT-LICENSE +0 -222
- data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +0 -25
- data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +0 -339
- data/spec/fixtures/license_directory/LICENSE/LICENSE +0 -191
- data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -21
- data/spec/fixtures/license_directory/LICENSE/RUBY.txt +0 -60
- data/spec/fixtures/mit_licensed_gem/LICENSE +0 -22
- data/spec/fixtures/other_licensed_gem/LICENSE +0 -3
- data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
- data/spec/fixtures/readme/README +0 -0
- data/spec/fixtures/readme/Readme.markdown +0 -0
- data/spec/lib/license_finder/cli_spec.rb +0 -298
- data/spec/lib/license_finder/dependency_manager_spec.rb +0 -198
- data/spec/lib/license_finder/package_saver_spec.rb +0 -82
- data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +0 -33
- data/spec/lib/license_finder/reports/reporter_spec.rb +0 -33
- data/spec/lib/license_finder/tables/dependency_spec.rb +0 -196
- data/spec/lib/license_finder/yml_to_sql_spec.rb +0 -123
- data/spec/lib/license_finder_spec.rb +0 -16
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
describe Package do
|
5
|
+
subject do
|
6
|
+
described_class.new(
|
7
|
+
"a package",
|
8
|
+
"1.3.1",
|
9
|
+
summary: "a summary",
|
10
|
+
description: "a description",
|
11
|
+
homepage: "a homepage",
|
12
|
+
groups: %w[dev test],
|
13
|
+
children: %w[child-1 child2],
|
14
|
+
install_path: "some/package/path",
|
15
|
+
spec_licenses: %w[MIT GPL]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it_behaves_like "a Package"
|
20
|
+
|
21
|
+
its(:name) { should == "a package" }
|
22
|
+
its(:version) { should == "1.3.1" }
|
23
|
+
its(:summary) { should == "a summary" }
|
24
|
+
its(:description) { should == "a description" }
|
25
|
+
its(:homepage) { should == "a homepage" }
|
26
|
+
its(:groups) { should == %w[dev test] }
|
27
|
+
its(:children) { should == %w[child-1 child2] }
|
28
|
+
its(:install_path) { should eq "some/package/path" }
|
29
|
+
|
30
|
+
it "has defaults" do
|
31
|
+
subject = described_class.new(nil, nil)
|
32
|
+
expect(subject.name).to be_nil
|
33
|
+
expect(subject.version).to be_nil
|
34
|
+
expect(subject.summary).to eq ""
|
35
|
+
expect(subject.description).to eq ""
|
36
|
+
expect(subject.homepage).to eq ""
|
37
|
+
expect(subject.groups).to eq []
|
38
|
+
expect(subject.children).to eq []
|
39
|
+
expect(subject.install_path).to be_nil
|
40
|
+
expect(subject.license_names_from_spec).to eq []
|
41
|
+
expect(subject.licenses.map(&:name)).to eq ['unknown']
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#licenses' do
|
45
|
+
def stub_license_files(*license_names)
|
46
|
+
license_files = license_names.map do |license_name|
|
47
|
+
double(:file, license: License.find_by_name(license_name), path: "some/path")
|
48
|
+
end
|
49
|
+
allow(PossibleLicenseFiles).to receive(:find).
|
50
|
+
with("some/package/path").and_return(license_files)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "are not required" do
|
54
|
+
subject = described_class.new(nil, nil)
|
55
|
+
expect(subject.licenses.map(&:name)).to eq ['unknown']
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "decided by user" do
|
59
|
+
it "returns all decided licenses" do
|
60
|
+
subject = described_class.new(nil, nil)
|
61
|
+
subject.decide_on_license(License.find_by_name("MIT"))
|
62
|
+
subject.decide_on_license(License.find_by_name("GPL"))
|
63
|
+
expect(subject.licenses.map(&:name)).to match_array ["MIT", "GPL"]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "de-duplicates across license aliases" do
|
67
|
+
subject = described_class.new(nil, nil)
|
68
|
+
subject.decide_on_license(License.find_by_name("MIT"))
|
69
|
+
subject.decide_on_license(License.find_by_name("Expat"))
|
70
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT"]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "trumps licenses from the spec" do
|
74
|
+
subject = described_class.new(nil, nil, spec_licenses: ["GPL"])
|
75
|
+
subject.decide_on_license(License.find_by_name("MIT"))
|
76
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT"]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "trumps licenses from the install path" do
|
80
|
+
stub_license_files 'Detected License'
|
81
|
+
subject = described_class.new(nil, nil, install_path: "some/package/path")
|
82
|
+
subject.decide_on_license(License.find_by_name("MIT"))
|
83
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT"]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "from the spec" do
|
88
|
+
it "converts the names to licenses" do
|
89
|
+
subject = described_class.new(nil, nil, spec_licenses: ["MIT", "GPL"])
|
90
|
+
expect(subject.licenses.map(&:name)).to match_array ["MIT", "GPL"]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "de-duplicates across license aliases" do
|
94
|
+
subject = described_class.new(nil, nil, spec_licenses: ["MIT", "Expat"])
|
95
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT"]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "trumps licenses from the install path" do
|
99
|
+
stub_license_files 'Detected License'
|
100
|
+
subject = described_class.new(nil, nil, spec_licenses: ["MIT"], install_path: "some/package/path")
|
101
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT"]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "from the install path" do
|
106
|
+
it "uses the licenses reported by files in the install path" do
|
107
|
+
stub_license_files 'MIT', 'GPL'
|
108
|
+
subject = described_class.new(nil, nil, install_path: "some/package/path")
|
109
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT", "GPL"]
|
110
|
+
end
|
111
|
+
|
112
|
+
it "de-duplicates across license aliases" do
|
113
|
+
stub_license_files 'MIT', 'Expat'
|
114
|
+
subject = described_class.new(nil, nil, install_path: "some/package/path")
|
115
|
+
expect(subject.licenses.map(&:name)).to eq ["MIT"]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
@@ -3,20 +3,19 @@ require 'spec_helper'
|
|
3
3
|
module LicenseFinder
|
4
4
|
describe PossibleLicenseFile do
|
5
5
|
context "file parsing" do
|
6
|
-
subject { described_class.new('root
|
6
|
+
subject { described_class.new('root/nested/path') }
|
7
7
|
|
8
8
|
context "ignoring text" do
|
9
9
|
before do
|
10
10
|
allow(subject).to receive(:text).and_return('file text')
|
11
11
|
end
|
12
12
|
|
13
|
-
its(:file_path) { should == 'nested/path' }
|
14
13
|
its(:text) { should == 'file text' } # this is a terrible test, considering the stubbing
|
15
14
|
its(:path) { should == 'root/nested/path' }
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
|
-
subject { described_class.new('gem
|
18
|
+
subject { described_class.new('gem/license/path') }
|
20
19
|
|
21
20
|
context "with a known license" do
|
22
21
|
before do
|
@@ -3,51 +3,47 @@ require 'spec_helper'
|
|
3
3
|
module LicenseFinder
|
4
4
|
describe PossibleLicenseFiles do
|
5
5
|
def fixture_path(fixture)
|
6
|
-
Pathname.new(
|
6
|
+
Pathname.new(__FILE__).dirname.join('..', '..', 'fixtures', fixture)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#find" do
|
10
|
+
def files_in(fixture)
|
11
|
+
root_path = fixture_path(fixture)
|
12
|
+
subject = described_class.find(root_path.to_s)
|
13
|
+
|
14
|
+
subject.map do |f|
|
15
|
+
Pathname(f.path).relative_path_from(root_path).to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
10
19
|
it "is empty if passed a nil install path" do
|
11
20
|
subject = described_class.new nil
|
12
21
|
expect(subject.find).to eq([])
|
13
22
|
end
|
14
23
|
|
15
24
|
it "is empty if there aren't any license files" do
|
16
|
-
|
17
|
-
expect(subject.find).to eq([])
|
25
|
+
expect(files_in('not/a/dir')).to eq([])
|
18
26
|
end
|
19
27
|
|
20
|
-
it "includes files with names like LICENSE,
|
21
|
-
|
22
|
-
|
23
|
-
expect(subject.find.map(&:file_path)).to match_array(
|
28
|
+
it "includes files with names like LICENSE, README or COPYING" do
|
29
|
+
expect(files_in('license_names')).to match_array(
|
24
30
|
%w[COPYING.txt LICENSE Mit-License README.rdoc Licence.rdoc]
|
25
31
|
)
|
26
32
|
end
|
27
33
|
|
28
34
|
it "includes files deep in the hierarchy" do
|
29
|
-
|
30
|
-
|
31
|
-
expect(subject.find.map(&:file_path)).to match_array(%w[vendor/LICENSE])
|
35
|
+
expect(files_in('nested_gem')).to eq(['vendor/LICENSE'])
|
32
36
|
end
|
33
37
|
|
34
|
-
it "includes
|
35
|
-
|
36
|
-
found_license_files = subject.find
|
37
|
-
|
38
|
-
expect(found_license_files.map(&:file_path)).to match_array(%w[
|
39
|
-
LICENSE/BSD-2-Clause.txt
|
40
|
-
LICENSE/GPL-2.0.txt
|
41
|
-
LICENSE/MIT.txt
|
42
|
-
LICENSE/RUBY.txt
|
38
|
+
it "includes files nested inside LICENSE directory" do
|
39
|
+
expect(files_in('license_directory')).to match_array(%w[
|
43
40
|
COPYING
|
44
|
-
LICENSE/
|
41
|
+
LICENSE/Apache.txt
|
45
42
|
])
|
46
43
|
end
|
47
44
|
|
48
45
|
it "handles non UTF8 encodings" do
|
49
|
-
|
50
|
-
expect { subject.find }.not_to raise_error
|
46
|
+
expect { files_in('utf8_gem') }.not_to raise_error
|
51
47
|
end
|
52
48
|
end
|
53
49
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
describe CsvReport do
|
5
|
+
it "accepts a custom list of columns" do
|
6
|
+
dep = Package.new('gem_a', '1.0')
|
7
|
+
subject = described_class.new([dep], columns: %w[name version])
|
8
|
+
expect(subject.to_s).to eq("gem_a,1.0\n")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "understands many columns" do
|
12
|
+
dep = Package.new('gem_a', '1.0', description: "A description", summary: "A summary")
|
13
|
+
dep.decide_on_license(License.find_by_name("MIT"))
|
14
|
+
dep.decide_on_license(License.find_by_name("GPL"))
|
15
|
+
dep.whitelisted!
|
16
|
+
subject = described_class.new([dep], columns: %w[name version licenses approved summary description])
|
17
|
+
expect(subject.to_s).to eq("gem_a,1.0,\"MIT,GPL\",Approved,A summary,A description\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "ignores unknown columns" do
|
21
|
+
dep = Package.new('gem_a', '1.0')
|
22
|
+
subject = described_class.new([dep], columns: %w[unknown])
|
23
|
+
expect(subject.to_s).to eq("\n")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,17 +4,22 @@ require "capybara"
|
|
4
4
|
module LicenseFinder
|
5
5
|
describe HtmlReport do
|
6
6
|
describe "#to_s" do
|
7
|
-
let(:dependency_name) { "the-name" }
|
8
7
|
let(:dependency) do
|
9
|
-
dep =
|
10
|
-
dep.
|
8
|
+
dep = Package.new("the-dep")
|
9
|
+
dep.decide_on_license License.find_by_name("MIT")
|
11
10
|
dep
|
12
11
|
end
|
12
|
+
let(:dependencies) { [dependency] }
|
13
13
|
|
14
|
-
subject { Capybara.string(HtmlReport.new(
|
14
|
+
subject { Capybara.string(HtmlReport.new(dependencies, project_name: "project name").to_s) }
|
15
|
+
|
16
|
+
it "should show the project name" do
|
17
|
+
title = subject.find "h1"
|
18
|
+
expect(title).to have_text "project name"
|
19
|
+
end
|
15
20
|
|
16
21
|
context "when the dependency is manually approved" do
|
17
|
-
before { dependency.
|
22
|
+
before { dependency.approved_manually!(Decisions::TXN.new("the-approver", "the-approval-note", Time.now.utc)) }
|
18
23
|
|
19
24
|
it "should show approved dependencies without action items" do
|
20
25
|
is_expected.to have_selector ".approved"
|
@@ -31,7 +36,7 @@ module LicenseFinder
|
|
31
36
|
end
|
32
37
|
|
33
38
|
context "when the dependency is whitelisted" do
|
34
|
-
before {
|
39
|
+
before { dependency.whitelisted! }
|
35
40
|
|
36
41
|
it "should show approved dependencies without action items" do
|
37
42
|
is_expected.to have_selector ".approved"
|
@@ -45,38 +50,50 @@ module LicenseFinder
|
|
45
50
|
end
|
46
51
|
|
47
52
|
context "when the dependency is not approved" do
|
48
|
-
before {
|
49
|
-
dependency.licenses = [License.find_by_name('GPL')].to_set
|
50
|
-
dependency.manual_approval = nil
|
51
|
-
}
|
52
|
-
|
53
53
|
it "should show unapproved dependencies with action items" do
|
54
54
|
is_expected.to have_selector ".unapproved"
|
55
55
|
is_expected.to have_selector ".action-items li"
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
context "when the gem has a group" do
|
60
|
+
let(:dependency) do
|
61
|
+
Package.new(nil, nil, groups: ["foo group"])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should show the group" do
|
65
|
+
is_expected.to have_text "(foo group)"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when the gem does not have a group" do
|
70
|
+
it "should not show the group" do
|
71
|
+
is_expected.not_to have_text "()"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
59
75
|
context "when the gem has many relationships" do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
76
|
+
let(:dependencies) do
|
77
|
+
grandparent = Package.new("foo grandparent", nil, children: ["foo parent"])
|
78
|
+
parent = Package.new("foo parent", nil, children: ["foo child"])
|
79
|
+
child = Package.new("foo child")
|
80
|
+
pm = PackageManager.new
|
81
|
+
allow(pm).to receive(:current_packages) { [grandparent, parent, child] }
|
82
|
+
pm.current_packages_with_relations
|
64
83
|
end
|
65
84
|
|
66
85
|
it "should show the relationships" do
|
67
|
-
is_expected.to have_text "
|
68
|
-
is_expected.to have_text "
|
69
|
-
is_expected.to have_text "foo parent"
|
70
|
-
is_expected.to have_text "#{dependency_name} relies on:"
|
86
|
+
is_expected.to have_text "foo parent is required by:"
|
87
|
+
is_expected.to have_text "foo grandparent"
|
88
|
+
is_expected.to have_text "foo parent relies on:"
|
71
89
|
is_expected.to have_text "foo child"
|
72
90
|
end
|
73
91
|
end
|
74
92
|
|
75
93
|
context "when the gem has no relationships" do
|
76
94
|
it "should not show any relationships" do
|
77
|
-
is_expected.not_to have_text "
|
78
|
-
is_expected.not_to have_text "
|
79
|
-
is_expected.not_to have_text "#{dependency_name} relies on:"
|
95
|
+
is_expected.not_to have_text "is required by:"
|
96
|
+
is_expected.not_to have_text "relies on:"
|
80
97
|
end
|
81
98
|
end
|
82
99
|
end
|
@@ -4,27 +4,19 @@ module LicenseFinder
|
|
4
4
|
describe MarkdownReport do
|
5
5
|
describe '#to_s' do
|
6
6
|
let(:dep1) do
|
7
|
-
|
8
|
-
'name' => 'gem_a',
|
9
|
-
'version' => '1.0',
|
10
|
-
'licenses' => [License.find_by_name('other')].to_set
|
11
|
-
)
|
7
|
+
Package.new('gem_a', '1.0')
|
12
8
|
end
|
13
9
|
|
14
10
|
let(:dep2) do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
)
|
20
|
-
dependency.approve!
|
21
|
-
dependency
|
11
|
+
result = Package.new('gem_b', '2.3')
|
12
|
+
result.decide_on_license(License.find_by_name('BSD'))
|
13
|
+
result.approved_manually!(double(:approval).as_null_object)
|
14
|
+
result
|
22
15
|
end
|
23
16
|
|
24
|
-
subject { MarkdownReport.new([dep2, dep1]).to_s }
|
17
|
+
subject { MarkdownReport.new([dep2, dep1], project_name: "new_project_name").to_s }
|
25
18
|
|
26
19
|
it 'should have the correct header' do
|
27
|
-
LicenseFinder.config.project_name = "new_project_name"
|
28
20
|
is_expected.to match "# new_project_name"
|
29
21
|
end
|
30
22
|
|
@@ -34,12 +26,12 @@ module LicenseFinder
|
|
34
26
|
end
|
35
27
|
|
36
28
|
it "should list the unapproved dependency" do
|
37
|
-
is_expected.to match
|
29
|
+
is_expected.to match 'href="#gem_a"'
|
38
30
|
end
|
39
31
|
|
40
32
|
it "should display a summary" do
|
41
33
|
is_expected.to match "## Summary"
|
42
|
-
is_expected.to match /\s+\* 1
|
34
|
+
is_expected.to match /\s+\* 1 unknown/
|
43
35
|
is_expected.to match /\s+\* 1 BSD/
|
44
36
|
end
|
45
37
|
|
@@ -4,25 +4,34 @@ module LicenseFinder
|
|
4
4
|
describe TextReport do
|
5
5
|
describe '#to_s' do
|
6
6
|
let(:dep1) do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
'licenses' => [License.find_by_name('MIT')].to_set
|
11
|
-
)
|
7
|
+
result = Package.new('gem_a', '1.0')
|
8
|
+
result.decide_on_license(License.find_by_name('MIT'))
|
9
|
+
result
|
12
10
|
end
|
13
11
|
|
14
12
|
let(:dep2) do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
'licenses' => [License.find_by_name('MIT')].to_set
|
19
|
-
)
|
13
|
+
result = Package.new('gem_b', '1.0')
|
14
|
+
result.decide_on_license(License.find_by_name('MIT'))
|
15
|
+
result
|
20
16
|
end
|
21
17
|
|
22
|
-
|
18
|
+
let(:dep3) do
|
19
|
+
result = Package.new('gem_c', '2.0')
|
20
|
+
result.decide_on_license(License.find_by_name('MIT'))
|
21
|
+
result.decide_on_license(License.find_by_name('BSD'))
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { described_class.new([dep3, dep2, dep1]).to_s }
|
23
26
|
|
24
27
|
it 'should generate a text report with the name, version and license of each dependency, sorted by name' do
|
25
|
-
is_expected.to eq("gem_a, 1.0, MIT\ngem_b, 1.0, MIT")
|
28
|
+
is_expected.to eq("gem_a, 1.0, MIT\ngem_b, 1.0, MIT\ngem_c, 2.0, \"MIT, BSD\"\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'prints a warning message for packages that have not been installed' do
|
32
|
+
dep = Package.new('gem_d', '2.0', missing: true)
|
33
|
+
report = described_class.new([dep]).to_s
|
34
|
+
expect(report).to eq("gem_d, 2.0, \"This package is not installed. Please install to determine licenses.\"\n")
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,7 @@ require 'license_finder'
|
|
6
6
|
require 'rspec'
|
7
7
|
require 'webmock/rspec'
|
8
8
|
require 'rspec/its'
|
9
|
+
require 'fileutils'
|
9
10
|
|
10
11
|
ENV['test_run'] = true.to_s
|
11
12
|
|
@@ -18,10 +19,6 @@ RSpec.configure do |config|
|
|
18
19
|
end
|
19
20
|
|
20
21
|
RSpec.configure do |config|
|
21
|
-
config.around do |example|
|
22
|
-
LicenseFinder::DB.transaction(rollback: :always) { example.run }
|
23
|
-
end
|
24
|
-
|
25
22
|
config.after(:suite) do
|
26
23
|
["./doc", "./elsewhere", "./test path", "./config"].each do |tmp_dir|
|
27
24
|
FileUtils.rm_rf(tmp_dir)
|