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,13 @@
1
+ module LicenseFinder
2
+ class MergedReport < CsvReport
3
+ AVAILABLE_COLUMNS = AVAILABLE_COLUMNS + ['subproject_paths']
4
+
5
+ def initialize(dependencies, options = {})
6
+ super(dependencies, options.merge(columns: %w(name version licenses subproject_paths)))
7
+ end
8
+
9
+ def format_subproject_paths(merged_dep)
10
+ merged_dep.subproject_paths.join(self.class::COMMA_SEP)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module LicenseFinder
2
- VERSION = "2.0.4"
2
+ VERSION = "2.1.0.rc1"
3
3
  end
@@ -1,5 +1,8 @@
1
- require './lib/license_finder/platform'
2
- require './lib/license_finder/version'
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'license_finder/platform'
5
+ require 'license_finder/version'
3
6
 
4
7
  Gem::Specification.new do |s|
5
8
  s.required_ruby_version = '>= 1.9.3'
@@ -42,6 +45,7 @@ Gem::Specification.new do |s|
42
45
 
43
46
  s.add_development_dependency "rake"
44
47
  s.add_development_dependency "rspec-its"
48
+ s.add_development_dependency "fakefs"
45
49
  s.add_development_dependency "pry"
46
50
  s.add_development_dependency "rspec", "~> 3"
47
51
  s.add_development_dependency "capybara", "~> 2.0.0"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.1.5'
