halite 1.0.0.rc.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +20 -0
  4. data/.travis.yml +14 -4
  5. data/.yardopts +7 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +30 -8
  8. data/LICENSE +202 -202
  9. data/README.md +104 -2
  10. data/Rakefile +25 -5
  11. data/gemfiles/default.gemfile +17 -0
  12. data/gemfiles/master.gemfile +21 -0
  13. data/halite.gemspec +21 -10
  14. data/lib/berkshelf/halite.rb +25 -0
  15. data/lib/berkshelf/locations/gem.rb +84 -0
  16. data/lib/halite.rb +34 -4
  17. data/lib/halite/berkshelf/helper.rb +8 -2
  18. data/lib/halite/berkshelf/source.rb +9 -1
  19. data/lib/halite/converter.rb +34 -10
  20. data/lib/halite/converter/chef.rb +43 -0
  21. data/lib/halite/converter/libraries.rb +93 -26
  22. data/lib/halite/converter/metadata.rb +48 -10
  23. data/lib/halite/converter/misc.rb +43 -0
  24. data/lib/halite/dependencies.rb +48 -8
  25. data/lib/halite/error.rb +20 -0
  26. data/lib/halite/gem.rb +106 -21
  27. data/lib/halite/helper_base.rb +129 -0
  28. data/lib/halite/rake_helper.rb +46 -60
  29. data/lib/halite/rake_tasks.rb +17 -1
  30. data/lib/halite/spec_helper.rb +403 -54
  31. data/lib/halite/spec_helper/patcher.rb +130 -0
  32. data/lib/halite/spec_helper/runner.rb +57 -9
  33. data/lib/halite/version.rb +19 -1
  34. data/spec/converter/chef_spec.rb +54 -0
  35. data/spec/converter/libraries_spec.rb +131 -123
  36. data/spec/converter/metadata_spec.rb +61 -8
  37. data/spec/converter/misc_spec.rb +61 -0
  38. data/spec/converter_spec.rb +21 -6
  39. data/spec/dependencies_spec.rb +64 -10
  40. data/spec/example_resources/poise.rb +42 -0
  41. data/spec/example_resources/simple.rb +48 -0
  42. data/spec/{data/gems/test1/lib → fixtures/cookbooks/test1/files/halite_gem}/test1.rb +0 -0
  43. data/spec/{data/gems/test1/lib → fixtures/cookbooks/test1/files/halite_gem}/test1/version.rb +0 -0
  44. data/spec/fixtures/cookbooks/test1/libraries/default.rb +4 -0
  45. data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test1/metadata.rb +0 -0
  46. data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/attributes.rb +0 -0
  47. data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2.rb +0 -0
  48. data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2/resource.rb +0 -0
  49. data/spec/{data/gems/test2/lib → fixtures/cookbooks/test2/files/halite_gem}/test2/version.rb +0 -0
  50. data/spec/fixtures/cookbooks/test2/libraries/default.rb +3 -0
  51. data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test2/metadata.rb +1 -1
  52. data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/recipes/default.rb +0 -0
  53. data/spec/{data/gems/test2/chef → fixtures/cookbooks/test2}/templates/default/conf.erb +0 -0
  54. data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3.rb +0 -0
  55. data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3/dsl.rb +0 -0
  56. data/spec/{data/gems/test3/lib → fixtures/cookbooks/test3/files/halite_gem}/test3/version.rb +0 -0
  57. data/spec/fixtures/cookbooks/test3/libraries/default.rb +4 -0
  58. data/spec/{data/integration_cookbooks → fixtures/cookbooks}/test3/metadata.rb +0 -0
  59. data/spec/{data/gems/test3/chef → fixtures/cookbooks/test3}/recipes/default.rb +0 -0
  60. data/spec/{data → fixtures}/gems/test1/Rakefile +0 -0
  61. data/spec/fixtures/gems/test1/lib/test1.rb +2 -0
  62. data/spec/fixtures/gems/test1/lib/test1/version.rb +3 -0
  63. data/spec/{data → fixtures}/gems/test1/test1.gemspec +0 -0
  64. data/spec/{data → fixtures}/gems/test2/Rakefile +0 -0
  65. data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/attributes.rb +0 -0
  66. data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/recipes/default.rb +0 -0
  67. data/spec/{data/integration_cookbooks/test2 → fixtures/gems/test2/chef}/templates/default/conf.erb +0 -0
  68. data/spec/fixtures/gems/test2/lib/test2.rb +4 -0
  69. data/spec/{data/integration_cookbooks/test2/libraries/test2__resource.rb → fixtures/gems/test2/lib/test2/resource.rb} +1 -2
  70. data/spec/fixtures/gems/test2/lib/test2/version.rb +3 -0
  71. data/spec/{data → fixtures}/gems/test2/test2.gemspec +0 -0
  72. data/spec/{data → fixtures}/gems/test3/Rakefile +0 -0
  73. data/spec/{data/integration_cookbooks/test3 → fixtures/gems/test3/chef}/recipes/default.rb +0 -0
  74. data/spec/fixtures/gems/test3/lib/test3.rb +4 -0
  75. data/spec/{data/integration_cookbooks/test3/libraries/test3__dsl.rb → fixtures/gems/test3/lib/test3/dsl.rb} +1 -2
  76. data/spec/fixtures/gems/test3/lib/test3/version.rb +3 -0
  77. data/spec/{data → fixtures}/gems/test3/test3.gemspec +1 -0
  78. data/spec/gem_spec.rb +41 -31
  79. data/spec/integration_spec.rb +58 -82
  80. data/spec/runner_spec.rb +108 -0
  81. data/spec/spec_helper.rb +19 -26
  82. data/spec/spec_helper_spec.rb +238 -0
  83. metadata +124 -151
  84. data/lib/halite/converter/other.rb +0 -19
  85. data/lib/halite/converter/readme.rb +0 -20
  86. data/spec/converter/other_spec.rb +0 -56
  87. data/spec/converter/readme_spec.rb +0 -55
  88. data/spec/data/integration_cookbooks/test1/libraries/test1.rb +0 -3
  89. data/spec/data/integration_cookbooks/test1/libraries/test1__version.rb +0 -4
  90. data/spec/data/integration_cookbooks/test2/libraries/test2.rb +0 -5
  91. data/spec/data/integration_cookbooks/test2/libraries/test2__version.rb +0 -4
  92. data/spec/data/integration_cookbooks/test3/libraries/test3.rb +0 -5
  93. data/spec/data/integration_cookbooks/test3/libraries/test3__version.rb +0 -4
