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.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.force-build +0 -0
  3. data/.travis.yml +8 -7
  4. data/CHANGELOG.rdoc +29 -1
  5. data/Rakefile +2 -2
  6. data/db/migrate/201311192003_reassociate_manual_approval.rb +2 -3
  7. data/db/migrate/201403181732_rename_manual_fields.rb +10 -0
  8. data/db/migrate/201403190028_add_manual_approvals.rb +22 -0
  9. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +15 -0
  10. data/db/migrate/201403191645_remove_license_aliases.rb +23 -0
  11. data/features/cli.feature +21 -20
  12. data/features/cocoapods_dependencies.feature +10 -0
  13. data/features/configure_bundler_groups.feature +23 -0
  14. data/features/configure_ignore_dependencies.feature +16 -0
  15. data/features/{project_name.feature → configure_project_name.feature} +1 -1
  16. data/features/{whitelist.feature → configure_whitelist.feature} +6 -6
  17. data/features/manually_added.feature +19 -0
  18. data/features/{approve_dependencies.feature → manually_approved.feature} +2 -2
  19. data/features/manually_assigned_license.feature +16 -0
  20. data/features/{text_report.feature → report_csv.feature} +2 -2
  21. data/features/{html_report.feature → report_html.feature} +2 -2
  22. data/features/step_definitions/cli_steps.rb +22 -32
  23. data/features/step_definitions/cocoapod_steps.rb +8 -0
  24. data/features/step_definitions/configure_bundler_groups_steps.rb +30 -0
  25. data/features/step_definitions/configure_ignore_dependencies.rb +35 -0
  26. data/features/step_definitions/{project_name_steps.rb → configure_project_name_steps.rb} +0 -0
  27. data/features/step_definitions/configure_whitelist_steps.rb +45 -0
  28. data/features/step_definitions/gradle_steps.rb +2 -2
  29. data/features/step_definitions/manually_added_steps.rb +28 -0
  30. data/features/step_definitions/manually_approved_steps.rb +24 -0
  31. data/features/step_definitions/manually_assigned_license_steps.rb +34 -0
  32. data/features/step_definitions/maven_steps.rb +2 -2
  33. data/features/step_definitions/node_steps.rb +2 -2
  34. data/features/step_definitions/python_steps.rb +1 -1
  35. data/features/step_definitions/report_csv_steps.rb +20 -0
  36. data/features/step_definitions/report_html_steps.rb +60 -0
  37. data/features/step_definitions/shared_steps.rb +125 -104
  38. data/{files/license_finder.yml → lib/data/license_finder.example.yml} +3 -0
  39. data/lib/license_finder.rb +3 -2
  40. data/lib/license_finder/cli.rb +94 -49
  41. data/lib/license_finder/configuration.rb +21 -14
  42. data/lib/license_finder/dependency_manager.rb +27 -19
  43. data/lib/license_finder/license.rb +33 -19
  44. data/lib/license_finder/license/definitions.rb +153 -104
  45. data/lib/license_finder/license/matcher.rb +6 -1
  46. data/lib/license_finder/license/none_matcher.rb +9 -0
  47. data/lib/license_finder/license/text.rb +1 -0
  48. data/lib/license_finder/package.rb +30 -6
  49. data/lib/license_finder/package_managers/bower.rb +2 -2
  50. data/lib/license_finder/package_managers/bower_package.rb +2 -2
  51. data/lib/license_finder/package_managers/bundler.rb +9 -17
  52. data/lib/license_finder/package_managers/bundler_package.rb +1 -1
  53. data/lib/license_finder/package_managers/cocoa_pods.rb +35 -0
  54. data/lib/license_finder/package_managers/cocoa_pods_package.rb +19 -0
  55. data/lib/license_finder/package_managers/gradle.rb +9 -5
  56. data/lib/license_finder/package_managers/gradle_package.rb +4 -4
  57. data/lib/license_finder/package_managers/maven.rb +7 -3
  58. data/lib/license_finder/package_managers/maven_package.rb +5 -5
  59. data/lib/license_finder/package_managers/npm.rb +2 -2
  60. data/lib/license_finder/package_managers/npm_package.rb +2 -2
  61. data/lib/license_finder/package_managers/pip.rb +2 -2
  62. data/lib/license_finder/package_managers/pip_package.rb +7 -11
  63. data/lib/license_finder/package_saver.rb +12 -10
  64. data/lib/license_finder/possible_license_file.rb +1 -1
  65. data/lib/license_finder/possible_license_files.rb +11 -15
  66. data/lib/license_finder/reports/formatted_report.rb +25 -6
  67. data/lib/license_finder/reports/html_report.rb +2 -1
  68. data/lib/license_finder/reports/reporter.rb +3 -3
  69. data/lib/license_finder/tables.rb +6 -4
  70. data/lib/license_finder/tables/dependency.rb +36 -16
  71. data/lib/license_finder/tables/manual_approval.rb +13 -0
  72. data/lib/license_finder/yml_to_sql.rb +12 -9
  73. data/lib/templates/html_report.erb +68 -74
  74. data/lib/templates/markdown_report.erb +20 -21
  75. data/license_finder.gemspec +7 -7
  76. data/readme.md +76 -79
  77. data/spec/fixtures/Podfile +3 -0
  78. data/spec/lib/license_finder/cli_spec.rb +71 -23
  79. data/spec/lib/license_finder/configuration_spec.rb +61 -21
  80. data/spec/lib/license_finder/dependency_manager_spec.rb +52 -33
  81. data/spec/lib/license_finder/license/definitions_spec.rb +30 -14
  82. data/spec/lib/license_finder/license_spec.rb +55 -12
  83. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +38 -19
  84. data/spec/lib/license_finder/package_managers/bower_spec.rb +10 -16
  85. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +39 -15
  86. data/spec/lib/license_finder/package_managers/bundler_spec.rb +10 -22
  87. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +44 -0
  88. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +79 -0
  89. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +4 -5
  90. data/spec/lib/license_finder/package_managers/gradle_spec.rb +26 -20
  91. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +4 -5
  92. data/spec/lib/license_finder/package_managers/maven_spec.rb +16 -19
  93. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +39 -19
  94. data/spec/lib/license_finder/package_managers/npm_spec.rb +10 -16
  95. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +8 -8
  96. data/spec/lib/license_finder/package_managers/pip_spec.rb +10 -16
  97. data/spec/lib/license_finder/package_saver_spec.rb +27 -3
  98. data/spec/lib/license_finder/possible_license_file_spec.rb +25 -23
  99. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +6 -8
  100. data/spec/lib/license_finder/reports/html_report_spec.rb +45 -44
  101. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -9
  102. data/spec/lib/license_finder/reports/reporter_spec.rb +1 -1
  103. data/spec/lib/license_finder/reports/text_report_spec.rb +6 -8
  104. data/spec/lib/license_finder/tables/dependency_spec.rb +57 -41
  105. data/spec/lib/license_finder/yml_to_sql_spec.rb +94 -92
  106. data/spec/spec_helper.rb +1 -0
  107. data/spec/support/stdout_helpers.rb +25 -0
  108. metadata +86 -69
  109. data/MIT.LICENSE +0 -20
  110. data/features/ignore_bundle_groups.feature +0 -23
  111. data/features/manually_managed_dependencies.feature +0 -19
  112. data/features/set_license.feature +0 -10
  113. data/features/step_definitions/approve_dependencies_steps.rb +0 -25
  114. data/features/step_definitions/html_report_steps.rb +0 -62
  115. data/features/step_definitions/ignore_bundle_groups_steps.rb +0 -29
  116. data/features/step_definitions/manually_managed_steps.rb +0 -33
  117. data/features/step_definitions/set_license_steps.rb +0 -20
  118. data/features/step_definitions/text_report_steps.rb +0 -19
  119. data/features/step_definitions/whitelist_steps.rb +0 -45
  120. data/files/dependency_breakdown.png +0 -0
  121. data/files/report_breakdown.png +0 -0
  122. data/lib/license_finder/license_url.rb +0 -9
  123. data/lib/license_finder/tables/license_alias.rb +0 -22
  124. data/spec/lib/license_finder/license_url_spec.rb +0 -16
  125. data/spec/lib/license_finder/tables/license_alias_spec.rb +0 -37
  126. data/spec/support/silence_stdout.rb +0 -13
