halite 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +15 -0
  5. data/LICENSE +202 -0
  6. data/README.md +75 -0
  7. data/Rakefile +22 -0
  8. data/halite.gemspec +33 -0
  9. data/lib/berkshelf/halite.rb +2 -0
  10. data/lib/halite.rb +12 -0
  11. data/lib/halite/berkshelf/helper.rb +69 -0
  12. data/lib/halite/berkshelf/source.rb +56 -0
  13. data/lib/halite/converter.rb +17 -0
  14. data/lib/halite/converter/libraries.rb +40 -0
  15. data/lib/halite/converter/metadata.rb +21 -0
  16. data/lib/halite/converter/other.rb +19 -0
  17. data/lib/halite/converter/readme.rb +20 -0
  18. data/lib/halite/dependencies.rb +72 -0
  19. data/lib/halite/error.rb +4 -0
  20. data/lib/halite/gem.rb +82 -0
  21. data/lib/halite/rake_helper.rb +151 -0
  22. data/lib/halite/rake_tasks.rb +2 -0
  23. data/lib/halite/spec_helper.rb +134 -0
  24. data/lib/halite/spec_helper/empty/README.md +1 -0
  25. data/lib/halite/spec_helper/runner.rb +43 -0
  26. data/lib/halite/version.rb +3 -0
  27. data/spec/converter/libraries_spec.rb +152 -0
  28. data/spec/converter/metadata_spec.rb +60 -0
  29. data/spec/converter/other_spec.rb +56 -0
  30. data/spec/converter/readme_spec.rb +55 -0
  31. data/spec/converter_spec.rb +14 -0
  32. data/spec/data/gems/test1/Rakefile +1 -0
  33. data/spec/data/gems/test1/lib/test1.rb +2 -0
  34. data/spec/data/gems/test1/lib/test1/version.rb +3 -0
  35. data/spec/data/gems/test1/test1.gemspec +25 -0
  36. data/spec/data/gems/test2/Rakefile +1 -0
  37. data/spec/data/gems/test2/chef/attributes.rb +0 -0
  38. data/spec/data/gems/test2/chef/recipes/default.rb +0 -0
  39. data/spec/data/gems/test2/chef/templates/default/conf.erb +0 -0
  40. data/spec/data/gems/test2/lib/test2.rb +4 -0
  41. data/spec/data/gems/test2/lib/test2/resource.rb +6 -0
  42. data/spec/data/gems/test2/lib/test2/version.rb +3 -0
  43. data/spec/data/gems/test2/test2.gemspec +24 -0
  44. data/spec/data/gems/test3/Rakefile +1 -0
  45. data/spec/data/gems/test3/chef/recipes/default.rb +1 -0
  46. data/spec/data/gems/test3/lib/test3.rb +4 -0
  47. data/spec/data/gems/test3/lib/test3/dsl.rb +15 -0
  48. data/spec/data/gems/test3/lib/test3/version.rb +3 -0
  49. data/spec/data/gems/test3/test3.gemspec +24 -0
  50. data/spec/data/integration_cookbooks/test1/libraries/test1.rb +3 -0
  51. data/spec/data/integration_cookbooks/test1/libraries/test1__version.rb +4 -0
  52. data/spec/data/integration_cookbooks/test1/metadata.rb +4 -0
  53. data/spec/data/integration_cookbooks/test2/attributes.rb +0 -0
  54. data/spec/data/integration_cookbooks/test2/libraries/test2.rb +5 -0
  55. data/spec/data/integration_cookbooks/test2/libraries/test2__resource.rb +7 -0
  56. data/spec/data/integration_cookbooks/test2/libraries/test2__version.rb +4 -0
  57. data/spec/data/integration_cookbooks/test2/metadata.rb +4 -0
  58. data/spec/data/integration_cookbooks/test2/recipes/default.rb +0 -0
  59. data/spec/data/integration_cookbooks/test2/templates/default/conf.erb +0 -0
  60. data/spec/data/integration_cookbooks/test3/libraries/test3.rb +5 -0
  61. data/spec/data/integration_cookbooks/test3/libraries/test3__dsl.rb +16 -0
  62. data/spec/data/integration_cookbooks/test3/libraries/test3__version.rb +4 -0
  63. data/spec/data/integration_cookbooks/test3/metadata.rb +4 -0
  64. data/spec/data/integration_cookbooks/test3/recipes/default.rb +1 -0
  65. data/spec/dependencies_spec.rb +167 -0
  66. data/spec/gem_spec.rb +164 -0
  67. data/spec/integration_spec.rb +104 -0
  68. data/spec/spec_helper.rb +28 -0
  69. metadata +307 -0
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'halite/converter/readme'
3
+
4
+ describe Halite::Converter::Readme do
5
+
6
+ describe '#write' do
7
+ let(:spec) { double(full_gem_path: '/source') }
8
+ let(:readme_file) { }
9
+ let(:input) { [] }
10
+ let(:output) { [] }
11
+ before do
12
+ allow(File).to receive(:exists?).and_return(false)
13
+ Array(readme_file).each do |path|
14
+ input_sentinel = double("content of #{path}")
15
+ output_sentinel = double("generated output for #{path}")
16
+ allow(File).to receive(:exists?).with(File.join('/source', path)).and_return(true)
17
+ allow(File).to receive(:open).with(File.join('/source', path), 'rb').and_yield(input_sentinel)
18
+ input << input_sentinel
19
+ output << output_sentinel
20
+ end
21
+ end
22
+
23
+ context 'with a README.md' do
24
+ let(:readme_file) { 'README.md' }
25
+
26
+ it 'writes out a README.md' do
27
+ expect(File).to receive(:open).with('/test/README.md', 'wb').and_yield(output[0])
28
+ expect(IO).to receive(:copy_stream).with(input[0], output[0])
29
+ described_class.write(spec, '/test')
30
+ end
31
+ end # /context with a README.md
32
+
33
+ context 'with a README' do
34
+ let(:readme_file) { 'README' }
35
+
36
+ it 'writes out a README' do
37
+ expect(File).to receive(:open).with('/test/README', 'wb').and_yield(output[0])
38
+ expect(IO).to receive(:copy_stream).with(input[0], output[0])
39
+ described_class.write(spec, '/test')
40
+ end
41
+ end # /context with a README
42
+
43
+ context 'with multiple files' do
44
+ let(:readme_file) { %w{README.txt readme.md} }
45
+
46
+ it 'writes out a README' do
47
+ expect(File).to receive(:open).with('/test/README.txt', 'wb').and_yield(output[0])
48
+ expect(IO).to receive(:copy_stream).with(input[0], output[0])
49
+ described_class.write(spec, '/test')
50
+ end
51
+ end # /context with multiple files
52
+
53
+ end # /describe #write
54
+
55
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'halite/converter'
3
+
4
+ describe Halite::Converter do
5
+ describe '#write' do
6
+ it 'should call all submodules' do
7
+ expect(Halite::Converter::Metadata).to receive(:write).ordered
8
+ expect(Halite::Converter::Libraries).to receive(:write).ordered
9
+ expect(Halite::Converter::Other).to receive(:write).ordered
10
+ expect(Halite::Converter::Readme).to receive(:write).ordered
11
+ described_class.write(nil, '/test')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ require 'halite/rake_tasks'
@@ -0,0 +1,2 @@
1
+ module Test1
2
+ end
@@ -0,0 +1,3 @@
1
+ module Test1
2
+ VERSION = '1.2.3'
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ # Awesome license
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'test1/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'test1'
9
+ spec.version = Test1::VERSION
10
+ spec.authors = ['Noah Kantrowitz']
11
+ spec.email = %w{noah@coderanger.net}
12
+ spec.description = %q||
13
+ spec.summary = %q||
14
+ spec.homepage = ''
15
+ spec.license = 'Apache 2.0'
16
+
17
+ spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = %w{lib}
21
+
22
+ spec.add_dependency 'halite'
23
+
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1 @@
1
+ require 'halite/rake_tasks'
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ require 'test2/resource'
2
+
3
+ module Test2
4
+ end
@@ -0,0 +1,6 @@
1
+ require 'chef/resource'
2
+
3
+ module Test2
4
+ class Resource < Chef::Resource
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Test2
2
+ VERSION = '4.5.6'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'test2'
8
+ spec.version = Test2::VERSION
9
+ spec.authors = ['Noah Kantrowitz']
10
+ spec.email = %w{noah@coderanger.net}
11
+ spec.description = %q||
12
+ spec.summary = %q||
13
+ spec.homepage = ''
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w{lib}
20
+
21
+ spec.add_dependency 'halite'
22
+ spec.add_development_dependency 'rake'
23
+ spec.requirements = %w{testdep}
24
+ end
@@ -0,0 +1 @@
1
+ require 'halite/rake_tasks'
@@ -0,0 +1 @@
1
+ log test3_method
@@ -0,0 +1,4 @@
1
+ require 'test3/dsl'
2
+
3
+ module Test3
4
+ end
@@ -0,0 +1,15 @@
1
+ require 'test2/version'
2
+
3
+ module Test3
4
+ module DSL
5
+ def test3_method
6
+ "!!!!!!!!!!test3#{Test2::VERSION}"
7
+ end
8
+ end
9
+ end
10
+
11
+ class Chef
12
+ class Recipe
13
+ include Test3::DSL
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Test3
2
+ VERSION = '7.8.9'
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test3/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'test3'
8
+ spec.version = Test3::VERSION
9
+ spec.authors = ['Noah Kantrowitz']
10
+ spec.email = %w{noah@coderanger.net}
11
+ spec.description = %q||
12
+ spec.summary = %q||
13
+ spec.homepage = ''
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w{lib}
20
+
21
+ spec.add_dependency 'halite'
22
+ spec.add_dependency 'test2', '~> 4.5.6'
23
+ spec.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,3 @@
1
+ ENV['HALITE_LOAD'] = '1'; begin; module Test1
2
+ end
3
+ ensure; ENV.delete('HALITE_LOAD'); end
@@ -0,0 +1,4 @@
1
+ if ENV['HALITE_LOAD']; module Test1
2
+ VERSION = '1.2.3'
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ # Awesome license
3
+ name "test1"
4
+ version "1.2.3"
@@ -0,0 +1,5 @@
1
+ ENV['HALITE_LOAD'] = '1'; begin; require_relative 'test2__resource'
2
+
3
+ module Test2
4
+ end
5
+ ensure; ENV.delete('HALITE_LOAD'); end
@@ -0,0 +1,7 @@
1
+ if ENV['HALITE_LOAD']; require 'chef/resource'
2
+
3
+ module Test2
4
+ class Resource < Chef::Resource
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ if ENV['HALITE_LOAD']; module Test2
2
+ VERSION = '4.5.6'
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ name "test2"
3
+ version "4.5.6"
4
+ depends "testdep", ">= 0.0"
@@ -0,0 +1,5 @@
1
+ ENV['HALITE_LOAD'] = '1'; begin; require_relative 'test3__dsl'
2
+
3
+ module Test3
4
+ end
5
+ ensure; ENV.delete('HALITE_LOAD'); end
@@ -0,0 +1,16 @@
1
+ if ENV['HALITE_LOAD']; require_relative '../../test2/libraries/test2__version'
2
+
3
+ module Test3
4
+ module DSL
5
+ def test3_method
6
+ "!!!!!!!!!!test3#{Test2::VERSION}"
7
+ end
8
+ end
9
+ end
10
+
11
+ class Chef
12
+ class Recipe
13
+ include Test3::DSL
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ if ENV['HALITE_LOAD']; module Test3
2
+ VERSION = '7.8.9'
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ name "test3"
3
+ version "7.8.9"
4
+ depends "test2", "~> 4.5.6"
@@ -0,0 +1 @@
1
+ log test3_method
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+ require 'halite/dependencies'
3
+
4
+ describe Halite::Dependencies do
5
+ before do
6
+ allow(Gem::Specification).to receive(:stubs).and_return([
7
+ Gem::Specification.new {|s| s.name = 'gem1'; s.version = Gem::Version.new('1.0.0') },
8
+ Gem::Specification.new {|s| s.name = 'gem2'; s.version = Gem::Version.new('1.0.0'); s.requirements << 'dep2' },
9
+ ])
10
+ end
11
+
12
+ describe '#extract_from_requirements' do
13
+ let(:requirements) { [] }
14
+ subject { described_class.extract_from_requirements(Gem::Specification.new {|s| s.name = 'name'; s.version = Gem::Version.new('1.0.0'); s.requirements += requirements }) }
15
+
16
+ context 'with []' do
17
+ it { is_expected.to eq [] }
18
+ end
19
+
20
+ context 'with [req1]' do
21
+ let(:requirements) { ['req1'] }
22
+ it { is_expected.to eq ['req1'] }
23
+ end
24
+
25
+ context 'with [req1, req2]' do
26
+ let(:requirements) { ['req1', 'req2'] }
27
+ it { is_expected.to eq ['req1', 'req2'] }
28
+ end
29
+ end # /describe #extract_from_requirements
30
+
31
+
32
+ describe '#extract_from_metadata' do
33
+ let(:metadata) { nil }
34
+ subject { described_class.extract_from_metadata(Gem::Specification.new {|s| s.name = 'name'; s.version = Gem::Version.new('1.0.0'); s.metadata = {'halite_dependencies' => metadata} if metadata}) }
35
+
36
+ context 'with no metadata' do
37
+ it { is_expected.to eq [] }
38
+ end
39
+
40
+ context 'with req1' do
41
+ let(:metadata) { 'req1' }
42
+ it { is_expected.to eq ['req1'] }
43
+ end
44
+
45
+ context 'with req1,req2' do
46
+ let(:metadata) { 'req1,req2' }
47
+ it { is_expected.to eq ['req1', 'req2'] }
48
+ end
49
+ end # /describe #extract_from_metadata
50
+
51
+ describe '#clean' do
52
+ let(:dependency) { nil }
53
+ subject { described_class.clean(dependency) }
54
+ before { allow(described_class).to receive(:clean_requirement) {|arg| arg.to_s } }
55
+
56
+ context 'with name' do
57
+ let(:dependency) { 'name' }
58
+ it { is_expected.to eq ['name', '>= 0'] }
59
+ end
60
+
61
+ context 'with name 1.0.0' do
62
+ let(:dependency) { 'name 1.0.0' }
63
+ it { is_expected.to eq ['name', '1.0.0'] }
64
+ end
65
+
66
+ context 'with name = 1.0.0' do
67
+ let(:dependency) { 'name = 1.0.0' }
68
+ it { is_expected.to eq ['name', '= 1.0.0'] }
69
+ end
70
+
71
+ context 'with [name]' do
72
+ let(:dependency) { ['name'] }
73
+ it { is_expected.to eq ['name', '>= 0'] }
74
+ end
75
+
76
+ context 'with [name, = 1.0.0]' do
77
+ let(:dependency) { ['name', '= 1.0.0'] }
78
+ it { is_expected.to eq ['name', '= 1.0.0'] }
79
+ end
80
+
81
+ context 'with [name, = 1.0.0, = 1.0.0]' do
82
+ let(:dependency) { ['name', '= 1.0.0', '= 1.0.0'] }
83
+ it { expect { subject }.to raise_error Halite::Dependencies::InvalidDependencyError }
84
+ end
85
+ end # /describe #clean
86
+
87
+ describe '#clean_requirement' do
88
+ let(:requirement) { nil }
89
+ subject { described_class.clean_requirement(requirement) }
90
+ before { allow(described_class).to receive(:clean_version) {|arg| arg } }
91
+
92
+ context 'with = 1.0.0' do
93
+ let(:requirement) { '= 1.0.0' }
94
+ it { is_expected.to eq '= 1.0.0' }
95
+ end
96
+
97
+ context 'with 1.0.0' do
98
+ let(:requirement) { '1.0.0' }
99
+ it { is_expected.to eq '= 1.0.0' }
100
+ end
101
+
102
+ context 'with = 1.0.0' do
103
+ let(:requirement) { '= 1.0.0' }
104
+ it { is_expected.to eq '= 1.0.0' }
105
+ end
106
+
107
+ context 'with =1.0.0' do
108
+ let(:requirement) { '=1.0.0' }
109
+ it { is_expected.to eq '= 1.0.0' }
110
+ end
111
+
112
+ context 'with ~> 1.0.0' do
113
+ let(:requirement) { '~> 1.0.0' }
114
+ it { is_expected.to eq '~> 1.0.0' }
115
+ end
116
+
117
+ context 'with >= 1.0.0' do
118
+ let(:requirement) { '>= 1.0.0' }
119
+ it { is_expected.to eq '>= 1.0.0' }
120
+ end
121
+
122
+ context 'with <= 1.0.0' do
123
+ let(:requirement) { '<= 1.0.0' }
124
+ it { is_expected.to eq '<= 1.0.0' }
125
+ end
126
+ end # /describe #clean_requirement
127
+
128
+ describe '#clean_version' do
129
+ let(:version) { nil }
130
+ subject { described_class.clean_version(::Gem::Version.new(version)).to_s }
131
+
132
+ context 'with 1.0.0' do
133
+ let(:version) { '1.0.0' }
134
+ it { is_expected.to eq '1.0.0' }
135
+ end
136
+
137
+ context 'with 1.0' do
138
+ let(:version) { '1.0' }
139
+ it { is_expected.to eq '1.0' }
140
+ end
141
+
142
+ context 'with 1' do
143
+ let(:version) { '1' }
144
+ it { is_expected.to eq '1.0' }
145
+ end
146
+
147
+ context 'with 0' do
148
+ let(:version) { '0' }
149
+ it { is_expected.to eq '0.0' }
150
+ end
151
+
152
+ context 'with 1.0.a' do
153
+ let(:version) { '1.0.a' }
154
+ it { expect { subject }.to raise_error Halite::Dependencies::InvalidDependencyError }
155
+ end
156
+
157
+ context 'with 1.2.3.4' do
158
+ let(:version) { '1.2.3.4' }
159
+ it { expect { subject }.to raise_error Halite::Dependencies::InvalidDependencyError }
160
+ end
161
+
162
+ context 'with 1.2.3' do
163
+ let(:version) { '1.2.3' }
164
+ it { is_expected.to eq '1.2.3' }
165
+ end
166
+ end # /describe #clean_version
167
+ end