@@ -0,0 +1,4 @@
1
+ # coding: utf-8
2
+ raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
3
+ $LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
4
+ require "test3/dsl"
File without changes
@@ -0,0 +1,2 @@
1
+ module Test1
2
+ end
@@ -0,0 +1,3 @@
1
+ module Test1
2
+ VERSION = '1.2.3'
3
+ end
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ require 'test2/resource'
2
+
3
+ module Test2
4
+ end
@@ -1,7 +1,6 @@
1
- if ENV['HALITE_LOAD']; require 'chef/resource'
1
+ require 'chef/resource'
2
2
 
3
3
  module Test2
4
4
  class Resource < Chef::Resource
5
5
  end
6
6
  end
7
- end
@@ -0,0 +1,3 @@
1
+ module Test2
2
+ VERSION = '4.5.6'
3
+ end
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ require 'test3/dsl'
2
+
3
+ module Test3
4
+ end
@@ -1,4 +1,4 @@
1
- if ENV['HALITE_LOAD']; require_relative '../../test2/libraries/test2__version'
1
+ require 'test2/version'
2
2
 
3
3
  module Test3
4
4
  module DSL
@@ -13,4 +13,3 @@ class Chef
13
13
  include Test3::DSL
14
14
  end
15
15
  end
16
- end
@@ -0,0 +1,3 @@
1
+ module Test3
2
+ VERSION = '7.8.9'
3
+ end
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q||
13
13
  spec.homepage = ''
14
14
  spec.license = 'Apache 2.0'
15
+ spec.metadata['halite_entry_point'] = 'test3/dsl'
15
16
 
16
17
  spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
data/spec/gem_spec.rb CHANGED
@@ -1,3 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
1
17
  require 'spec_helper'
2
18
  require 'halite/gem'