@@ -1,32 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe LicenseFinder::License::Definitions do
4
+ it "should create unrecognized licenses" do
5
+ license = described_class.build_unrecognized("foo", [])
6
+ license.name.should == "foo"
7
+ license.url.should be_nil
8
+ license.should be_matches_name("foo")
9
+ license.should_not be_matches_text("foo")
10
+ license.should_not be_whitelisted
11
+ end
12
+
13
+ it "should whitelist unrecognized licenses" do
14
+ license = described_class.build_unrecognized("foo", ["foo"])
15
+ license.should be_whitelisted
16
+ end
17
+ end
18
+
3
19
  describe LicenseFinder::License, "Apache2" do
4
- it "should be findable" do |e|
5
- described_class.find_by_name("Apache2").should be
20
+ it "should be recognized" do |e|
21
+ described_class.find_by_name("Apache2").url.should be
6
22
  end
7
23
  end
8
24
 
9
25
  describe LicenseFinder::License, "BSD" do
10
- it "should be findable" do |e|
11
- described_class.find_by_name("BSD").should be
26
+ it "should be recognized" do |e|
27
+ described_class.find_by_name("BSD").url.should be
12
28
  end
13
29
  end
14
30
 
15
31
  describe LicenseFinder::License, "GPLv2" do
16
- it "should be findable" do
17
- described_class.find_by_name("GPLv2").should be
32
+ it "should be recognized" do
33
+ described_class.find_by_name("GPLv2").url.should be
18
34
  end
