license_finder 0.4.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/README.markdown +43 -11
  2. data/bin/license_finder +2 -5
  3. data/features/executables/license_finder.feature +19 -0
  4. data/features/rake_tasks/action_items.feature +18 -4
  5. data/features/rake_tasks/action_items_ok.feature +10 -7
  6. data/features/rake_tasks/generate_dependencies.feature +43 -12
  7. data/features/rake_tasks/init.feature +8 -1
  8. data/features/rake_tasks/regressions.feature +18 -0
  9. data/features/step_definitions/steps.rb +163 -43
  10. data/lib/license_finder.rb +9 -4
  11. data/lib/license_finder/{gem_spec_details.rb → bundled_gem.rb} +12 -41
  12. data/lib/license_finder/bundler_dependency_query.rb +51 -0
  13. data/lib/license_finder/cli.rb +16 -0
  14. data/lib/license_finder/dependency.rb +80 -28
  15. data/lib/license_finder/dependency_list.rb +20 -35
  16. data/lib/license_finder/finder.rb +2 -2
  17. data/lib/license_finder/license.rb +74 -0
  18. data/lib/license_finder/license/apache.rb +5 -0
  19. data/lib/license_finder/license/bsd.rb +2 -0
  20. data/lib/license_finder/license/gplv2.rb +2 -0
  21. data/lib/license_finder/license/isc.rb +2 -0
  22. data/lib/license_finder/license/lgpl.rb +2 -0
  23. data/lib/license_finder/license/mit.rb +20 -0
  24. data/lib/license_finder/license/new_bsd.rb +5 -0
  25. data/lib/license_finder/license/ruby.rb +11 -0
  26. data/lib/license_finder/license/simplified_bsd.rb +5 -0
  27. data/lib/license_finder/{file_parser.rb → possible_license_file.rb} +9 -17
  28. data/lib/tasks/license_finder.rake +8 -8
  29. data/lib/templates/{Apache-2.0-body → Apache.txt} +0 -0
  30. data/lib/templates/BSD.txt +24 -0
  31. data/lib/templates/{GPL-2.0-body → GPLv2.txt} +0 -0
  32. data/lib/templates/{ISC-body → ISC.txt} +0 -0
  33. data/lib/templates/{LGPL-body → LGPL.txt} +0 -0
  34. data/lib/templates/{MIT-body → MIT.txt} +0 -0
  35. data/lib/templates/NewBSD.txt +21 -0
  36. data/lib/templates/Ruby.txt +52 -0
  37. data/lib/templates/SimplifiedBSD.txt +23 -0
  38. data/license_finder.gemspec +4 -3
  39. data/spec/fixtures/{no_license/.gitkeep → license_names/Licence.rdoc} +0 -0
  40. data/spec/lib/license_finder/bundled_gem_spec.rb +148 -0
  41. data/spec/lib/license_finder/dependency_list_spec.rb +133 -144
  42. data/spec/lib/license_finder/dependency_spec.rb +189 -5
  43. data/spec/lib/license_finder/license/apache_spec.rb +7 -0
  44. data/spec/lib/license_finder/license/bsd_spec.rb +41 -0
  45. data/spec/lib/license_finder/license/gplv2_spec.rb +7 -0
  46. data/spec/lib/license_finder/license/isc_spec.rb +7 -0
  47. data/spec/lib/license_finder/license/lgpl_spec.rb +7 -0
  48. data/spec/lib/license_finder/license/mit_spec.rb +33 -0
  49. data/spec/lib/license_finder/license/new_bsd_spec.rb +35 -0
  50. data/spec/lib/license_finder/license/ruby_spec.rb +19 -0
  51. data/spec/lib/license_finder/license/simplified_bsd_spec.rb +7 -0
  52. data/spec/lib/license_finder/possible_license_file_spec.rb +42 -0
  53. data/spec/spec_helper.rb +6 -0
  54. data/spec/support/license_examples.rb +24 -0
  55. metadata +89 -33
  56. data/lib/license_finder/license_file.rb +0 -98
  57. data/spec/fixtures/apache_licensed_gem/LICENSE +0 -191
  58. data/spec/fixtures/gplv2_licensed_gem/LICENSE +0 -339
  59. data/spec/fixtures/isc_licensed_gem/LICENSE +0 -10
  60. data/spec/fixtures/lgpl_licensed_gem/LICENSE +0 -165
  61. data/spec/fixtures/mit_licensed_gem_in_README/README.rdoc +0 -222
  62. data/spec/fixtures/mit_licensed_gem_via_url/README +0 -210
  63. data/spec/fixtures/mit_licensed_with_hashes/MIT-LICENSE +0 -20
  64. data/spec/lib/license_finder/file_parser_spec.rb +0 -16
  65. data/spec/lib/license_finder/gem_spec_details_spec.rb +0 -229
  66. data/spec/lib/license_finder/license_file_spec.rb +0 -155