3
19
  require 'halite/version'
@@ -10,22 +26,20 @@ describe Halite::Gem do
10
26
  context 'when loading halite' do
11
27
  its(:name) { is_expected.to eq 'halite' }
12
28
  its(:version) { is_expected.to eq Halite::VERSION }
13
- its(:description) { is_expected.to be_a String }
14
- its(:files) { is_expected.to include 'halite.gemspec' }
15
- its(:files) { is_expected.to include 'lib/halite/gem.rb' }
29
+ its(:spec) { is_expected.to be_a Gem::Specification }
16
30
  end
17
31
 
18
32
  context 'when loading halite with a version' do
19
33
  let(:gem_version) { Halite::VERSION }
20
34
  its(:name) { is_expected.to eq 'halite' }
21
35
  its(:version) { is_expected.to eq Halite::VERSION }
22
- its(:description) { is_expected.to be_a String }
36
+ its(:spec) { is_expected.to be_a Gem::Specification }
23
37
  end
24
38
 
25
39
  context 'when loading rspec' do
26
40
  let(:gem_name) { 'rspec' }
27
41
  its(:name) { is_expected.to eq 'rspec' }
28
- its(:description) { is_expected.to be_a String }
42
+ its(:spec) { is_expected.to be_a Gem::Specification }
29
43
  its(:is_halite_cookbook?) { is_expected.to be_falsey }
30
44
  end
31
45
 
@@ -34,12 +48,10 @@ describe Halite::Gem do
34
48
  its(:name) { is_expected.to eq 'test1' }
35
49
  its(:version) { is_expected.to eq '1.2.3' }
36
50
  its(:cookbook_name) { is_expected.to eq 'test1' }
37
- its(:files) { is_expected.to include 'test1.gemspec' }
38
- its(:files) { is_expected.to include 'lib/test1.rb' }
39
51
  its(:license_header) { is_expected.to eq "# coding: utf-8\n# Awesome license\n" }
40
52
  its(:each_library_file) { is_expected.to eq [
41
- [File.expand_path('../data/gems/test1/lib/test1.rb', __FILE__), 'test1.rb'],
42
- [File.expand_path('../data/gems/test1/lib/test1/version.rb', __FILE__), 'test1/version.rb'],
53
+ [File.expand_path('../fixtures/gems/test1/lib/test1.rb', __FILE__), 'test1.rb'],
54
+ [File.expand_path('../fixtures/gems/test1/lib/test1/version.rb', __FILE__), 'test1/version.rb'],
43
55
  ] }
44
56
  its(:cookbook_dependencies) { is_expected.to eq [] }
45
57
  its(:is_halite_cookbook?) { is_expected.to be_truthy }
@@ -48,10 +60,10 @@ describe Halite::Gem do
48
60
  context 'with no prefixes' do
49
61
  it 'returns all files' do
50
62
  expect(subject.each_file).to eq [
51
- [File.expand_path('../data/gems/test1/Rakefile', __FILE__), 'Rakefile'],
52
- [File.expand_path('../data/gems/test1/lib/test1.rb', __FILE__), 'lib/test1.rb'],
53
- [File.expand_path('../data/gems/test1/lib/test1/version.rb', __FILE__), 'lib/test1/version.rb'],
54
- [File.expand_path('../data/gems/test1/test1.gemspec', __FILE__), 'test1.gemspec'],
63
+ [File.expand_path('../fixtures/gems/test1/Rakefile', __FILE__), 'Rakefile'],
64
+ [File.expand_path('../fixtures/gems/test1/lib/test1.rb', __FILE__), 'lib/test1.rb'],
65
+ [File.expand_path('../fixtures/gems/test1/lib/test1/version.rb', __FILE__), 'lib/test1/version.rb'],
66
+ [File.expand_path('../fixtures/gems/test1/test1.gemspec', __FILE__), 'test1.gemspec'],
55
67
  ]
56
68
  end
57
69
  end
@@ -59,7 +71,7 @@ describe Halite::Gem do
59
71
  context 'with a prefix that overlaps a filename' do
60
72
  it 'returns only files in that folder' do