19
35
  end
20
36
 
21
37
  describe LicenseFinder::License, "ISC" do
22
- it "should be findable" do
23
- described_class.find_by_name("ISC").should be
38
+ it "should be recognized" do
39
+ described_class.find_by_name("ISC").url.should be
24
40
  end
25
41
  end
26
42
 
27
43
  describe LicenseFinder::License, "LGPL" do
28
- it "should be findable" do
29
- described_class.find_by_name("LGPL").should be
44
+ it "should be recognized" do
45
+ described_class.find_by_name("LGPL").url.should be
30
46
  end
31
47
  end
32
48
 
@@ -119,8 +135,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119
135
  end
120
136
 
121
137
  describe LicenseFinder::License, "Python" do
122
- it "should be findable" do
123
- described_class.find_by_name("Python").should be
138
+ it "should be recognized" do
139
+ described_class.find_by_name("Python").url.should be
124
140
  end
125
141
  end
126
142
 
@@ -143,7 +159,7 @@ describe LicenseFinder::License, "Ruby" do
143
159
  end
144
160
 
145
161
  describe LicenseFinder::License, "SimplifiedBSD" do
146
- it "should be findable" do
147
- described_class.find_by_name("SimplifiedBSD").should be
162
+ it "should be recognized" do
163
+ described_class.find_by_name("SimplifiedBSD").url.should be
148
164
  end
149
165
  end
@@ -7,12 +7,30 @@ module LicenseFinder
7
7
  License.find_by_name("Apache2").should be_a License
8
8
  end
9
9
 
10
- context "when license not found" do
11
- it "should return UnknownLicense with the name" do
12
- license = License.find_by_name("New License")
10
+ it "should make an unrecognized license" do
11
+ license = License.find_by_name("not a known license")
13
12
 
14
- expect(license).to be_a UnknownLicense
15
- expect(license.pretty_name).to eq "New License"
13
+ expect(license).to be_a License
14
+ expect(license.name).to eq "not a known license"
15
+ end
16
+
17
+ context "making the default license" do
18
+ it "set the name to 'other'" do
19
+ License.find_by_name(nil).name.should == "other"
20
+ end
21
+
22
+ it "does not equal other uses of the default license" do
23
+ License.find_by_name(nil).should_not == License.find_by_name(nil)
24
+ end
25
+
26
+ context "when there is a whitelist" do
27
+ before do
28
+ LicenseFinder.config.stub(:whitelist).and_return(["not empty"])
29
+ end
30
+
31
+ it "does not blow up" do
32
+ License.find_by_name(nil).name.should == "other"
33
+ end
16
34
  end
17
35
  end
18
36
  end
@@ -22,20 +40,39 @@ module LicenseFinder
22
40
  License.find_by_text('This gem is released under the MIT license').should be_a License
23
41
  end
24
42
 
25
- it "returns UnknownLicense with nil name if not found" do
43
+ it "returns nil if not found" do
26
44
  license = License.find_by_text("foo")