@@ -1,42 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe LicenseFinder::DependencyList do
4
+ def build_gemspec(name, version)
5
+ Gem::Specification.new do |s|
6
+ s.name = name
7
+ s.version = version
8
+ s.summary = 'summary'
9
+ s.description = 'description'
10
+ end
11
+ end
12
+
4
13
  before do
5
14
  config = stub(LicenseFinder).config.stub!
6
15
  config.whitelist { [] }
7
16
  config.ignore_groups { [] }
8
-
9
- @mock_gemspec = Class.new do
10
- def initialize(name = nil, version = nil, path = nil)
11
- @name = name
12
- @version = version
13
- @path = path
14
- end
15
-
16
- def name
17
- @name || 'spec_name'
18
- end
19
-
20
- def version
21
- @version || '2.1.3'
22
- end
23
-
24
- def full_gem_path
25
- @path || 'install/path'
26
- end
27
-
28
- def license
29
- nil
30
- end
31
- end
32
17
  end
33
18
 
34
- describe 'from Bundler' do
19
+ describe '.from_bundler' do
35
20
  subject do
36
- mock_bundler = Object.new
37
- stub(Bundler::Definition).build {mock_bundler}
38
- stub(mock_bundler).groups {[]}
39
- stub(mock_bundler).specs_for { [@mock_gemspec.new('gem1', '1.2.3'), @mock_gemspec.new('gem2', '0.4.2')] }
21
+ bundle = stub(Bundler::Definition).build.stub!
22
+ bundle.dependencies { [] }
23
+ bundle.groups { [] }
24
+ bundle.specs_for { [build_gemspec('gem1', '1.2.3'), build_gemspec('gem2', '0.4.2')] }
25
+
40
26
  LicenseFinder::DependencyList.from_bundler
41
27
  end
42
28
 
@@ -44,58 +30,88 @@ describe LicenseFinder::DependencyList do
44
30
  subject.dependencies.size.should == 2
45
31
  end
46
32
 
47
- describe "first" do
48
- let(:dep) { subject.dependencies.first }
49
- it { dep.name.should == 'gem1' }
50
- it { dep.version.should == '1.2.3' }
51
- end
33
+ it 'should maintain the incoming order' do
34
+ subject.dependencies[0].name.should == 'gem1'
35
+ subject.dependencies[0].version.should == '1.2.3'
52
36
 
53
- describe "second" do
54
- let(:dep) { subject.dependencies[1] }
55
- it { dep.name.should == 'gem2' }
56
- it { dep.version.should == '0.4.2' }
37
+ subject.dependencies[1].name.should == 'gem2'
38
+ subject.dependencies[1].version.should == '0.4.2'
57
39
  end
58
-
59
40
  end
60
41
 