61
73
  expect(subject.each_file('lib/test1')).to eq [
62
- [File.expand_path('../data/gems/test1/lib/test1/version.rb', __FILE__), 'version.rb'],
74
+ [File.expand_path('../fixtures/gems/test1/lib/test1/version.rb', __FILE__), 'version.rb'],
63
75
  ]
64
76
  end
65
77
  end
@@ -71,29 +83,27 @@ describe Halite::Gem do
71
83
  its(:name) { is_expected.to eq 'test2' }
72
84
  its(:version) { is_expected.to eq '4.5.6' }
73
85
  its(:cookbook_name) { is_expected.to eq 'test2' }
74
- its(:files) { is_expected.to include 'test2.gemspec' }
75
- its(:files) { is_expected.to include 'lib/test2.rb' }
76
86
  its(:license_header) { is_expected.to eq "# coding: utf-8\n" }
77
87
  its(:each_library_file) { is_expected.to eq [
78
- [File.expand_path('../data/gems/test2/lib/test2.rb', __FILE__), 'test2.rb'],
79
- [File.expand_path('../data/gems/test2/lib/test2/resource.rb', __FILE__), 'test2/resource.rb'],
80
- [File.expand_path('../data/gems/test2/lib/test2/version.rb', __FILE__), 'test2/version.rb'],
88
+ [File.expand_path('../fixtures/gems/test2/lib/test2.rb', __FILE__), 'test2.rb'],
89
+ [File.expand_path('../fixtures/gems/test2/lib/test2/resource.rb', __FILE__), 'test2/resource.rb'],
90
+ [File.expand_path('../fixtures/gems/test2/lib/test2/version.rb', __FILE__), 'test2/version.rb'],
81
91
  ] }
82
- its(:cookbook_dependencies) { is_expected.to eq [Halite::Dependencies::Dependency.new('testdep', '>= 0.0', :requirements)] }
92
+ its(:cookbook_dependencies) { is_expected.to eq [Halite::Dependencies::Dependency.new('testdep', '>= 0', :requirements)] }
83
93
  its(:is_halite_cookbook?) { is_expected.to be_truthy }
84
94
 
85
95
  describe '#each_file' do
86
96
  context 'with no prefixes' do
87
97
  it 'returns all files' do
88
98
  expect(subject.each_file).to eq [
89
- [File.expand_path('../data/gems/test2/Rakefile', __FILE__), 'Rakefile'],
90
- [File.expand_path('../data/gems/test2/chef/attributes.rb', __FILE__), 'chef/attributes.rb'],
91
- [File.expand_path('../data/gems/test2/chef/recipes/default.rb', __FILE__), 'chef/recipes/default.rb'],
92
- [File.expand_path('../data/gems/test2/chef/templates/default/conf.erb', __FILE__), 'chef/templates/default/conf.erb'],
93
- [File.expand_path('../data/gems/test2/lib/test2.rb', __FILE__), 'lib/test2.rb'],
94
- [File.expand_path('../data/gems/test2/lib/test2/resource.rb', __FILE__), 'lib/test2/resource.rb'],
95
- [File.expand_path('../data/gems/test2/lib/test2/version.rb', __FILE__), 'lib/test2/version.rb'],
96
- [File.expand_path('../data/gems/test2/test2.gemspec', __FILE__), 'test2.gemspec'],
99
+ [File.expand_path('../fixtures/gems/test2/Rakefile', __FILE__), 'Rakefile'],
100
+ [File.expand_path('../fixtures/gems/test2/chef/attributes.rb', __FILE__), 'chef/attributes.rb'],
101
+ [File.expand_path('../fixtures/gems/test2/chef/recipes/default.rb', __FILE__), 'chef/recipes/default.rb'],
102
+ [File.expand_path('../fixtures/gems/test2/chef/templates/default/conf.erb', __FILE__), 'chef/templates/default/conf.erb'],
103
+ [File.expand_path('../fixtures/gems/test2/lib/test2.rb', __FILE__), 'lib/test2.rb'],
104
+ [File.expand_path('../fixtures/gems/test2/lib/test2/resource.rb', __FILE__), 'lib/test2/resource.rb'],
105
+ [File.expand_path('../fixtures/gems/test2/lib/test2/version.rb', __FILE__), 'lib/test2/version.rb'],
106
+ [File.expand_path('../fixtures/gems/test2/test2.gemspec', __FILE__), 'test2.gemspec'],
97
107
  ]