4
+
5
+ gem 'bundler'
6
+ gem 'httparty'
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ project_go_root="$(dirname ${BASH_SOURCE[0]})/../../../../"
2
+
3
+ cd $project_go_root
4
+ if [ $(basename $PWD) == "cf-release" ]
5
+ then
6
+ export GOPATH=$GOPATH:$PWD
7
+ fi
8
+ cd -
@@ -0,0 +1,16 @@
1
+ {
2
+ "ImportPath": "github.com/pivotal/foo",
3
+ "GoVersion": "go1.4.2",
4
+ "Deps": [
5
+ {
6
+ "ImportPath": "github.com/onsi/ginkgo",
7
+ "Comment": "v1.2.0-6-gd981d36",
8
+ "Rev": "d981d36e9884231afa909627b9c275e4ba678f90"
9
+ },
10
+ {
11
+ "ImportPath": "github.com/onsi/gomega",
12
+ "Comment": "v1.0-50-gd6c945f",
13
+ "Rev": "d6c945f9fdbf6cad99e85b0feff591caa268e0db"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,5 @@
1
+ This directory tree is generated automatically by godep.
2
+
3
+ Please do not edit.
4
+
5
+ See https://github.com/tools/godep for more information.
@@ -0,0 +1,6 @@
1
+ package foo
2
+
3
+ import (
4
+ . "github.com/onsi/ginkgo"
5
+ . "github.com/onsi/gomega"
6
+ )
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "#add" do
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ module CLI
5
+ describe Blacklist do
6
+ let(:decisions) { Decisions.new }
7
+
8
+ before do
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
+ end
11
+
12
+ describe "list" do
13
+ it "shows the blacklist of licenses" do
14
+ decisions.blacklist("MIT")
15
+
16
+ expect(capture_stdout { subject.list }).to match /MIT/
17
+ end
18
+ end
19
+
20
+ describe "add" do
21
+ it "adds the specified license to the blacklist" do
22
+ silence_stdout do
23
+ subject.add("test")
24
+ end
25
+ expect(subject.decisions.blacklisted).to eq [License.find_by_name("test")].to_set
26
+ end
27
+
28
+ it "adds multiple licenses to the blacklist" do
29
+ silence_stdout do
30
+ subject.add("test", "rest")
31
+ end
32
+ expect(subject.decisions.blacklisted).to eq [
33
+ License.find_by_name("test"),
34
+ License.find_by_name("rest")
35
+ ].to_set
36
+ end
37
+ end
38
+
39
+ describe "remove" do
40
+ it "removes the specified license from the blacklist" do
41
+ silence_stdout do
42
+ subject.add("test")
43
+ subject.remove("test")
44
+ end
45
+ expect(subject.decisions.blacklisted).to be_empty
46
+ end
47
+
48
+ it "removes multiple licenses from the blacklist" do
49
+ silence_stdout do
50
+ subject.add("test", "rest")
51
+ subject.remove("test", "rest")
52
+ end
53
+ expect(subject.decisions.blacklisted).to be_empty
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "add" do
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "list" do
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "list" do
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "add" do
@@ -11,22 +11,66 @@ module LicenseFinder
11
11
  packages: packages
12
12
  )
13
13
  end
14
+ let(:configuration) { double(:configuration, valid_project_path?: true) }
15
+ let(:license_finder_instance) { double(:license_finder, unapproved: [unapproved_dependency], blacklisted: [], project_name: 'taco stand', config: configuration) }
16
+ let(:license) { double(:license, name: "thing") }
17
+ let(:unapproved_dependency) { double(:dependency, name: "a dependency", version: "2.4.1", missing?: false, licenses: [license]) }
14
18
 
15
19
  before do
16
- allow(Decisions).to receive(:saved!) { decisions }
20
+ allow(Decisions).to receive(:fetch_saved) { decisions }
17
21
  allow(DecisionApplier).to receive(:new) { decision_applier }
18
22
  end
19
23
 
20
24
  describe "default" do
21
25
  it "checks for action items" do
22
26
  decisions.add_package("a dependency", nil)
23
-
27
+ expect_any_instance_of(LicenseFinder::Core).to receive(:unapproved).and_return([unapproved_dependency])
24
28
  silence_stdout do
25
29
  expect { described_class.start(["--quiet"]) }.to raise_error(SystemExit)
26
30
  end
27
31
  end
28
32
  end
29
33
 
34
+ describe "cli options" do
35
+ let(:config_options) { [
36
+ "--decisions_file=whatever.yml",
37
+ "--project_path=../other_project",
38
+ "--gradle_command=do_things",
39
+ "--rebar_command=do_other_things",
40
+ "--rebar_deps_dir=rebar_dir",
41
+ "--save"
42
+ ] }
43
+ let(:logger_options) {
44
+ [
45
+ '--quiet',
46
+ '--debug'
47
+ ]
48
+ }
49
+ let(:parsed_config) { {
50
+ decisions_file: 'whatever.yml',
51
+ project_path: '../other_project',
52
+ gradle_command: 'do_things',
53
+ rebar_command: 'do_other_things',
54
+ rebar_deps_dir: 'rebar_dir',
55
+ save: 'license_report',
56
+ logger: {}
57
+ } }
58
+
59
+ it "passes the config options to the new LicenseFinder::Core instance" do
60
+ expect(LicenseFinder::Core).to receive(:new).with(parsed_config).and_return(license_finder_instance)
61
+ silence_stdout do
62
+ expect { described_class.start(config_options) }.to raise_error(SystemExit)
63
+ end
64
+ end
65
+
66
+ it "passes the logger options to the new LicenseFinder::Core instance" do
67
+ expect(LicenseFinder::Core).to receive(:new).with({logger: {debug: true, quiet: true}}).and_return(license_finder_instance)
68
+ silence_stdout do
69
+ expect { described_class.start(logger_options) }.to raise_error(SystemExit)
70
+ end
71
+ end
72
+ end
73
+
30
74
  describe "#report" do
31
75
  let(:packages) { [Package.new('one dependency', "1.1")] }
32
76
 
@@ -39,20 +83,20 @@ module LicenseFinder
39
83
  end
40
84
 
41
85
  it "will output a specific format" do
42
- subject.options = { format: 'markdown' }
86
+ subject.options = {format: 'markdown'}
43
87
 
44
88
  expect(report).to include "## Action"
45
89
  end
46
90
 
47
91
  it "will output a custom csv" do
48
- subject.options = { format: 'csv', columns: ['name', 'version'] }
92
+ subject.options = {format: 'csv', columns: ['name', 'version']}
49
93
 
50
94
  expect(report).to eq "one dependency,1.1\n"
51
95
  end
52
96
 
53
97
  context "in html reports" do
54
98
  before do
55
- subject.options = { format: 'html' }
99
+ subject.options = {format: 'html'}
56
100
  end
57
101
 
58
102
  context "when the project has a name" do
@@ -64,18 +108,68 @@ module LicenseFinder
64
108
  end
65
109
 
66
110
  context "when the project has no name" do
67
- before { allow(Dir).to receive(:getwd).and_return("/path/to/a_project") }
111
+ before { allow_any_instance_of(Pathname).to receive(:basename).and_return("a_project") }
68
112
 
69
113
  it "should default to the directory name" do
70
114
  expect(report).to include "a_project"
71
115
  end
72
116
  end
73
117
  end
118
+
119
+ context "when the --save option is passed" do
120
+ it "calls report method and calls save_report" do
121
+ subject.options = {save: "license_report", format: 'text'}
122
+ expect(subject).to receive(:report).and_call_original
123
+ expect(subject).to receive(:save_report)
124
+
125
+ subject.report
126
+ end
127
+
128
+ context "when file name is not specified (--save)" do
129
+ it "creates report that is called the default file name" do
130
+ provided_by_thor_as_default_name = "license_report" #####FIX ME
131
+ subject.options = {save: provided_by_thor_as_default_name, format: 'text'}
132
+ expect(subject).to receive(:report).and_call_original
133
+ expect(subject).to receive(:save_report).with(instance_of(String), "license_report")
134
+
135
+ subject.report
136
+ end
137
+
138
+ it "saves the output report to default file ('license_report.txt') in project root" do
139
+ mock_file = double(:file)
140
+ expect(File).to receive(:open).with("license_report.txt", "w").and_yield(mock_file)
141
+ expect(mock_file).to receive(:write).with("content of file")
142
+
143
+ subject.send(:save_report, "content of file", "license_report.txt")
144
+ end
145
+ end
146
+
147
+ context "when file name is specified (--save='FILENAME')" do
148
+ it "saves with a specified file name" do
149
+ subject.options = {save: 'my_report' , format: 'text'}
150
+ expect(subject).to receive(:report).and_call_original
151
+ expect(subject).to receive(:save_report).with(instance_of(String), "my_report")
152
+
153
+ subject.report
154
+ end
155
+ end
156
+ end
157
+
158
+ context "when the --save option is not passed" do
159
+ it "calls report method and does not call save_report" do
160
+ subject.options = {format: 'text'}
161
+ expect(subject).to receive(:report).and_call_original
162
+ expect(subject).not_to receive(:save_report)
163
+ expect(subject).to receive(:report_of)
164
+
165
+ report
166
+ end
167
+ end
74
168
  end
75
169
 
76
170
  describe "#action_items" do
77
171
  def action_items
78
- subject.options = { quiet: true, format: 'text' }
172
+ subject.options = {quiet: true, format: 'text'}
79
173
  subject.action_items
80
174
  end
81
175
 
@@ -91,6 +185,18 @@ module LicenseFinder
91
185
  end
92
186
  end
93
187
 
188
+ context "with blacklisted dependencies" do
189
+ let(:decisions) { Decisions.new.blacklist('GPLv3')}
190
+ let(:packages) { [Package.new('blacklisted', '1.0', spec_licenses: ['GPLv3'])] }
191
+
192
+ it "reports blacklisted dependencies" do
193
+ result = capture_stdout do
194
+ expect { action_items }.to raise_error(SystemExit)
195
+ end
196
+ expect(result).to include "Blacklisted dependencies:\nblacklisted, 1.0, GPLv3"
197
+ end
198
+ end
199
+
94
200
  it "reports that all dependencies are approved" do
95
201
  result = capture_stdout do
96
202
  expect { action_items }.not_to raise_error
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "show" do
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  let(:decisions) { Decisions.new }
7
7
 
8
8
  before do
9
- allow(Decisions).to receive(:saved!) { decisions }
9
+ allow(Decisions).to receive(:fetch_saved) { decisions }
10
10
  end
11
11
 
12
12
  describe "list" do
@@ -4,9 +4,31 @@ module LicenseFinder
4
4
  describe Configuration do
5
5
  describe ".with_optional_saved_config" do
6
6
  it "should init and use saved config" do
7
- subject = described_class.with_optional_saved_config({}, fixture_path("."))
7
+ subject = described_class.with_optional_saved_config({project_path: fixture_path(".")})
8
8
  expect(subject.gradle_command).to eq('gradlew')
9
9
  end
10
+
11
+ it "prepends the project_path to the config file path" do
12
+ subject = described_class.with_optional_saved_config({project_path: "other_directory"})
13
+ expect(subject.send(:saved_config)).to eq({})
14
+ end
15
+ end
16
+
17
+ describe "#valid_project_path?" do
18
+ it "returns false when the path does not exist" do
19
+ subject = described_class.with_optional_saved_config({project_path: '/path/that/does/not/exist'})
20
+ expect(subject.valid_project_path?).to be(false)
21
+ end
22
+
23
+ it "returns true when the path exists" do
24
+ subject = described_class.with_optional_saved_config({project_path: '/'})
25
+ expect(subject.valid_project_path?).to be(true)
26
+ end
27
+
28
+ it "returns true if the path is not provided" do
29
+ subject = described_class.with_optional_saved_config({})
30
+ expect(subject.valid_project_path?).to be(true)
31
+ end
10
32
  end
11
33
 
12
34
  describe "gradle_command" do
@@ -41,7 +63,7 @@ module LicenseFinder
41
63
  {decisions_file: "primary"},
42
64
  {"decisions_file" => "secondary"}
43
65
  )
44
- expect(subject.decisions_file.to_s).to eq "primary"
66
+ expect(subject.decisions_file_path.to_s).to end_with "primary"
45
67
  end
46
68
 
47
69
  it "accepts saved value" do
@@ -49,7 +71,7 @@ module LicenseFinder
49
71
  {decisions_file: nil},
50
72
  {"decisions_file" => "secondary"}
51
73
  )