61
- describe 'from yaml' do
62
- subject { LicenseFinder::DependencyList.from_yaml("--- \n- name: \"gem1\"\n version: \"1.2.3\"\n license: \"MIT\"\n approved: false\n- name: \"gem2\"\n version: \"0.4.2\"\n license: \"MIT\"\n approved: false\n") }
42
+ describe '#from_yaml' do
43
+ subject do
44
+ LicenseFinder::DependencyList.from_yaml([
45
+ {'name' => 'gem1', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false},
46
+ {'name' => 'gem2', 'version' => '0.4.2', 'license' => 'MIT', 'approved' => false}
47
+ ].to_yaml)
48
+ end
63
49
 
64
- it "should have 2 dependencies" do
50
+ it 'should have 2 dependencies' do
65
51
  subject.dependencies.size.should == 2
66
52
  end
67
53
 
68
- describe "first" do
69
- let(:dep) { subject.dependencies.first }
70
- it { dep.name.should == 'gem1' }
71
- it { dep.version.should == '1.2.3' }
72
- end
54
+ it 'should maintain the incoming order' do
55
+ subject.dependencies[0].name.should == 'gem1'
56
+ subject.dependencies[0].version.should == '1.2.3'
73
57
 
74
- describe "second" do
75
- let(:dep) { subject.dependencies[1] }
76
- it { dep.name.should == 'gem2' }
77
- it { dep.version.should == '0.4.2' }
58
+ subject.dependencies[1].name.should == 'gem2'
59
+ subject.dependencies[1].version.should == '0.4.2'
78
60
  end
61
+ end
79
62
 
63
+ describe '#as_yaml' do
64
+ it "should generate yaml" do
65
+ list = LicenseFinder::DependencyList.new([
66
+ LicenseFinder::Dependency.new('name' => 'b_gem', 'version' => '0.4.2', 'license' => 'MIT', 'approved' => false, 'source' => "bundle"),
67
+ LicenseFinder::Dependency.new('name' => 'a_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false)
68
+ ])
69
+
70
+ list.as_yaml.should == [
71
+ {
72
+ 'name' => 'a_gem',
73
+ 'version' => '1.2.3',
74
+ 'license' => 'MIT',
75
+ 'approved' => false,
76
+ 'source' => nil,
77
+ 'license_url' => '',
78
+ 'notes' => '',
79
+ 'license_files' => nil,
80
+ 'readme_files' => nil
81
+ },
82
+ {
83
+ 'name' => 'b_gem',
84
+ 'version' => '0.4.2',
85
+ 'license' => 'MIT',
86
+ 'approved' => false,
87
+ 'source' => 'bundle',
88
+ 'license_url' => '',
89
+ 'notes' => '',
90
+ 'license_files' => nil,
91
+ 'readme_files' => nil
92
+ }
93
+ ]
94
+ end
80
95
  end
81
96
 
82
- describe 'to_yaml' do
97
+ describe '#to_yaml' do
83
98
  it "should generate yaml" do
84
99
  list = LicenseFinder::DependencyList.new([
85
- LicenseFinder::Dependency.new('name' => 'b_gem', 'version' => '0.4.2', 'license' => 'MIT', 'approved' => false),
86
- LicenseFinder::Dependency.new('name' => 'a_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false)
87
- ])
100
+ LicenseFinder::Dependency.new('name' => 'b_gem', 'version' => '0.4.2', 'license' => 'MIT', 'approved' => false, 'source' => "bundle"),
101
+ LicenseFinder::Dependency.new('name' => 'a_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false)
102
+ ])
88
103
 
89
- list.to_yaml.should == "--- \n- name: \"a_gem\"\n version: \"1.2.3\"\n license: \"MIT\"\n approved: false\n license_url: \"\"\n notes: \"\"\n license_files:\n readme_files:\n- name: \"b_gem\"\n version: \"0.4.2\"\n license: \"MIT\"\n approved: false\n license_url: \"\"\n notes: \"\"\n license_files:\n readme_files:\n"
104
+ yaml = YAML.load(list.to_yaml)
105
+ yaml.should == list.as_yaml
90
106
  end
91
107
  end
92
108
 
93
109
  describe 'round trip' do
94
110
  it 'should recreate from to_yaml' do
95
111
  list = LicenseFinder::DependencyList.new([
96
- LicenseFinder::Dependency.new('name' => 'gem1', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false),
97
- LicenseFinder::Dependency.new('name' => 'gem2', 'version' => '0.4.2', 'license' => 'MIT', 'approved' => false)
98
- ])
112
+ LicenseFinder::Dependency.new('name' => 'gem1', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false),
113
+ LicenseFinder::Dependency.new('name' => 'gem2', 'version' => '0.4.2', 'license' => 'MIT', 'approved' => false)
114
+ ])
99
115
 