98
108
  end
99
109
  end
@@ -101,9 +111,9 @@ describe Halite::Gem do
101
111
  context 'with a prefix of chef' do
102
112
  it 'returns only files in that folder' do
103
113
  expect(subject.each_file('chef')).to eq [
104
- [File.expand_path('../data/gems/test2/chef/attributes.rb', __FILE__), 'attributes.rb'],
105
- [File.expand_path('../data/gems/test2/chef/recipes/default.rb', __FILE__), 'recipes/default.rb'],
106
- [File.expand_path('../data/gems/test2/chef/templates/default/conf.erb', __FILE__), 'templates/default/conf.erb'],
114
+ [File.expand_path('../fixtures/gems/test2/chef/attributes.rb', __FILE__), 'attributes.rb'],
115
+ [File.expand_path('../fixtures/gems/test2/chef/recipes/default.rb', __FILE__), 'recipes/default.rb'],
116
+ [File.expand_path('../fixtures/gems/test2/chef/templates/default/conf.erb', __FILE__), 'templates/default/conf.erb'],
107
117
  ]
108
118
  end
109
119
  end
@@ -1,104 +1,80 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
1
17
  require 'spec_helper'
2
- require 'tmpdir'
3
- require 'mixlib/shellout'
4
- require 'halite/converter'
18
+ require 'rspec-command'
5
19
 
6
20
  describe 'integration tests' do
7
- around do |example|
8
- Dir.mktmpdir('halite_test') do |path|
9
- example.metadata[:halite_temp_path] = path
10
- example.run
11
- end
12
- end
13
- let(:temp_path) do |example|
14
- example.metadata[:halite_temp_path]
15
- end
16
- let(:gem_name) { '' }
17
- let(:stub_cookbooks) { [] }
21
+ include RSpecCommand
22
+ include RSpecCommand::Rake
18
23
  let(:extra_gems) { [] }
19
24
  let(:recipes) { [] }
20
- let(:fixture_path) { File.expand_path("../data/integration_cookbooks/#{gem_name}", __FILE__) }
21
- let(:expect_output) { nil }
22
-
23
- shared_examples 'an integration test' do
24
- def directories_match(temp_path, fixture_path)
25
- temp_files = Dir[File.join(temp_path, '**', '*')].sort
26
- fixture_files = Dir[File.join(fixture_path, '**', '*')].sort
27
- expect(temp_files.map {|path| path[temp_path.length..-1] }).to eq fixture_files.map {|path| path[fixture_path.length..-1] }
28
- temp_files.zip(fixture_files).each do |temp_file, fixture_file|
29
- next unless File.file?(temp_file)
30
- expect(IO.read(temp_file)).to eq IO.read(fixture_file)
31
- end
32
- end
25
+ let(:expect_output) { }
33
26
 
34
- it 'matches the fixture' do
35
- # Convert gem
36
- Halite.convert(gem_name, temp_path)
37
- # Check that conversion matches the fixture
38
- directories_match(temp_path, fixture_path)
39
- end
27
+ shared_examples 'an integration test' do |gem_name, version, stub_cookbooks=[]|
28
+ describe 'Halite.convert' do
29
+ subject { Halite.convert(gem_name, temp_path) }
30
+ it { is_expected.to match_fixture("cookbooks/#{gem_name}") }
31
+ end # /describe Halite.convert
40
32
 
41
- it 'is a valid cookbook', slow: true do
42
- # Write out a solo config with the path
43
- solo_rb = File.join(temp_path, 'solo.rb')
44
- IO.write(solo_rb, "cookbook_path '#{temp_path}'")
45
- # Write out a cookbook that depends on our gem cookbook
46
- runner_path = File.join(temp_path, 'runner')
47
- Dir.mkdir(runner_path)
48
- IO.write(File.join(runner_path, 'metadata.rb'), "name 'runner'\ndepends '#{gem_name}'")
49
- Dir.mkdir(File.join(runner_path, 'recipes'))
50
- IO.write(File.join(runner_path, 'recipes', 'default.rb'), '')
51
- # Write out a stub cookbooks for dependency testing
33
+ describe 'run it with chef-solo', slow: true do
34
+ file('solo.rb') { "cookbook_path '#{temp_path}'" }
35
+ file 'runner/metadata.rb', "name 'runner'\ndepends '#{gem_name}'"
36
+ file 'runner/recipes/default.rb', ''
37
+ # Write out a stub cookbooks for dependency testing.
52
38
  stub_cookbooks.each do |(stub_name, stub_version)|
