license_finder 1.0.0.0-java → 1.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.force-build +0 -0
- data/.travis.yml +8 -7
- data/CHANGELOG.rdoc +29 -1
- data/Rakefile +2 -2
- data/db/migrate/201311192003_reassociate_manual_approval.rb +2 -3
- data/db/migrate/201403181732_rename_manual_fields.rb +10 -0
- data/db/migrate/201403190028_add_manual_approvals.rb +22 -0
- data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +15 -0
- data/db/migrate/201403191645_remove_license_aliases.rb +23 -0
- data/features/cli.feature +21 -20
- data/features/cocoapods_dependencies.feature +10 -0
- data/features/configure_bundler_groups.feature +23 -0
- data/features/configure_ignore_dependencies.feature +16 -0
- data/features/{project_name.feature → configure_project_name.feature} +1 -1
- data/features/{whitelist.feature → configure_whitelist.feature} +6 -6
- data/features/manually_added.feature +19 -0
- data/features/{approve_dependencies.feature → manually_approved.feature} +2 -2
- data/features/manually_assigned_license.feature +16 -0
- data/features/{text_report.feature → report_csv.feature} +2 -2
- data/features/{html_report.feature → report_html.feature} +2 -2
- data/features/step_definitions/cli_steps.rb +22 -32
- data/features/step_definitions/cocoapod_steps.rb +8 -0
- data/features/step_definitions/configure_bundler_groups_steps.rb +30 -0
- data/features/step_definitions/configure_ignore_dependencies.rb +35 -0
- data/features/step_definitions/{project_name_steps.rb → configure_project_name_steps.rb} +0 -0
- data/features/step_definitions/configure_whitelist_steps.rb +45 -0
- data/features/step_definitions/gradle_steps.rb +2 -2
- data/features/step_definitions/manually_added_steps.rb +28 -0
- data/features/step_definitions/manually_approved_steps.rb +24 -0
- data/features/step_definitions/manually_assigned_license_steps.rb +34 -0
- data/features/step_definitions/maven_steps.rb +2 -2
- data/features/step_definitions/node_steps.rb +2 -2
- data/features/step_definitions/python_steps.rb +1 -1
- data/features/step_definitions/report_csv_steps.rb +20 -0
- data/features/step_definitions/report_html_steps.rb +60 -0
- data/features/step_definitions/shared_steps.rb +125 -104
- data/{files/license_finder.yml → lib/data/license_finder.example.yml} +3 -0
- data/lib/license_finder.rb +3 -2
- data/lib/license_finder/cli.rb +94 -49
- data/lib/license_finder/configuration.rb +21 -14
- data/lib/license_finder/dependency_manager.rb +27 -19
- data/lib/license_finder/license.rb +33 -19
- data/lib/license_finder/license/definitions.rb +153 -104
- data/lib/license_finder/license/matcher.rb +6 -1
- data/lib/license_finder/license/none_matcher.rb +9 -0
- data/lib/license_finder/license/text.rb +1 -0
- data/lib/license_finder/package.rb +30 -6
- data/lib/license_finder/package_managers/bower.rb +2 -2
- data/lib/license_finder/package_managers/bower_package.rb +2 -2
- data/lib/license_finder/package_managers/bundler.rb +9 -17
- data/lib/license_finder/package_managers/bundler_package.rb +1 -1
- data/lib/license_finder/package_managers/cocoa_pods.rb +35 -0
- data/lib/license_finder/package_managers/cocoa_pods_package.rb +19 -0
- data/lib/license_finder/package_managers/gradle.rb +9 -5
- data/lib/license_finder/package_managers/gradle_package.rb +4 -4
- data/lib/license_finder/package_managers/maven.rb +7 -3
- data/lib/license_finder/package_managers/maven_package.rb +5 -5
- data/lib/license_finder/package_managers/npm.rb +2 -2
- data/lib/license_finder/package_managers/npm_package.rb +2 -2
- data/lib/license_finder/package_managers/pip.rb +2 -2
- data/lib/license_finder/package_managers/pip_package.rb +7 -11
- data/lib/license_finder/package_saver.rb +12 -10
- data/lib/license_finder/possible_license_file.rb +1 -1
- data/lib/license_finder/possible_license_files.rb +11 -15
- data/lib/license_finder/reports/formatted_report.rb +25 -6
- data/lib/license_finder/reports/html_report.rb +2 -1
- data/lib/license_finder/reports/reporter.rb +3 -3
- data/lib/license_finder/tables.rb +6 -4
- data/lib/license_finder/tables/dependency.rb +36 -16
- data/lib/license_finder/tables/manual_approval.rb +13 -0
- data/lib/license_finder/yml_to_sql.rb +12 -9
- data/lib/templates/html_report.erb +68 -74
- data/lib/templates/markdown_report.erb +20 -21
- data/license_finder.gemspec +7 -7
- data/readme.md +76 -79
- data/spec/fixtures/Podfile +3 -0
- data/spec/lib/license_finder/cli_spec.rb +71 -23
- data/spec/lib/license_finder/configuration_spec.rb +61 -21
- data/spec/lib/license_finder/dependency_manager_spec.rb +52 -33
- data/spec/lib/license_finder/license/definitions_spec.rb +30 -14
- data/spec/lib/license_finder/license_spec.rb +55 -12
- data/spec/lib/license_finder/package_managers/bower_package_spec.rb +38 -19
- data/spec/lib/license_finder/package_managers/bower_spec.rb +10 -16
- data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +39 -15
- data/spec/lib/license_finder/package_managers/bundler_spec.rb +10 -22
- data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +44 -0
- data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +79 -0
- data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +4 -5
- data/spec/lib/license_finder/package_managers/gradle_spec.rb +26 -20
- data/spec/lib/license_finder/package_managers/maven_package_spec.rb +4 -5
- data/spec/lib/license_finder/package_managers/maven_spec.rb +16 -19
- data/spec/lib/license_finder/package_managers/npm_package_spec.rb +39 -19
- data/spec/lib/license_finder/package_managers/npm_spec.rb +10 -16
- data/spec/lib/license_finder/package_managers/pip_package_spec.rb +8 -8
- data/spec/lib/license_finder/package_managers/pip_spec.rb +10 -16
- data/spec/lib/license_finder/package_saver_spec.rb +27 -3
- data/spec/lib/license_finder/possible_license_file_spec.rb +25 -23
- data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +6 -8
- data/spec/lib/license_finder/reports/html_report_spec.rb +45 -44
- data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -9
- data/spec/lib/license_finder/reports/reporter_spec.rb +1 -1
- data/spec/lib/license_finder/reports/text_report_spec.rb +6 -8
- data/spec/lib/license_finder/tables/dependency_spec.rb +57 -41
- data/spec/lib/license_finder/yml_to_sql_spec.rb +94 -92
- data/spec/spec_helper.rb +1 -0
- data/spec/support/stdout_helpers.rb +25 -0
- metadata +86 -69
- data/MIT.LICENSE +0 -20
- data/features/ignore_bundle_groups.feature +0 -23
- data/features/manually_managed_dependencies.feature +0 -19
- data/features/set_license.feature +0 -10
- data/features/step_definitions/approve_dependencies_steps.rb +0 -25
- data/features/step_definitions/html_report_steps.rb +0 -62
- data/features/step_definitions/ignore_bundle_groups_steps.rb +0 -29
- data/features/step_definitions/manually_managed_steps.rb +0 -33
- data/features/step_definitions/set_license_steps.rb +0 -20
- data/features/step_definitions/text_report_steps.rb +0 -19
- data/features/step_definitions/whitelist_steps.rb +0 -45
- data/files/dependency_breakdown.png +0 -0
- data/files/report_breakdown.png +0 -0
- data/lib/license_finder/license_url.rb +0 -9
- data/lib/license_finder/tables/license_alias.rb +0 -22
- data/spec/lib/license_finder/license_url_spec.rb +0 -16
- data/spec/lib/license_finder/tables/license_alias_spec.rb +0 -37
- data/spec/support/silence_stdout.rb +0 -13
@@ -5,7 +5,7 @@ module LicenseFinder
|
|
5
5
|
describe Dependencies do
|
6
6
|
describe "add" do
|
7
7
|
it "adds a dependency" do
|
8
|
-
DependencyManager.should_receive(:
|
8
|
+
DependencyManager.should_receive(:manually_add).with("MIT", "js_dep", "1.2.3")
|
9
9
|
|
10
10
|
silence_stdout do
|
11
11
|
subject.add("MIT", "js_dep", "1.2.3")
|
@@ -13,7 +13,7 @@ module LicenseFinder
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "does not require a version" do
|
16
|
-
DependencyManager.should_receive(:
|
16
|
+
DependencyManager.should_receive(:manually_add).with("MIT", "js_dep", nil)
|
17
17
|
|
18
18
|
silence_stdout do
|
19
19
|
subject.add("MIT", "js_dep")
|
@@ -21,18 +21,18 @@ module LicenseFinder
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "has an --approve option to approve the added dependency" do
|
24
|
-
DependencyManager.should_receive(:
|
25
|
-
DependencyManager.should_receive(:approve!).with("js_dep")
|
24
|
+
DependencyManager.should_receive(:manually_add).with("MIT", "js_dep", "1.2.3")
|
25
|
+
DependencyManager.should_receive(:approve!).with("js_dep", "Julian", "We really need this")
|
26
26
|
|
27
27
|
silence_stdout do
|
28
|
-
|
28
|
+
Main.start(["dependencies", "add", "--approve", "--approver", "Julian", "--message", "We really need this", "MIT", "js_dep", "1.2.3"])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "remove" do
|
34
34
|
it "removes a dependency" do
|
35
|
-
DependencyManager.should_receive(:
|
35
|
+
DependencyManager.should_receive(:manually_remove).with("js_dep")
|
36
36
|
silence_stdout do
|
37
37
|
subject.remove("js_dep")
|
38
38
|
end
|
@@ -57,7 +57,7 @@ module LicenseFinder
|
|
57
57
|
it "adds the specified license to the whitelist" do
|
58
58
|
config.whitelist.should_receive(:push).with("test")
|
59
59
|
config.should_receive(:save)
|
60
|
-
|
60
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
61
61
|
|
62
62
|
silence_stdout do
|
63
63
|
subject.add("test")
|
@@ -68,7 +68,7 @@ module LicenseFinder
|
|
68
68
|
config.whitelist.should_receive(:push).with("test")
|
69
69
|
config.whitelist.should_receive(:push).with("rest")
|
70
70
|
config.should_receive(:save)
|
71
|
-
|
71
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
72
72
|
|
73
73
|
silence_stdout do
|
74
74
|
subject.add("test", "rest")
|
@@ -80,7 +80,7 @@ module LicenseFinder
|
|
80
80
|
it "removes the specified license from the whitelist" do
|
81
81
|
config.should_receive(:save)
|
82
82
|
config.whitelist.should_receive(:delete).with("test")
|
83
|
-
|
83
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
84
84
|
|
85
85
|
silence_stdout do
|
86
86
|
|
@@ -92,7 +92,7 @@ module LicenseFinder
|
|
92
92
|
config.should_receive(:save)
|
93
93
|
config.whitelist.should_receive(:delete).with("test")
|
94
94
|
config.whitelist.should_receive(:delete).with("rest")
|
95
|
-
|
95
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
96
96
|
|
97
97
|
silence_stdout do
|
98
98
|
subject.remove("test", "rest")
|
@@ -108,7 +108,7 @@ module LicenseFinder
|
|
108
108
|
it "sets the project name" do
|
109
109
|
config.should_receive(:save)
|
110
110
|
config.project_name.should_not eq("new_project_name")
|
111
|
-
|
111
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
112
112
|
|
113
113
|
silence_stdout do
|
114
114
|
subject.set("new_project_name")
|
@@ -124,11 +124,9 @@ module LicenseFinder
|
|
124
124
|
|
125
125
|
describe "list" do
|
126
126
|
it "shows the ignored groups in the standard output" do
|
127
|
-
config.should_receive(:ignore_groups).and_return([])
|
127
|
+
config.should_receive(:ignore_groups).and_return(['development'])
|
128
128
|
|
129
|
-
|
130
|
-
subject.list
|
131
|
-
end
|
129
|
+
expect(capture_stdout { subject.list }).to match /development/
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
@@ -136,7 +134,7 @@ module LicenseFinder
|
|
136
134
|
it "adds the specified group to the ignored groups list" do
|
137
135
|
config.ignore_groups.should_receive(:push).with("test")
|
138
136
|
config.should_receive(:save)
|
139
|
-
|
137
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
140
138
|
|
141
139
|
silence_stdout do
|
142
140
|
subject.add("test")
|
@@ -148,7 +146,51 @@ module LicenseFinder
|
|
148
146
|
it "removes the specified group from the ignored groups list" do
|
149
147
|
config.ignore_groups.should_receive(:delete).with("test")
|
150
148
|
config.should_receive(:save)
|
151
|
-
|
149
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
150
|
+
|
151
|
+
silence_stdout do
|
152
|
+
subject.remove("test")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe IgnoredDependencies do
|
159
|
+
let(:config) { LicenseFinder.config }
|
160
|
+
|
161
|
+
describe "list" do
|
162
|
+
context "when there is at least one ignored dependency" do
|
163
|
+
it "shows the ignored dependencies" do
|
164
|
+
expect(config).to receive(:ignore_dependencies).and_return(['bundler'])
|
165
|
+
expect(capture_stdout { subject.list }).to match /bundler/
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "when there are no ignored dependencies" do
|
170
|
+
it "prints '(none)'" do
|
171
|
+
expect(config).to receive(:ignore_dependencies).and_return([])
|
172
|
+
expect(capture_stdout { subject.list }).to match /\(none\)/
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "add" do
|
178
|
+
it "adds the specified group to the ignored groups list" do
|
179
|
+
config.ignore_dependencies.should_receive(:push).with("test")
|
180
|
+
config.should_receive(:save)
|
181
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
182
|
+
|
183
|
+
silence_stdout do
|
184
|
+
subject.add("test")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "remove" do
|
190
|
+
it "removes the specified group from the ignored groups list" do
|
191
|
+
config.ignore_dependencies.should_receive(:delete).with("test")
|
192
|
+
config.should_receive(:save)
|
193
|
+
expect(DependencyManager).to receive(:sync_with_package_managers)
|
152
194
|
|
153
195
|
silence_stdout do
|
154
196
|
subject.remove("test")
|
@@ -191,7 +233,7 @@ module LicenseFinder
|
|
191
233
|
|
192
234
|
describe "#approve" do
|
193
235
|
it "approves the requested gem" do
|
194
|
-
DependencyManager.should_receive(:approve!).with("foo")
|
236
|
+
DependencyManager.should_receive(:approve!).with("foo", nil, nil)
|
195
237
|
|
196
238
|
silence_stdout do
|
197
239
|
subject.approve 'foo'
|
@@ -199,8 +241,8 @@ module LicenseFinder
|
|
199
241
|
end
|
200
242
|
|
201
243
|
it "approves multiple gem" do
|
202
|
-
DependencyManager.should_receive(:approve!).with("foo")
|
203
|
-
DependencyManager.should_receive(:approve!).with("bar")
|
244
|
+
DependencyManager.should_receive(:approve!).with("foo", nil, nil)
|
245
|
+
DependencyManager.should_receive(:approve!).with("bar", nil, nil)
|
204
246
|
|
205
247
|
silence_stdout do
|
206
248
|
subject.approve 'foo', 'bar'
|
@@ -211,9 +253,15 @@ module LicenseFinder
|
|
211
253
|
DependencyManager.should_not_receive(:approve!)
|
212
254
|
|
213
255
|
silence_stdout do
|
214
|
-
subject.
|
215
|
-
|
216
|
-
|
256
|
+
expect { subject.approve }.to raise_error(ArgumentError)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it "sets approver and approval message" do
|
261
|
+
DependencyManager.should_receive(:approve!).with("foo", "Julian", "We really need this")
|
262
|
+
|
263
|
+
silence_stdout do
|
264
|
+
Main.start(["approve", "--approver", "Julian", "--message", "We really need this", "foo"])
|
217
265
|
end
|
218
266
|
end
|
219
267
|
end
|
@@ -11,40 +11,61 @@ module LicenseFinder
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe "#last_modified" do
|
15
|
+
let(:time) { double :time }
|
16
|
+
before do
|
17
|
+
allow(Configuration::Persistence).to receive(:last_modified) { time }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the last modified date of the config file' do
|
21
|
+
expect(LicenseFinder::Configuration.new({}).last_modified).to eq time
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
14
25
|
describe '.new' do
|
15
26
|
it "should default missing attributes" do
|
16
27
|
subject = described_class.new({})
|
17
28
|
subject.whitelist.should == []
|
18
29
|
subject.ignore_groups.should == []
|
30
|
+
subject.ignore_dependencies.should == []
|
19
31
|
subject.artifacts.dir.should == Pathname('./doc/')
|
32
|
+
subject.gradle_command.should == 'gradle'
|
20
33
|
end
|
21
34
|
|
22
35
|
it "should default missing attributes even if they are saved as nils in the YAML file" do
|
23
36
|
attributes = {
|
24
37
|
"whitelist" => nil,
|
25
38
|
"ignore_groups" => nil,
|
39
|
+
"ignore_dependencies" => nil,
|
26
40
|
"dependencies_file_dir" => nil,
|
27
|
-
"project_name" => nil
|
41
|
+
"project_name" => nil,
|
42
|
+
"gradle_command" => nil
|
28
43
|
}
|
29
44
|
subject = described_class.new(attributes)
|
30
45
|
subject.whitelist.should == []
|
31
46
|
subject.ignore_groups.should == []
|
47
|
+
subject.ignore_dependencies.should == []
|
32
48
|
subject.artifacts.dir.should == Pathname('./doc/')
|
33
49
|
subject.project_name.should_not be_nil
|
50
|
+
subject.gradle_command.should == 'gradle'
|
34
51
|
end
|
35
52
|
|
36
53
|
it "should set the all of the attributes on the instance" do
|
37
54
|
attributes = {
|
38
55
|
"whitelist" => %w{a whitelist},
|
39
56
|
"ignore_groups" => %w{test development},
|
57
|
+
"ignore_dependencies" => %w{bundler},
|
40
58
|
"dependencies_file_dir" => "some/path",
|
41
|
-
"project_name" => "my_app"
|
59
|
+
"project_name" => "my_app",
|
60
|
+
"gradle_command" => "./gradlew"
|
42
61
|
}
|
43
62
|
subject = described_class.new(attributes)
|
44
63
|
subject.whitelist.should == %w{a whitelist}
|
45
64
|
subject.ignore_groups.should == %w{test development}
|
65
|
+
subject.ignore_dependencies.should == %w{bundler}
|
46
66
|
subject.artifacts.dir.should == Pathname("some/path")
|
47
67
|
subject.project_name.should == "my_app"
|
68
|
+
subject.gradle_command.should == "./gradlew"
|
48
69
|
end
|
49
70
|
end
|
50
71
|
|
@@ -72,31 +93,15 @@ module LicenseFinder
|
|
72
93
|
end
|
73
94
|
end
|
74
95
|
|
75
|
-
describe "whitelisted?" do
|
76
|
-
context "short name whitelisted" do
|
77
|
-
subject { described_class.new('whitelist' => ["Apache2"]) }
|
78
|
-
|
79
|
-
it "should accept any of the licenses names" do
|
80
|
-
subject.should be_whitelisted "Apache2"
|
81
|
-
subject.should be_whitelisted "Apache 2.0"
|
82
|
-
subject.should be_whitelisted "Apache-2.0"
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should be case-insensitive" do
|
86
|
-
subject.should be_whitelisted "apache2"
|
87
|
-
subject.should be_whitelisted "apache 2.0"
|
88
|
-
subject.should be_whitelisted "apache-2.0"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
96
|
describe "#save" do
|
94
97
|
def attributes # can't be a let... the caching causes polution
|
95
98
|
{
|
96
99
|
'whitelist' => ['my_gem'],
|
97
100
|
'ignore_groups' => ['other_group', 'test'],
|
101
|
+
'ignore_dependencies' => ['bundler'],
|
98
102
|
'project_name' => "New Project Name",
|
99
|
-
'dependencies_file_dir' => "./deps"
|
103
|
+
'dependencies_file_dir' => "./deps",
|
104
|
+
'gradle_command' => './gradle'
|
100
105
|
}
|
101
106
|
end
|
102
107
|
|
@@ -109,6 +114,7 @@ module LicenseFinder
|
|
109
114
|
config = described_class.new(attributes)
|
110
115
|
config.whitelist << 'my_gem'
|
111
116
|
config.ignore_groups << 'test'
|
117
|
+
config.ignore_dependencies << 'bundler'
|
112
118
|
|
113
119
|
Configuration::Persistence.should_receive(:set).with(attributes)
|
114
120
|
config.save
|
@@ -116,6 +122,28 @@ module LicenseFinder
|
|
116
122
|
end
|
117
123
|
end
|
118
124
|
|
125
|
+
describe Configuration::Artifacts do
|
126
|
+
describe "#last_refreshed" do
|
127
|
+
let(:database_modified_time) { 1 }
|
128
|
+
let(:text_modified_time) { 2 }
|
129
|
+
let(:detailed_text_modified_time) { 3 }
|
130
|
+
let(:html_modified_time) { 4 }
|
131
|
+
let(:markdown_modified_time) { 5 }
|
132
|
+
|
133
|
+
before do
|
134
|
+
allow(File).to receive(:mtime).with(Pathname('./doc/dependencies.db')) { database_modified_time }
|
135
|
+
allow(File).to receive(:mtime).with(Pathname('./doc/dependencies.csv')) { text_modified_time }
|
136
|
+
allow(File).to receive(:mtime).with(Pathname('./doc/dependencies_detailed.csv')) { detailed_text_modified_time }
|
137
|
+
allow(File).to receive(:mtime).with(Pathname('./doc/dependencies.html')) { html_modified_time }
|
138
|
+
allow(File).to receive(:mtime).with(Pathname('./doc/dependencies.md')) { markdown_modified_time }
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns the earliest modified date of the config file' do
|
142
|
+
expect(described_class.new(Pathname('./doc')).last_refreshed).to eq database_modified_time
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
119
147
|
describe Configuration::Persistence do
|
120
148
|
describe ".get" do
|
121
149
|
it "should use saved configuration" do
|
@@ -168,5 +196,17 @@ module LicenseFinder
|
|
168
196
|
described_class.init
|
169
197
|
end
|
170
198
|
end
|
199
|
+
|
200
|
+
describe ".last_modified" do
|
201
|
+
let(:time) { double :time }
|
202
|
+
let(:config_path) { Pathname.new('.').join('config').join('license_finder.yml') }
|
203
|
+
before do
|
204
|
+
allow(File).to receive(:mtime).with(config_path) { time }
|
205
|
+
end
|
206
|
+
|
207
|
+
it "returns the last time the yml file was modified" do
|
208
|
+
expect(described_class.last_modified).to eq time
|
209
|
+
end
|
210
|
+
end
|
171
211
|
end
|
172
212
|
end
|
@@ -13,10 +13,10 @@ module LicenseFinder
|
|
13
13
|
let(:gem1) { double(:package) }
|
14
14
|
let(:gem2) { double(:package) }
|
15
15
|
|
16
|
-
it "destroys every dependency except for the ones Bundler reports as 'current' or are marked as '
|
16
|
+
it "destroys every dependency except for the ones Bundler reports as 'current' or are marked as 'added_manually'" do
|
17
17
|
cur1 = Dependency.create(name: "current dependency 1")
|
18
18
|
cur2 = Dependency.create(name: "current dependency 2")
|
19
|
-
man1 = Dependency.create(name: "manual dependency",
|
19
|
+
man1 = Dependency.create(name: "manual dependency", added_manually: true)
|
20
20
|
Dependency.create(name: "old dependency 1")
|
21
21
|
Dependency.create(name: "old dependency 2")
|
22
22
|
|
@@ -29,20 +29,20 @@ module LicenseFinder
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe ".
|
32
|
+
describe ".manually_add" do
|
33
33
|
it "should add a Dependency" do
|
34
34
|
expect do
|
35
|
-
described_class.
|
35
|
+
described_class.manually_add("MIT", "js_dep", "0.0.0")
|
36
36
|
end.to change(Dependency, :count).by(1)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should mark the dependency as manual" do
|
40
|
-
described_class.
|
41
|
-
.should
|
40
|
+
described_class.manually_add("MIT", "js_dep", "0.0.0")
|
41
|
+
.should be_added_manually
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should set the appropriate values" do
|
45
|
-
dep = described_class.
|
45
|
+
dep = described_class.manually_add("GPL", "js_dep", "0.0.0")
|
46
46
|
dep.name.should == "js_dep"
|
47
47
|
dep.version.should == "0.0.0"
|
48
48
|
dep.license.name.should == "GPL"
|
@@ -51,23 +51,16 @@ module LicenseFinder
|
|
51
51
|
|
52
52
|
it "should complain if the dependency already exists" do
|
53
53
|
Dependency.create(name: "current dependency 1")
|
54
|
-
expect { described_class.
|
55
|
-
.to raise_error(
|
56
|
-
end
|
57
|
-
|
58
|
-
it "re-uses an existing, unassociated, license alias" do
|
59
|
-
existing_license = LicenseAlias.named("existing license")
|
60
|
-
|
61
|
-
dep = described_class.create_manually_managed("existing license", "js_dep", "0.0.0")
|
62
|
-
dep.license.should == existing_license
|
54
|
+
expect { described_class.manually_add("GPL", "current dependency 1", "0.0.0") }
|
55
|
+
.to raise_error(Error)
|
63
56
|
end
|
64
57
|
end
|
65
58
|
|
66
|
-
describe ".
|
59
|
+
describe ".manually_remove" do
|
67
60
|
it "should remove a manually managed Dependency" do
|
68
|
-
described_class.
|
61
|
+
described_class.manually_add("GPL", "a manually managed dep", nil)
|
69
62
|
expect do
|
70
|
-
described_class.
|
63
|
+
described_class.manually_remove("a manually managed dep")
|
71
64
|
end.to change(Dependency, :count).by(-1)
|
72
65
|
end
|
73
66
|
|
@@ -75,8 +68,8 @@ module LicenseFinder
|
|
75
68
|
Dependency.create(name: "a bundler dep")
|
76
69
|
expect do
|
77
70
|
expect do
|
78
|
-
described_class.
|
79
|
-
end.to raise_error(
|
71
|
+
described_class.manually_remove("a bundler dep")
|
72
|
+
end.to raise_error(Error)
|
80
73
|
end.to_not change(Dependency, :count)
|
81
74
|
end
|
82
75
|
end
|
@@ -84,14 +77,24 @@ module LicenseFinder
|
|
84
77
|
describe ".approve!" do
|
85
78
|
it "approves the dependency" do
|
86
79
|
dep = Dependency.named("current dependency")
|
80
|
+
dep.license = License.find_by_name('not approved')
|
81
|
+
dep.save
|
87
82
|
dep.reload.should_not be_approved
|
88
83
|
described_class.approve!("current dependency")
|
89
84
|
dep.reload.should be_approved
|
90
85
|
end
|
91
86
|
|
87
|
+
it "optionally adds approver and approval notes" do
|
88
|
+
dep = Dependency.named("current dependency")
|
89
|
+
described_class.approve!("current dependency", "Julian", "We really need this")
|
90
|
+
approval = dep.reload.manual_approval
|
91
|
+
approval.approver.should eq "Julian"
|
92
|
+
approval.notes.should eq "We really need this"
|
93
|
+
end
|
94
|
+
|
92
95
|
it "should raise an error if it can't find the dependency" do
|
93
96
|
expect { described_class.approve!("non-existent dependency") }
|
94
|
-
.to raise_error(
|
97
|
+
.to raise_error(Error)
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
@@ -100,13 +103,13 @@ module LicenseFinder
|
|
100
103
|
|
101
104
|
it "adds a license for the dependency" do
|
102
105
|
DependencyManager.stub(:find_by_name).with("dependency").and_return(dependency)
|
103
|
-
dependency.should_receive(:set_license_manually!).with("MIT")
|
106
|
+
dependency.should_receive(:set_license_manually!).with(License.find_by_name "MIT")
|
104
107
|
described_class.license!("dependency", "MIT")
|
105
108
|
end
|
106
109
|
|
107
110
|
it "should raise an error if it can't find the dependency" do
|
108
111
|
expect { described_class.license!("non-existent dependency", "a license") }
|
109
|
-
.to raise_error(
|
112
|
+
.to raise_error(Error)
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
@@ -145,27 +148,43 @@ module LicenseFinder
|
|
145
148
|
context "when the database has not changed" do
|
146
149
|
before do
|
147
150
|
Digest::SHA2.stub_chain(:file, :hexdigest) { 5 }
|
151
|
+
allow(config).to receive(:last_modified) { config_last_update }
|
152
|
+
allow(config.artifacts).to receive(:last_refreshed) { artifacts_last_update }
|
148
153
|
end
|
149
154
|
|
150
|
-
context "
|
155
|
+
context "and the reports do not exist" do
|
151
156
|
before do
|
152
|
-
config.artifacts.stub(:html_file).and_return(
|
157
|
+
config.artifacts.stub(:html_file).and_return(file_does_not_exist)
|
153
158
|
end
|
154
159
|
|
155
|
-
it "
|
156
|
-
Reporter.
|
160
|
+
it "writes reports" do
|
161
|
+
Reporter.should_receive(:write_reports)
|
157
162
|
DependencyManager.modifying {}
|
158
163
|
end
|
159
164
|
end
|
160
165
|
|
161
|
-
context "
|
166
|
+
context "and the reports exist" do
|
162
167
|
before do
|
163
|
-
config.artifacts.stub(:html_file).and_return(
|
168
|
+
config.artifacts.stub(:html_file).and_return(file_exists)
|
164
169
|
end
|
165
170
|
|
166
|
-
|
167
|
-
|
168
|
-
|
171
|
+
context "and configs are newer than the reports" do
|
172
|
+
let(:config_last_update) { 4 }
|
173
|
+
let(:artifacts_last_update) { 1 }
|
174
|
+
it "writes reports" do
|
175
|
+
expect(Reporter).to receive(:write_reports)
|
176
|
+
DependencyManager.modifying {}
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "and configs are older than the reports" do
|
181
|
+
let(:config_last_update) { 4 }
|
182
|
+
let(:artifacts_last_update) { 6 }
|
183
|
+
|
184
|
+
it "does not write reports" do
|
185
|
+
expect(Reporter).not_to receive(:write_reports)
|
186
|
+
DependencyManager.modifying {}
|
187
|
+
end
|
169
188
|
end
|
170
189
|
end
|
171
190
|
end
|