52
- expect(subject.decisions_file.to_s).to eq "secondary"
74
+ expect(subject.decisions_file_path.to_s).to end_with "secondary"
53
75
  end
54
76
 
55
77
  it "has default" do
@@ -57,7 +79,44 @@ module LicenseFinder
57
79
  {decisions_file: nil},
58
80
  {"decisions_file" => nil}
59
81
  )
60
- expect(subject.decisions_file.to_s).to eq "doc/dependency_decisions.yml"
82
+ expect(subject.decisions_file_path.to_s).to end_with "doc/dependency_decisions.yml"
83
+ end
84
+
85
+ it "prepends project path to default path if project_path option is set" do
86
+ subject = described_class.new({project_path: "magic_path"}, {})
87
+ expect(subject.decisions_file_path.to_s).to end_with "magic_path/doc/dependency_decisions.yml"
88
+ end
89
+
90
+ it "prepends project path to provided value" do
91
+ subject = described_class.new({decisions_file: "primary",
92
+ project_path: "magic_path"},
93
+ {"decisions_file" => "secondary"}
94
+ )
95
+ expect(subject.decisions_file_path.to_s).to end_with "magic_path/primary"
96
+ end
97
+ end
98
+
99
+ describe "rebar_deps_dir" do
100
+ it "has default" do
101
+ subject = described_class.new(
102
+ {rebar_deps_dir: nil},
103
+ {"rebar_deps_dir" => nil}
104
+ )
105
+ expect(subject.rebar_deps_dir.to_s).to end_with "deps"
106
+ end
107
+
108
+ it "prepends project path to default path if project_path option is set" do
109
+ subject = described_class.new({project_path: "magic_path"}, {})
110
+ expect(subject.rebar_deps_dir.to_s).to end_with "magic_path/deps"
111
+ end
112
+
113
+ it "prepends project path to provided value" do
114
+ subject = described_class.new(
115
+ {rebar_deps_dir: "primary",
116
+ project_path: "magic_path"},
117
+ {"rebar_deps_dir" => "secondary"}
118
+ )
119
+ expect(subject.rebar_deps_dir.to_s).to end_with "magic_path/primary"
61
120
  end
62
121
  end
63
122
  end