53
- stub_path = File.join(temp_path, stub_name)
54
- Dir.mkdir(stub_path)
55
- IO.write(File.join(stub_path, 'metadata.rb'), "name '#{stub_name}'\nversion '#{stub_version}'")
39
+ file "#{stub_name}/metadata.rb", "name '#{stub_name}'\nversion '#{stub_version}'"
56
40
  end
57
- # Convert gems
58
- ([gem_name] + extra_gems).each do |name|
59
- cookbook_path = File.join(temp_path, name)
60
- Dir.mkdir(cookbook_path)
61
- Halite.convert(name, cookbook_path)
41
+ before do
42
+ ([gem_name] + extra_gems).each do |name|
43
+ cookbook_path = File.join(temp_path, name)
44
+ Dir.mkdir(cookbook_path)
45
+ Halite.convert(name, cookbook_path)
46
+ end
62
47
  end
63
- # Run solo
64
- cmd = Mixlib::ShellOut.new("bundle exec chef-solo -l debug -c #{solo_rb} -o #{(['runner']+recipes).map{|r| "recipe[#{r}]"}.join(',')}", cwd: temp_path)
65
- cmd.run_command
66
- expect(cmd.error?).to be_falsey, "Running #{cmd.command} failed (#{cmd.exitstatus} #{cmd.error?}):\n#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
67
- Array(expect_output).each do |output|
68
- expect(cmd.stdout).to include(output), "'#{output}' not found in the output of #{cmd.command}:\n#{cmd.stdout}"
48
+ command { "chef-solo -l debug -c solo.rb -o #{(['runner']+recipes).map{|r| "recipe[#{r}]"}.join(',')}" }
49
+
50
+ it do
51
+ # Force the command to run at least once.
52
+ subject
53
+ Array(expect_output).each do |output|
54
+ expect(subject.stdout).to include(output), "'#{output}' not found in the output of #{subject.command}:\n#{subject.stdout}"
55
+ end
69
56
  end
70
- end
57
+ end # /describe run it with chef-solo
71
58
 
72
- it 'can run rake chef:build', slow: true do
73
- # Copy the test gem to the temp path
74
- FileUtils.cp_r(File.join(File.expand_path(File.join('..', 'data', 'gems', gem_name), __FILE__), '.'), temp_path)
75
- # Run rake build
76
- cmd = Mixlib::ShellOut.new("bundle exec rake chef:build", cwd: temp_path)
77
- cmd.run_command
78
- expect(cmd.error?).to be_falsey, "Running #{cmd.command} failed (#{cmd.exitstatus} #{cmd.error?}):\n#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
79
- # Check that conversion matches the fixture
80
- directories_match(Dir[File.join(temp_path, 'pkg', '*')].first, fixture_path)
81
- end
82
- end
59
+ describe 'run rake chef:build' do
60
+ fixture_file "gems/#{gem_name}"
61
+ rake_task 'chef:build'
62
+ it { is_expected.to match_fixture("cookbooks/#{gem_name}", "pkg/#{gem_name}-#{version}") }
63
+ end # /describe run rake chef:build
64
+ end # /shared_examples an integration test
83
65
 
84
66
  context 'with test1 gem', integration: true do
85
- let(:gem_name) { 'test1' }
86
- it_should_behave_like 'an integration test'
87
- end
67
+ it_should_behave_like 'an integration test', 'test1', '1.2.3'
68
+ end # /context with test1 gem
88
69
 
89
70
  context 'with test2 gem', integration: true do
90
- let(:gem_name) { 'test2' }
91
- let(:stub_cookbooks) { [['testdep', '1.0.0']] }
92
- it_should_behave_like 'an integration test'
93
- end
71
+ it_should_behave_like 'an integration test', 'test2', '4.5.6', [['testdep', '1.0.0']]
72
+ end # /context with test2 gem
94
73
 
95
74
  context 'with test3 gem', integration: true do
96
- let(:gem_name) { 'test3' }
97
75
  let(:extra_gems) { ['test2'] }
98
- let(:stub_cookbooks) { [['testdep', '1.0.0']] }
99
76
  let(:recipes) { ['test3'] }
100
77
  let(:expect_output) { '!!!!!!!!!!test34.5.6' }
101
- it_should_behave_like 'an integration test'
102
- end
103
-
78
+ it_should_behave_like 'an integration test', 'test3', '7.8.9', [['testdep', '1.0.0']]
79
+ end # /context with test3 gem
104
80
  end
@@ -0,0 +1,108 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ # This file is not named spec/spec_helper/runner_spec.rb because that seems confusing.
18
+
19
+ require 'spec_helper'
20
+
21
+ require 'halite/spec_helper/runner'
22
+
23
+ describe Halite::SpecHelper::Runner do
24
+ let(:options) { Hash.new }
25
+ subject { described_class.new(options) }
26
+
27
+ describe 'Runner.converge' do
28
+ let(:instance) { double('Runner instance') }
29
+ before do
30
+ expect(described_class).to receive(:new).with(options).and_return(instance)
31
+ end
32
+
33
+ context 'with a block' do
34
+ it do
35
+ expect(instance).to receive(:converge) do |&block|
36
+ expect(block).to be_a(Proc)
37
+ end
38
+ described_class.converge { ruby_block 'test' }
39
+ end
40
+ end # /context with a block
41
+
42
+ context 'with a recipe' do
43
+ it do
44
+ expect(instance).to receive(:converge).with('test')
45
+ described_class.converge('test')
46
+ end
47
+ end # /context with a recipe
48
+
49
+ context 'with options' do
50
+ let(:options) { {dry_run: true} }
51
+ it do
52
+ expect(instance).to receive(:converge).with('test')
53
+ described_class.converge('test', dry_run: true)
54
+ end
55
+ end # /context with options
56
+ end # /describe Runner.converge
57
+
58
+ describe '#initialize' do
59
+
60
+ context 'with a simple option' do
61
+ let(:options) { {dry_run: true} }
62
+ its(:dry_run?) { is_expected.to be_truthy }
63
+ end # /context with a simple option
64
+
65
+ context 'with default_attributes' do
66
+ let(:options) { {default_attributes: {halite: 'test'}} }
67
+ it { expect(subject.node.default['halite']).to eq('test') }
68
+ it { expect(subject.node['halite']).to eq('test') }
69
+ end # /context with default_attributes
70
+
71
+ context 'with normal_attributes' do
72
+ let(:options) { {normal_attributes: {halite: 'test'}} }
73
+ it { expect(subject.node.normal['halite']).to eq('test') }
74
+ it { expect(subject.node['halite']).to eq('test') }
75
+ end # /context with normal_attributes
76
+
77
+ context 'with override_attributes' do
78
+ let(:options) { {override_attributes: {halite: 'test'}} }
79
+ it { expect(subject.node.override['halite']).to eq('test') }
80
+ it { expect(subject.node['halite']).to eq('test') }
81
+ end # /context with override_attributes
82
+ end # /describe #initialize
83
+
84
+ describe '#converge' do
85
+ context 'with a block' do
86
+ it do
87
+ sentinel = [false]
88
+ subject.converge { sentinel[0] = true }
89
+ expect(sentinel[0]).to eq(true)
90
+ end
91
+ end # /context with a block
92
+
93
+ context 'with a recipe' do
94
+ let(:options) { {dry_run: true} }
95
+
96
+ it do
97
+ expect(subject.node.run_list).to receive(:add).with('test')
98
+ subject.converge('test')
99
+ end
100
+ end # /context with a recipe
101
+
102
+ context 'with both a block and a recipe' do
103
+ it do
104
+ expect { subject.converge('test') { } }.to raise_error(Halite::Error)
105
+ end
106
+ end # /context with both a block and a recipe
107
+ end # /describe #converge
108
+ end