100
116
  new_list = LicenseFinder::DependencyList.from_yaml(list.to_yaml)
101
117
  new_list.dependencies.size.should == 2
@@ -104,106 +120,79 @@ describe LicenseFinder::DependencyList do
104
120
  end
105
121
  end
106
122
 
107
- describe 'updating dependency list' do
108
- before(:each) do
109
- @yml_same = LicenseFinder::Dependency.new('name' => 'same_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => true, 'license_url' => 'a', 'notes' => 'b')
110
- @yml_updated = LicenseFinder::Dependency.new('name' => 'updated_gem', 'version' => '1.0.1', 'license' => 'MIT', 'approved' => true, 'license_url' => 'a', 'notes' => 'b')
111
- @yml_new_license = LicenseFinder::Dependency.new('name' => 'new_license_gem', 'version' => '1.0.1', 'license' => 'MIT', 'approved' => true, 'license_url' => 'a', 'notes' => 'b')
112
- @yml_manual_license = LicenseFinder::Dependency.new('name' => 'manual_license_gem', 'version' => '1.0.1', 'license' => 'Ruby', 'approved' => true, 'license_url' => 'a', 'notes' => 'b')
113
- @yml_removed_gem = LicenseFinder::Dependency.new('name' => 'removed_gem', 'version' => '1.0.1', 'license' => 'MIT', 'approved' => true, 'license_url' => 'a', 'notes' => 'b')
114
- @yml_new_whitelist = LicenseFinder::Dependency.new('name' => 'new_whitelist_gem', 'version' => '1.0.1', 'license' => 'MIT', 'approved' => false, 'license_url' => 'a', 'notes' => 'b')
115
-
116
- @gemspec_same = LicenseFinder::Dependency.new('name' => 'same_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => false)
117
- @gemspec_new = LicenseFinder::Dependency.new('name' => 'brand_new_gem', 'version' => '0.9', 'license' => 'MIT', 'approved' => false)
118
- @gemspec_updated = LicenseFinder::Dependency.new('name' => 'updated_gem', 'version' => '1.1.2', 'license' => 'MIT', 'approved' => false)
119
- @gemspec_new_license = LicenseFinder::Dependency.new('name' => 'new_license_gem', 'version' => '2.0.1', 'license' => 'Apache 2.0', 'approved' => false)
120
- @gemspec_new_whitelist = LicenseFinder::Dependency.new('name' => 'new_whitelist_gem', 'version' => '1.0.1', 'license' => 'MIT', 'approved' => true)
121
- @gemspec_manual_license = LicenseFinder::Dependency.new('name' => 'manual_license_gem', 'version' => '1.2.1', 'license' => 'other', 'approved' => false)
122
-
123
- @list_from_yml = LicenseFinder::DependencyList.new([@yml_same, @yml_updated, @yml_new_license, @yml_removed_gem, @yml_new_whitelist, @yml_manual_license])
124
- @list_from_gemspec = LicenseFinder::DependencyList.new([@gemspec_same, @gemspec_new, @gemspec_updated, @gemspec_new_license, @gemspec_new_whitelist, @gemspec_manual_license])
125
- end
126
-
127
- it "should ignore existing gems with the same version" do
128
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'same_gem' }
129
- dep.approved.should == @yml_same.approved
130
- dep.license_url.should == 'a'
131
- dep.notes.should == 'b'
132
- end
133
-
134
- it "should keep old license value if gemspec license is other" do
135
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'manual_license_gem' }
136
- dep.license.should == @yml_manual_license.license
137
- dep.version.should == @gemspec_manual_license.version
138
- dep.approved.should == @yml_manual_license.approved
139
- dep.license_url.should == 'a'
140
- dep.notes.should == 'b'
141
- end
142
-
143
- it "should add new gem" do
144
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'brand_new_gem' }
145
- dep.should_not be_nil
146
- dep.version.should == @gemspec_new.version
147
- dep.approved.should == @gemspec_new.approved
148
- dep.license.should == @gemspec_new.license
149
- dep.license_url.should == ''
150
- dep.notes.should == ''
151
- end
152
-
153
- it "should update version if gem exists and license is the same" do
154
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'updated_gem' }
155
- dep.name.should == @gemspec_updated.name
156
- dep.approved.should == @yml_updated.approved
157
- dep.license_url.should == 'a'
158
- dep.notes.should == 'b'
159
- end
160
-
161
- it "should replace gem if version and license are different" do
162
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'new_license_gem' }
163
- dep.name.should == @gemspec_new_license.name
164
- dep.version.should == @gemspec_new_license.version
165
- dep.approved.should == @gemspec_new_license.approved
166
- dep.license_url.should == ''
167
- dep.notes.should == ''
168
- end
169
-
170
- it "should update approved if gemspec gem is approved" do
171
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'new_whitelist_gem' }
172
- dep.name.should == @gemspec_new_whitelist.name
173
- dep.version.should == @gemspec_new_whitelist.version
174
- dep.approved.should == @gemspec_new_whitelist.approved
175
- dep.license_url.should == 'a'
176
- dep.notes.should == 'b'
177
- end
178
-
179
- it "should remove gem if new list doesn't contain it" do
180
- dep = @list_from_yml.merge(@list_from_gemspec).dependencies.detect { |d| d.name == 'removed_gem' }
181
- dep.should be_nil
123
+ describe '#merge' do
124
+ let(:old_dep) do
125
+ LicenseFinder::Dependency.new(
126
+ 'name' => 'foo',
127
+ 'version' => '0.0.1',
128
+ 'source' => 'bundle'
129
+ )
130
+ end
131
+ let(:old_list) { LicenseFinder::DependencyList.new([old_dep]) }
132
+
133
+ let(:new_dep) do
134
+ LicenseFinder::Dependency.new(
135
+ 'name' => 'foo',
136
+ 'version' => '0.0.2',
137
+ 'source' => 'bundle'
138
+ )
139
+ end
140
+ let(:new_list) { LicenseFinder::DependencyList.new([new_dep]) }
141
+
142
+ it 'should merge dependencies with the same name' do
143
+ merged_list = old_list.merge(new_list)
144
+
145
+ merged_deps = merged_list.dependencies.select { |d| d.name == 'foo' }
146
+ merged_deps.should have(1).item
147
+
148
+ merged_dep = merged_deps.first
149
+ merged_dep.name.should == 'foo'
150
+ merged_dep.version.should == '0.0.2'
151
+ end
152
+
153
+ it 'should add new dependencies' do
154
+ new_dep.name = 'bar'
155
+
156
+ merged_list = old_list.merge(new_list)
157
+ merged_list.dependencies.should include(new_dep)
158
+ end
159
+
160
+ it 'should keep dependencies not originating from the bundle' do
161
+ old_dep.source = ''
162
+
163
+ merged_list = old_list.merge(new_list)
164
+ merged_list.dependencies.should include(old_dep)
165
+ end
166
+
167
+ it 'should remove dependencies missing from the bundle' do
168
+ old_dep.source = 'bundle'
169
+
170
+ merged_list = old_list.merge(new_list)
171
+ merged_list.dependencies.should_not include(old_dep)
182
172
  end