27
45
 
28
- expect(license).to be_a UnknownLicense
29
- expect(license.pretty_name).to be_nil
46
+ expect(license).to be_nil
30
47
  end
31
48
  end
32
49
 
33
50
  def make_license(settings = {})
34
- described_class.new({
51
+ defaults = {
35
52
  short_name: "Default Short Name",
36
53
  url: "http://example.com/license",
54
+ whitelisted: false,
37
55
  matcher: License::Matcher.from_text('Default Matcher')
38
- }.merge(settings))
56
+ }
57
+
58
+ License.new(defaults.merge(settings))
59
+ end
60
+
61
+ describe "#whitelisted?" do
62
+ it "is true if the settings say it is" do
63
+ make_license.should_not be_whitelisted
64
+ make_license(whitelisted: true).should be_whitelisted
65
+ end
66
+
67
+ it "can be made true (without mutating original)" do
68
+ original = make_license
69
+ license = original.whitelist
70
+ license.should_not == original
71
+ license.should be_whitelisted
72
+ license.url.should == "http://example.com/license"
73
+ license.should be_matches_name "Default Short Name"
74
+ license.should be_matches_text "Default Matcher"
75
+ end
39
76
  end
40
77
 
41
78
  describe "#matches_name?" do
@@ -65,7 +102,7 @@ module LicenseFinder
65
102
 
66
103
  describe ".matches_text?" do
67
104
  it "should match on text" do
68
- license = make_license(matcher: License::Matcher.new(/The license text/))
105
+ license = make_license(matcher: License::Matcher.from_regex(/The license text/))
69
106
  license.should be_matches_text "The license text"
70
107
  license.should_not be_matches_text "Some other text"
71
108
  end
@@ -82,10 +119,16 @@ module LicenseFinder
82
119
  shall not be held "responsible" for `anything`.
83
120
  FILE
84
121
  end
122
+
123
+ it "should match even if whitespace at beginning and end don't match" do
124
+ template = License::Template.new("\nThe license text")
125
+ license = make_license(matcher: License::Matcher.from_template(template))
126
+ license.should be_matches_text "The license text\n"
127
+ end
85
128
  end
86
129
 
87
130
  it "should default pretty_name to short_name" do
88
- make_license.pretty_name.should == "Default Short Name"
131
+ make_license.name.should == "Default Short Name"
89
132
  end
90
133
  end
91
134
  end
@@ -37,34 +37,53 @@ module LicenseFinder
37
37
  let(:package4) { { "pkgMeta" => {"licenses" => ["MIT"]}, "canonicalDir" => "/some/path" } }
38
38
 
39
39
  it 'finds the license for both license structures' do
40
- BowerPackage.new(package1).license.should eq("MIT")
41
- BowerPackage.new(package2).license.should eq("BSD")
42
- BowerPackage.new(package3).license.should eq("PSF")
43
- BowerPackage.new(package4).license.should eq("MIT")
40
+ BowerPackage.new(package1).license.name.should eq("MIT")
41
+ BowerPackage.new(package2).license.name.should eq("BSD")
42
+ BowerPackage.new(package3).license.name.should eq("Python Software Foundation License")
43
+ BowerPackage.new(package4).license.name.should eq("MIT")
44
44
  end
45
45
 
46
- it "returns a license in a file if detected" do
47
- stub_license_files [double(:file, license: 'Detected License')]
48
46
 
49
- subject.license.should == "Detected License"
50
- end
47
+ context "regardless of whether there are licenses in files" do
48
+ before do
49
+ stub_license_files [double(:file, license: License.find_by_name('Detected License'))]
50
+ end
51
+
52
+ it "returns the license from the spec if there is only one unique license" do
53
+ package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT", "Expat"]}, "canonicalDir" => "/path/to/thing" })
54
+ expect(package.license.name).to eq("MIT")
55
+ end
51
56
 
52
- it "returns other if there's more than one license" do
53
- package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT", "BSD"]}, "canonicalDir" => "/some/path" })
54
- expect(package.license).to eq("other")
57
+ it "returns 'multiple licenses' if there's more than one license" do
58
+ package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT", "BSD"]}, "canonicalDir" => "/some/path" })
59
+ expect(package.license.name).to eq("multiple licenses: MIT, BSD")
60
+ end
55
61
  end