183
173
  end
184
174
 
185
175
  describe "#to_s" do
186
176
  it "should return a human readable list of dependencies" do
187
- gem1 = LicenseFinder::Dependency.new('name' => 'b_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => true)
188
- gem2 = LicenseFinder::Dependency.new('name' => 'a_gem', 'version' => '0.9', 'license' => 'other', 'approved' => false, 'license_url' => 'http://foo.com/LICENSE')
189
177
 
190
- list = LicenseFinder::DependencyList.new([gem1, gem2])
178
+ gem1 = Struct.new(:name, :to_s).new("a", "a string ")
179
+ gem2 = Struct.new(:name, :to_s).new("b", "b string")
180
+
181
+ list = LicenseFinder::DependencyList.new([gem2, gem1])
191
182
 
192
- list.to_s.should == "a_gem 0.9, other, http://foo.com/LICENSE\n license files:\n readme files:\nb_gem 1.2.3, MIT"
183
+ list.to_s.should == "a string b string"
193
184
  end
194
185
  end
195
186
 
196
187
  describe '#action_items' do
197
188
  it "should return all unapproved dependencies" do
198
- gem1 = LicenseFinder::Dependency.new('name' => 'b_gem', 'version' => '1.2.3', 'license' => 'MIT', 'approved' => true)
199
- gem2 = LicenseFinder::Dependency.new('name' => 'a_gem', 'version' => '0.9', 'license' => 'other', 'approved' => false)
200
- gem3 = LicenseFinder::Dependency.new('name' => 'c_gem', 'version' => '0.2', 'license' => 'other', 'approved' => false)
189
+ gem1 = Struct.new(:name, :to_s, :approved).new("a", "a string ", true)
190
+ gem2 = Struct.new(:name, :to_s, :approved).new("b", "b string ", false)
191
+ gem3 = Struct.new(:name, :to_s, :approved).new("c", "c string", false)
201
192
 
202
193
  list = LicenseFinder::DependencyList.new([gem1, gem2, gem3])
203
194
 
204
- list.action_items.should == "a_gem 0.9, other\n license files:\n readme files:\nc_gem 0.2, other\n license files:\n readme files:"
195
+ list.action_items.should == "b string c string"
205
196
  end
206
197
  end
207
198
  end
208
-
209
-
@@ -10,7 +10,9 @@ describe LicenseFinder::Dependency do
10
10
  'license_url' => 'http://www.apache.org/licenses/LICENSE-2.0.html',
11
11
  'notes' => 'some notes',
12
12
  'license_files' => [{'path' => '/Users/pivotal/foo/lic1'}, {'path' => '/Users/pivotal/bar/lic2'}],
13
- 'readme_files' => [{'path' => '/Users/pivotal/foo/Readme1'}, {'path' => '/Users/pivotal/bar/Readme2'}]
13
+ 'readme_files' => [{'path' => '/Users/pivotal/foo/Readme1'}, {'path' => '/Users/pivotal/bar/Readme2'}],
14
+ 'source' => "bundle",
15
+ 'bundler_groups' => nil
14
16
  }
15
17
  end
16
18
 
@@ -35,6 +37,7 @@ describe LicenseFinder::Dependency do
35
37
  end
36
38
  end
37
39
 
40
+
38
41
  describe '.from_hash' do
39
42
  subject { LicenseFinder::Dependency.from_hash(attributes) }
40
43
 
@@ -44,10 +47,191 @@ describe LicenseFinder::Dependency do
44
47
  its(:approved) { should == false }
45
48
  its(:license_url) { should == "http://www.apache.org/licenses/LICENSE-2.0.html" }
46
49
  its(:notes) { should == "some notes" }
47
- its(:license_files) { should == ["/Users/pivotal/foo/lic1", "/Users/pivotal/bar/lic2"] }
48
- its(:readme_files) { should == ["/Users/pivotal/foo/Readme1", "/Users/pivotal/bar/Readme2"] }
49
- its(:to_yaml_entry) { should == "- name: \"spec_name\"\n version: \"2.1.3\"\n license: \"GPL\"\n approved: false\n license_url: \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n notes: \"some notes\"\n license_files:\n - path: \"/Users/pivotal/foo/lic1\"\n - path: \"/Users/pivotal/bar/lic2\"\n readme_files:\n - path: \"/Users/pivotal/foo/Readme1\"\n - path: \"/Users/pivotal/bar/Readme2\"\n" }
50
+ its(:license_files) { should == %w(/Users/pivotal/foo/lic1 /Users/pivotal/bar/lic2) }
51
+ its(:readme_files) { should == %w(/Users/pivotal/foo/Readme1 /Users/pivotal/bar/Readme2) }
52
+ its(:source) { should == "bundle" }
53
+ its(:bundler_groups) { should == [] }
54
+
55
+ its(:as_yaml) do
56
+ should == {
57
+ 'name' => 'spec_name',
58
+ 'version' => '2.1.3',
59
+ 'license' => 'GPL',
60
+ 'approved' => false,
61
+ 'source' => 'bundle',
62
+ 'license_url' => 'http://www.apache.org/licenses/LICENSE-2.0.html',
63
+ 'notes' => 'some notes',
64
+ 'license_files' => [
65
+ {'path' => '/Users/pivotal/foo/lic1'},
66
+ {'path' => '/Users/pivotal/bar/lic2'}
67
+ ],
68
+ 'readme_files' => [
69
+ {'path' => '/Users/pivotal/foo/Readme1'},
70
+ {'path' => '/Users/pivotal/bar/Readme2'}
71
+ ]
72
+ }
73
+ end
74
+
75
+ it 'should generate yaml' do
76
+ yaml = YAML.load(subject.to_yaml)
77
+ yaml.should == subject.as_yaml
78
+ end
50
79
  end