56
62
 
57
- it "returns other if the license from spec and license from files are different" do
58
- stub_license_files [double(:file, license: 'Detected License')]
59
- package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT"]}, "canonicalDir" => "/path/to/thing" })
63
+ context "when there is nothing in the spec" do
64
+ it "returns a license in a file if only one unique license detected" do
65
+ stub_license_files([
66
+ double(:first_file, license: License.find_by_name('MIT')),
67
+ double(:second_file, license: License.find_by_name('Expat'))
68
+ ])
60
69
 
61
- expect(package.license).to eq("other")
62
- end
70
+ subject.license.name.should == "MIT"
71
+ end
72
+
73
+ it "returns 'other' if there are no licenses in files" do
74
+ stub_license_files []
75
+
76
+ subject.license.name.should == "other"
77
+ end
63
78
 
64
- it "returns 'other' otherwise" do
65
- stub_license_files []
79
+ it "returns 'other' if there are many licenses in files" do
80
+ stub_license_files([
81
+ double(:first_file, license: License.find_by_name('First Detected License')),
82
+ double(:second_file, license: License.find_by_name('Second Detected License'))
83
+ ])
66
84
 
67
- subject.license.should == "other"
85
+ subject.license.name.should == "multiple licenses: First Detected License, Second Detected License"
86
+ end
68
87
  end
69
88
  end
70
89
  end
@@ -38,26 +38,20 @@ module LicenseFinder
38
38
  end
39
39
 
40
40
  describe '.active?' do
41
- let(:package) { Pathname.new('bower.json').expand_path }
41
+ let(:package) { double(:package_file) }
42
42
 
43
- context 'with a bower.json file' do
44
- before :each do
45
- allow(File).to receive(:exists?).with(package).and_return(true)
46
- end
47
-
48
- it 'returns true' do
49
- expect(Bower.active?).to eq(true)
50
- end
43
+ before do
44
+ Bower.stub(package_path: package)
51
45
  end
52
46
 
53
- context 'without a bower.json file' do
54
- before :each do
55
- allow(File).to receive(:exists?).with(package).and_return(false)
56
- end
47
+ it 'is true with a bower.json file' do
48
+ package.stub(:exist? => true)
49
+ expect(Bower).to be_active
50
+ end
57
51
 
58
- it 'returns false' do
59
- expect(Bower.active?).to eq(false)
60
- end
52
+ it 'is false without a bower.json file' do
53
+ package.stub(:exist? => false)
54
+ expect(Bower).to_not be_active
61
55
  end
62
56
  end
63
57
  end
@@ -31,28 +31,52 @@ module LicenseFinder
31
31
  PossibleLicenseFiles.stub(:find).and_return(license_files)
32
32
  end
33
33
 
34
- it "returns the license from the gemspec if provided" do
35
- gemspec.license = 'Gemspec License'
36
-
37
- subject.license.should == "Gemspec License"
34
+ context "regardless of whether there are licenses in files" do
35
+ before do
36
+ stub_license_files [double(:file, license: License.find_by_name('Detected License'))]
37
+ end
38
+
39
+ context 'if the gemspec provides two synonymous licenses' do
40
+ before { gemspec.licenses = ['MIT', 'Expat'] }
41
+
42
+ it 'returns the license only once' do
43
+ subject.license.name.should == "MIT"
44
+ end
45
+ end
46
+
47
+ context 'if the gemspec provides many licenses' do
48
+ before { gemspec.licenses = ['First Gemspec License', 'Second Gemspec License'] }
49
+
50
+ it "returns 'multiple licenses' with the names of the licenses from the gemspec (but not those from detected files)" do
51
+ subject.license.name.should == "multiple licenses: First Gemspec License, Second Gemspec License"
52
+ end
53
+ end
38
54
  end
39
55
 
40
- it "returns 'other' if the gemspec provides many" do
41
- gemspec.licenses = ['First Gemspec License', 'Second Gemspec License']
56
+ context "when there is nothing in the spec" do
57
+ it "returns a license in a file if there is only one unique license detected" do
58
+ stub_license_files([
59
+ double(:first_file, license: License.find_by_name('MIT')),
60
+ double(:second_file, license: License.find_by_name('Expat'))
61
+ ])
42
62
 