51
- end
52
80
 
81
+ describe '#to_s' do
82
+ let(:gem) do
83
+ LicenseFinder::Dependency.new(
84
+ 'name' => 'test_gem',
85
+ 'version' => '1.0',
86
+ 'summary' => 'summary foo',
87
+ 'description' => 'description bar',
88
+ 'license' => license,
89
+ 'license_url' => license_url,
90
+ 'license_files' => license_files,
91
+ 'readme_files' => readme_files,
92
+ 'bundler_groups' => bundler_groups
93
+ )
94
+ end
95
+ let(:bundler_groups) { [] }
96
+ let(:license_files) { [] }
97
+ let(:readme_files) { [] }
98
+ let(:license_url) { "" }
99
+ let(:license) { "MIT" }
100
+
101
+ subject { gem.to_s.strip }
102
+
103
+ it 'should generate text with all the gem attributes' do
104
+ should == "test_gem 1.0, MIT, summary foo, description bar"
105
+ end
106
+
107
+ context "when license is 'other'" do
108
+ context "when the gem includes license files and readme files" do
109
+ let(:license_files) { %w(somefile) }
110
+ let(:readme_files) { %w(somereadme) }
111
+ let(:license) { 'other' }
112
+
113
+ it "should generate text with the gem attributes, license files, and readme files" do
114
+ should == <<-STRING.strip
115
+ test_gem 1.0, other, summary foo, description bar
116
+ license files:
117
+ somefile
118
+ readme files:
119
+ somereadme
120
+ STRING
121
+ end
122
+ end
123
+ end
124
+
125
+ context "when the gem has a license url" do
126
+ let(:license_url) { "www.foobar.com"}
127
+
128
+ it "should include the license_url" do
129
+ should == "test_gem 1.0, MIT, www.foobar.com, summary foo, description bar"
130
+ end
131
+ end
132
+
133
+ context "when the gem has any bundler groups" do
134
+ let(:bundler_groups) { %w(staging production) }
135
+
136
+ it "should include the bundler groups" do
137
+ should == "test_gem 1.0, MIT, summary foo, description bar, staging, production"
138
+ end
139
+ end
140
+ end
141
+
142
+ describe '#source' do
143
+ it "should default to nil" do
144
+ LicenseFinder::Dependency.new.source.should be_nil
145
+ end
146
+
147
+ it "should be overridable" do
148
+ LicenseFinder::Dependency.new("source" => "foo").source.should == "foo"
149
+ end
150
+ end
151
+
152
+ describe '#merge' do
153
+ subject do
154
+ LicenseFinder::Dependency.new(
155
+ 'name' => 'foo',
156
+ 'license' => 'MIT',
157
+ 'version' => '0.0.1',
158
+ 'license_url' => 'http://www.example.com/license1.htm',
159
+ 'license_files' => "old license files",
160
+ 'readme_files' => "old readme files",
161
+ )
162
+ end
163
+
164
+ let(:new_dep) do
165
+ LicenseFinder::Dependency.new(
166
+ 'name' => 'foo',
167
+ 'license' => 'MIT',
168
+ 'version' => '0.0.2',
169
+ 'license_url' => 'http://www.example.com/license2.htm',
170
+ 'license_files' => "new license files",
171
+ 'readme_files' => "new readme files",
172
+ 'summary' => 'foo summary',
173
+ 'description' => 'awesome foo description!',
174
+ 'bundler_groups' => [1,2,3]
175
+ )
176
+ end
177
+
178
+ it 'should raise an error if the names do not match' do
179
+ new_dep.name = 'bar'
180
+
181
+ expect {
182
+ subject.merge(new_dep)
183
+ }.to raise_error
184
+ end
185
+
186
+ it 'should return the new version, license url, license files, readme files, and source' do
187
+ merged = subject.merge(new_dep)
188
+
189
+ merged.version.should == '0.0.2'
190
+ merged.license_url.should == 'http://www.example.com/license2.htm'
191
+ merged.license_files.should == new_dep.license_files
192
+ merged.readme_files.should == new_dep.readme_files
193
+ merged.source.should == new_dep.source
194
+ end
195
+
196
+ it 'should return the new summary and description and bundle groups' do
197
+ merged = subject.merge new_dep
198
+
199
+ merged.summary.should == new_dep.summary
200
+ merged.description.should == new_dep.description
201
+ merged.bundler_groups.should == new_dep.bundler_groups
202
+ end
203
+
204
+ it 'should return the old notes' do
205
+ subject.notes = 'old notes'
206
+ new_dep.notes = 'new notes'
207
+
208
+ merged = subject.merge(new_dep)
53
209
 
210
+ merged.notes.should == 'old notes'
211
+ end
212
+
213
+ it 'should return the new license and approval if the license is different' do
214
+ subject.license = "MIT"
215
+ subject.approved = true
216
+
217
+ new_dep.license = "GPLv2"
218
+ new_dep.approved = false
219
+
220
+ merged = subject.merge(new_dep)
221
+
222
+ merged.license.should == "GPLv2"
223
+ merged.approved.should == false
224
+ end
225
+
226
+ it 'should return the old license and approval if the new license is the same or "other"' do
227
+ subject.approved = false
228
+ new_dep.approved = true
229
+
230
+ subject.merge(new_dep).approved.should == false
231
+
232
+ new_dep.license = 'other'
233
+
234
+ subject.merge(new_dep).approved.should == false
235
+ end
236
+ end
237
+ end