43
- subject.license.should == "other"
44
- end
63
+ subject.license.name.should == "MIT"
64
+ end
45
65
 
46
- it "returns a license in a file if detected" do
47
- stub_license_files [double(:file, license: 'Detected License')]
66
+ it "returns 'other' if there are no licenses in files" do
67
+ stub_license_files []
48
68
 
49
- subject.license.should == "Detected License"
50
- end
69
+ subject.license.name.should == "other"
70
+ end
51
71
 
52
- it "returns 'other' otherwise" do
53
- stub_license_files []
72
+ it "returns 'multiple licenses' if there are many licenses in files" do
73
+ stub_license_files([
74
+ double(:first_file, license: License.find_by_name('First Detected License')),
75
+ double(:second_file, license: License.find_by_name('Second Detected License'))
76
+ ])
54
77
 
55
- subject.license.should == "other"
78
+ subject.license.name.should == "multiple licenses: First Detected License, Second Detected License"
79
+ end
56
80
  end
57
81
  end
58
82
 
@@ -28,13 +28,7 @@ module LicenseFinder
28
28
 
29
29
  describe '.current_packages' do
30
30
  subject do
31
- Bundler.current_packages(config)
32
- end
33
-
34
- let(:config) { double(:config, ignore_groups: ['dev', 'test']) }
35
-
36
- before do
37
- ::Bundler::Definition.stub(:build).and_return(definition)
31
+ Bundler.current_packages(['dev', 'test'], definition)
38
32
  end
39
33
 
40
34
  it "should have 2 dependencies" do
@@ -64,26 +58,20 @@ module LicenseFinder
64
58
  end
65
59
 
66
60
  describe '.active?' do
67
- let(:gemfile) { Pathname.new('Gemfile').expand_path }
61
+ let(:gemfile) { double(:gemfile_file) }
68
62
 
69
- before :each do
70
- allow(File).to receive(:exists?).and_call_original
63
+ before do
64
+ Bundler.stub(gemfile_path: gemfile)
71
65
  end
72
66
 
73
- context 'without a Gemfile' do
74
- it 'returns false' do
75
- allow(File).to receive(:exists?).with(gemfile).and_return(false)
76
-
77
- Bundler.active?.should == false
78
- end
67
+ it 'is true with a Gemfile file' do
68
+ gemfile.stub(:exist? => true)
69
+ expect(Bundler).to be_active
79
70
  end
80
71
 
81
- context 'with a Gemfile' do
82
- it 'returns true' do
83
- allow(File).to receive(:exists?).with(gemfile).and_return(true)
84
-
85
- Bundler.active?.should == true
86
- end
72
+ it 'is false without a Gemfile file' do
73
+ gemfile.stub(:exist? => false)
74
+ expect(Bundler).to_not be_active
87
75
  end
88
76
  end
89
77
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe CocoaPodsPackage do
5
+ subject do
6
+ described_class.new("Name", "1.0.0", license_text)
7
+ end
8
+ let(:license_text) { nil }
9
+
10
+ it_behaves_like "it conforms to interface required by PackageSaver"
11
+
12
+ its(:name) { should == "Name" }
13
+ its(:version) { should == "1.0.0" }
14
+ its(:summary) { should be_nil }
15
+ its(:description) { should be_nil }
16
+ its(:homepage) { should be_nil }
17
+ its(:groups) { should == [] }
18
+ its(:children) { should == [] }
19
+
20
+ describe '#license' do
21
+ context "when there's a license" do
22
+ let(:license_text) { "LicenseText" }
23
+
24
+ it "returns the name of the license if the license is found be text" do
25
+ license = double(:license, name: "LicenseName")
26
+ allow(License).to receive(:find_by_text).with(license_text).and_return(license)
27
+
28
+ expect(subject.license.name).to eq "LicenseName"
29
+ end
30
+
31
+ it "returns other if the license can't be found by text" do
32
+ allow(License).to receive(:find_by_text).with(license_text).and_return(nil)
33
+
34
+ expect(subject.license.name).to eq "other"
35
+ end
36
+ end
37
+
38
+ it "returns other when there's no license" do
39
+ expect(subject.license.name).to eq "other"
40
+ end
41
+ end
42
+ end
43
+ end
44
+