chef-gen-flavors 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 946c3722860ef01d69ca49847202671db1846c9b
4
- data.tar.gz: a51977f890bb4ef7be75e79d441f0338ba078bdb
3
+ metadata.gz: 562095360336aa05b9852c336b8ed4039cfda565
4
+ data.tar.gz: 08a2839dad35a4e412c74905f9e9b6a192dafb47
5
5
  SHA512:
6
- metadata.gz: bb6c97a4fe43d518c45fdc5be85fc3c857524d79ac48a09417e160a6fafcfe4bb4f35df93ad725d602776d76d636be0a9191f97e7ef87c180820a3c94ffc12b5
7
- data.tar.gz: 223a7f1f8652f75c5fa59eb1bd37e9cc56712550e5ea989b38f4ee446d1b74ace0c3f72cdfc0866fc697cbf7722a1ab5baf3185323837036e6a520d23bdbaacf
6
+ metadata.gz: 929b6174ccab2ec30537d317e6a9f9cb1279c738bb926521f1c5400f4428497fda54a773e0ee7e842afd32d0cddfb447aa70be36ef744e761bb4340fbb4b567f
7
+ data.tar.gz: 28e725b716c9241b46eb68a01195183f42512adc10da09585e363d2169ed09aabd7b87476293910d2dd89eb115fb11a06cd5604161dc1bcf12af95085bf3cbf5
data/History.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog for chef-gen-template
2
2
 
3
+ ## 0.4.0
4
+
5
+ * added a GitInit snippet that runs 'git init .'
6
+ * added a simple Aruba tests that verifies that 'chef generate cookbook foo' works
7
+
3
8
  ## 0.3.0
4
9
 
5
10
  * renamed from ChefDK::Template::Plugin to ChefGen::Flavors at Chef's request so as to not pollute the ChefDK namespace
data/Manifest.txt CHANGED
@@ -2,7 +2,6 @@
2
2
  .rubocop.yml
3
3
  .travis.yml
4
4
  Gemfile
5
- Gemfile.lock
6
5
  Guardfile
7
6
  History.md
8
7
  LICENSE
@@ -10,6 +9,10 @@ Manifest.txt
10
9
  README.md
11
10
  Rakefile
12
11
  chef-gen-flavors.gemspec
12
+ features/generate.feature
13
+ features/step_definitions/chef.rb
14
+ features/step_definitions/knife.rb
15
+ features/support/env.rb
13
16
  lib/chef_gen/flavor.rb
14
17
  lib/chef_gen/flavor_base.rb
15
18
  lib/chef_gen/flavors.rb
@@ -18,6 +21,7 @@ lib/chef_gen/snippet/chef_spec.rb
18
21
  lib/chef_gen/snippet/cookbook_base.rb
19
22
  lib/chef_gen/snippet/example_file.rb
20
23
  lib/chef_gen/snippet/example_template.rb
24
+ lib/chef_gen/snippet/git_init.rb
21
25
  lib/chef_gen/snippet/recipes.rb
22
26
  lib/chef_gen/snippet/resource_provider.rb
23
27
  lib/chef_gen/snippet/standard_ignore.rb
@@ -31,6 +35,7 @@ spec/lib/chef_gen/snippet/chef_spec_spec.rb
31
35
  spec/lib/chef_gen/snippet/cookbook_base_spec.rb
32
36
  spec/lib/chef_gen/snippet/example_file_spec.rb
33
37
  spec/lib/chef_gen/snippet/example_template_spec.rb
38
+ spec/lib/chef_gen/snippet/git_init_spec.rb
34
39
  spec/lib/chef_gen/snippet/recipes_spec.rb
35
40
  spec/lib/chef_gen/snippet/resource_provider_spec.rb
36
41
  spec/lib/chef_gen/snippet/standard_ignore_spec.rb
@@ -41,6 +46,7 @@ spec/support/fixtures/code_generator/metadata.rb
41
46
  spec/support/fixtures/code_generator/recipes/cookbook.rb
42
47
  spec/support/fixtures/code_generator_2/metadata.rb
43
48
  spec/support/fixtures/code_generator_2/recipes/cookbook.rb
49
+ spec/support/fixtures/code_generator_2/templates/default/README_md.erb
44
50
  spec/support/fixtures/lib/chef_gen/flavor/bar.rb
45
51
  spec/support/fixtures/lib/chef_gen/flavor/baz.rb
46
52
  spec/support/fixtures/lib/chef_gen/flavor/foo.rb
data/README.md CHANGED
@@ -41,8 +41,9 @@ provided by Chef, not as a gem.
41
41
 
42
42
  In your `knife.rb` file, add this snippet:
43
43
 
44
- unless chefdk.nil?
45
- require 'chef_gen/template'
44
+ # only load ChefGen::Flavors if we're being called from the ChefDK CLI
45
+ if defined?(ChefDK::CLI)
46
+ require 'chef_gen/flavors'
46
47
  chefdk.generator_cookbook = ChefGen::Flavors.path
47
48
  end
48
49
 
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  extra_dev_deps << ['simplecov', '~> 0.9']
23
23
  extra_dev_deps << ['simplecov-console', '~> 0.2']
24
24
  extra_dev_deps << ['yard', '~> 0.8']
25
+ extra_dev_deps << ['aruba', '~> 0.6']
25
26
  end
26
27
  # re-generate our gemspec before packaging
27
28
  task package: 'gem:spec'
@@ -64,6 +65,17 @@ rescue LoadError
64
65
  task :test
65
66
  end
66
67
 
68
+ # Feature Tests
69
+ begin
70
+ require 'cucumber'
71
+ require 'cucumber/rake/task'
72
+ Cucumber::Rake::Task.new(:features)
73
+ rescue LoadError
74
+ puts 'Cucumber/Aruba not available; disabling feature tasks'
75
+ # create a no-op spec task for :default
76
+ task :features
77
+ end
78
+
67
79
  # Documentation
68
80
  begin
69
81
  require 'yard'
@@ -76,9 +88,9 @@ rescue LoadError
76
88
  puts 'yard not available; disabling tasks'
77
89
  end
78
90
 
79
- # test is an alias for spec
80
- desc 'runs unit tests'
81
- task test: [:spec]
91
+ # test is an alias for spec and features
92
+ desc 'runs unit and feature tests'
93
+ task test: [:spec, :features]
82
94
 
83
95
  # default is to test everything
84
96
  desc 'runs all tests'
@@ -1,18 +1,18 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: chef-gen-flavors 0.3.0.20150514061941 ruby lib
2
+ # stub: chef-gen-flavors 0.4.0.20150515142632 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "chef-gen-flavors"
6
- s.version = "0.3.0.20150514061941"
6
+ s.version = "0.4.0.20150515142632"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["James FitzGibbon"]
11
- s.date = "2015-05-14"
11
+ s.date = "2015-05-15"
12
12
  s.description = "chef-gen-flavors is a framework for creating custom templates for the\n'chef generate' command provided by ChefDK.\n\nThis gem simply provides a framework; templates are provided by separate\ngems, which you can host privately for use within your organization or\npublicly for the Chef community to use.\n\nAt present this is focused primarily on providing templates for generation of\ncookbooks, as this is where most organization-specific customization takes place.\nSupport for the other artifacts that ChefDK can generate may work, but is not\nthe focus of early releases."
13
13
  s.email = ["james.i.fitzgibbon@nordstrom.com"]
14
14
  s.extra_rdoc_files = ["History.md", "Manifest.txt", "README.md"]
15
- s.files = [".rspec", ".rubocop.yml", ".travis.yml", "Gemfile", "Gemfile.lock", "Guardfile", "History.md", "LICENSE", "Manifest.txt", "README.md", "Rakefile", "chef-gen-flavors.gemspec", "lib/chef_gen/flavor.rb", "lib/chef_gen/flavor_base.rb", "lib/chef_gen/flavors.rb", "lib/chef_gen/snippet/attributes.rb", "lib/chef_gen/snippet/chef_spec.rb", "lib/chef_gen/snippet/cookbook_base.rb", "lib/chef_gen/snippet/example_file.rb", "lib/chef_gen/snippet/example_template.rb", "lib/chef_gen/snippet/recipes.rb", "lib/chef_gen/snippet/resource_provider.rb", "lib/chef_gen/snippet/standard_ignore.rb", "lib/chef_gen/snippet/style_rubocop.rb", "lib/chef_gen/snippet/test_kitchen.rb", "lib/chef_gen/snippets.rb", "spec/lib/chef_gen/flavor_base_spec.rb", "spec/lib/chef_gen/flavors_spec.rb", "spec/lib/chef_gen/snippet/attributes_spec.rb", "spec/lib/chef_gen/snippet/chef_spec_spec.rb", "spec/lib/chef_gen/snippet/cookbook_base_spec.rb", "spec/lib/chef_gen/snippet/example_file_spec.rb", "spec/lib/chef_gen/snippet/example_template_spec.rb", "spec/lib/chef_gen/snippet/recipes_spec.rb", "spec/lib/chef_gen/snippet/resource_provider_spec.rb", "spec/lib/chef_gen/snippet/standard_ignore_spec.rb", "spec/lib/chef_gen/snippet/style_rubocop_spec.rb", "spec/lib/chef_gen/snippet/test_kitchen_spec.rb", "spec/spec_helper.rb", "spec/support/fixtures/code_generator/metadata.rb", "spec/support/fixtures/code_generator/recipes/cookbook.rb", "spec/support/fixtures/code_generator_2/metadata.rb", "spec/support/fixtures/code_generator_2/recipes/cookbook.rb", "spec/support/fixtures/lib/chef_gen/flavor/bar.rb", "spec/support/fixtures/lib/chef_gen/flavor/baz.rb", "spec/support/fixtures/lib/chef_gen/flavor/foo.rb"]
15
+ s.files = [".rspec", ".rubocop.yml", ".travis.yml", "Gemfile", "Guardfile", "History.md", "LICENSE", "Manifest.txt", "README.md", "Rakefile", "chef-gen-flavors.gemspec", "features/generate.feature", "features/step_definitions/chef.rb", "features/step_definitions/knife.rb", "features/support/env.rb", "lib/chef_gen/flavor.rb", "lib/chef_gen/flavor_base.rb", "lib/chef_gen/flavors.rb", "lib/chef_gen/snippet/attributes.rb", "lib/chef_gen/snippet/chef_spec.rb", "lib/chef_gen/snippet/cookbook_base.rb", "lib/chef_gen/snippet/example_file.rb", "lib/chef_gen/snippet/example_template.rb", "lib/chef_gen/snippet/git_init.rb", "lib/chef_gen/snippet/recipes.rb", "lib/chef_gen/snippet/resource_provider.rb", "lib/chef_gen/snippet/standard_ignore.rb", "lib/chef_gen/snippet/style_rubocop.rb", "lib/chef_gen/snippet/test_kitchen.rb", "lib/chef_gen/snippets.rb", "spec/lib/chef_gen/flavor_base_spec.rb", "spec/lib/chef_gen/flavors_spec.rb", "spec/lib/chef_gen/snippet/attributes_spec.rb", "spec/lib/chef_gen/snippet/chef_spec_spec.rb", "spec/lib/chef_gen/snippet/cookbook_base_spec.rb", "spec/lib/chef_gen/snippet/example_file_spec.rb", "spec/lib/chef_gen/snippet/example_template_spec.rb", "spec/lib/chef_gen/snippet/git_init_spec.rb", "spec/lib/chef_gen/snippet/recipes_spec.rb", "spec/lib/chef_gen/snippet/resource_provider_spec.rb", "spec/lib/chef_gen/snippet/standard_ignore_spec.rb", "spec/lib/chef_gen/snippet/style_rubocop_spec.rb", "spec/lib/chef_gen/snippet/test_kitchen_spec.rb", "spec/spec_helper.rb", "spec/support/fixtures/code_generator/metadata.rb", "spec/support/fixtures/code_generator/recipes/cookbook.rb", "spec/support/fixtures/code_generator_2/metadata.rb", "spec/support/fixtures/code_generator_2/recipes/cookbook.rb", "spec/support/fixtures/code_generator_2/templates/default/README_md.erb", "spec/support/fixtures/lib/chef_gen/flavor/bar.rb", "spec/support/fixtures/lib/chef_gen/flavor/baz.rb", "spec/support/fixtures/lib/chef_gen/flavor/foo.rb"]
16
16
  s.homepage = "https://github.com/Nordstrom/chef-gen-flavors"
17
17
  s.licenses = ["apache2"]
18
18
  s.rdoc_options = ["--main", "README.md"]
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.add_development_dependency(%q<simplecov>, ["~> 0.9"])
39
39
  s.add_development_dependency(%q<simplecov-console>, ["~> 0.2"])
40
40
  s.add_development_dependency(%q<yard>, ["~> 0.8"])
41
+ s.add_development_dependency(%q<aruba>, ["~> 0.6"])
41
42
  else
42
43
  s.add_dependency(%q<little-plugger>, ["~> 1.1"])
43
44
  s.add_dependency(%q<bogo-ui>, ["~> 0.1"])
@@ -54,6 +55,7 @@ Gem::Specification.new do |s|
54
55
  s.add_dependency(%q<simplecov>, ["~> 0.9"])
55
56
  s.add_dependency(%q<simplecov-console>, ["~> 0.2"])
56
57
  s.add_dependency(%q<yard>, ["~> 0.8"])
58
+ s.add_dependency(%q<aruba>, ["~> 0.6"])
57
59
  end
58
60
  else
59
61
  s.add_dependency(%q<little-plugger>, ["~> 1.1"])
@@ -71,5 +73,6 @@ Gem::Specification.new do |s|
71
73
  s.add_dependency(%q<simplecov>, ["~> 0.9"])
72
74
  s.add_dependency(%q<simplecov-console>, ["~> 0.2"])
73
75
  s.add_dependency(%q<yard>, ["~> 0.8"])
76
+ s.add_dependency(%q<aruba>, ["~> 0.6"])
74
77
  end
75
78
  end
@@ -0,0 +1,17 @@
1
+ Feature: chef generate
2
+
3
+ Verifies that 'chef generate cookbook' works when the generator
4
+ path is dynamically chosen by chef-gen-flavors
5
+
6
+ Scenario: generate cookbook
7
+ Given a knife.rb that uses chef-gen-flavors
8
+ And I set the environment variables to:
9
+ | variable | value |
10
+ |----------------|----------------------------------|
11
+ | CHEFGEN_FLAVOR | bar |
12
+ | RUBYLIB | ../../spec/support/fixtures/lib |
13
+ When I generate a cookbook named 'foo'
14
+ Then the exit status should be 0
15
+ And the output should match /using ChefGen flavor 'bar'/
16
+ And the output should match /Recipe: code_generator_2::cookbook/
17
+ And the output should match /- create new file README.md/
@@ -0,0 +1,3 @@
1
+ Given(/I generate a cookbook named '(.+)'/) do |cbname|
2
+ run_simple "chef generate cookbook #{cbname}"
3
+ end
@@ -0,0 +1,6 @@
1
+ Given(/^a knife.rb that uses chef-gen-flavors$/) do
2
+ write_file 'knife.rb', <<END
3
+ require 'chef_gen/flavors'
4
+ chefdk.generator_cookbook = ChefGen::Flavors.path
5
+ END
6
+ end
@@ -0,0 +1,14 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ end
4
+
5
+ require 'aruba/cucumber'
6
+
7
+ # Travis runs tests in a limited environment which takes a long time to invoke
8
+ # the knife command. Up the timeout when we're in a travis build based on the
9
+ # environment variable set in .travis.yml
10
+ if ENV['TRAVIS_BUILD']
11
+ Before do
12
+ @aruba_timeout_seconds = 15
13
+ end
14
+ end
@@ -56,7 +56,7 @@ module ChefGen
56
56
  @recipe = recipe
57
57
 
58
58
  # derive our target path
59
- ctx = ChefDK::Generator.context
59
+ ctx = generator_context
60
60
  @target_path = File.expand_path(
61
61
  File.join(ctx.cookbook_root, ctx.cookbook_name)
62
62
  )
@@ -72,10 +72,16 @@ module ChefGen
72
72
  end
73
73
  end
74
74
 
75
+ # a proxy to ChefDK's generator context
76
+ # @return [ChefDK::Generator::Context]
77
+ def generator_context
78
+ ChefDK::Generator.context
79
+ end
80
+
75
81
  # generates the Chef resources that the plugin has declared
76
82
  # @return [void]
77
83
  def generate
78
- run_mixins
84
+ run_snippets
79
85
  add_directories
80
86
  add_files
81
87
  add_templates
@@ -108,7 +114,7 @@ module ChefGen
108
114
  # @yield [Chef::Recipe] the recipe into which the mixin can inject
109
115
  # resources
110
116
  # @api private
111
- def run_mixins
117
+ def run_snippets
112
118
  snippets = public_methods.select do |m|
113
119
  m.to_s =~ /^snippet_/
114
120
  end
@@ -7,7 +7,7 @@ module ChefGen
7
7
  # a plugin framework for creating ChefDK generator flavors
8
8
  class Flavors
9
9
  # the version of the gem
10
- VERSION = '0.3.0'
10
+ VERSION = '0.4.0'
11
11
 
12
12
  extend LittlePlugger path: 'chef_gen/flavor',
13
13
  module: ChefGen::Flavor
@@ -17,8 +17,6 @@ module ChefGen
17
17
  # the selected ChefGen Flavor
18
18
  # @return [String] the path to the code_generator cookbook
19
19
  def path
20
- # validate what LittlePlugger found
21
- validate_plugins
22
20
  # then take a copy so we can augment it
23
21
  @plugins = plugins.dup
24
22
  add_builtin_template
@@ -33,17 +31,6 @@ module ChefGen
33
31
 
34
32
  private
35
33
 
36
- # validates all plugins found by LittlePlugger
37
- # @raise RuntimeError if any plugin is invalid
38
- # @return [void]
39
- # @api private
40
- def validate_plugins
41
- plugins.each do |name, klass|
42
- fail "no description for plugin #{name}" \
43
- unless klass.respond_to?(:description)
44
- end
45
- end
46
-
47
34
  # checks if the plugin to use has been specified in the environment
48
35
  # variable CHEFGEN_FLAVOR
49
36
  # @return [Symbol,nil] the plugin if specified and found, nil otherwise
@@ -104,7 +91,8 @@ module ChefGen
104
91
  if true == klass
105
92
  output << "#{idx}. ChefDK built-in template"
106
93
  else
107
- output << "#{idx}. #{name}: #{klass.description}"
94
+ descr = klass.respond_to?(:description) ? klass.description : ''
95
+ output << "#{idx}. #{name}: #{descr}"
108
96
  end
109
97
  idx += 1
110
98
  end
@@ -0,0 +1,18 @@
1
+ module ChefGen
2
+ module Snippet
3
+ # initializes a git repo
4
+ module GitInit
5
+ # executes 'git init .'
6
+ # @param recipe [Chef::Recipe] the recipe into which resources
7
+ # will be injected
8
+ # @return [void]
9
+ def snippet_gitinit(recipe)
10
+ c = generator_context
11
+ recipe.send(:execute, 'initialize git repo') do
12
+ command('git init .')
13
+ cwd @target_path
14
+ end if c.have_git && !c.skip_git_init
15
+ end
16
+ end
17
+ end
18
+ end
@@ -11,5 +11,6 @@ module ChefGen
11
11
  autoload :StandardIgnore, 'chef_gen/snippet/standard_ignore'
12
12
  autoload :StyleRubocop, 'chef_gen/snippet/style_rubocop'
13
13
  autoload :TestKitchen, 'chef_gen/snippet/test_kitchen'
14
+ autoload :GitInit, 'chef_gen/snippet/git_init'
14
15
  end
15
16
  end
@@ -22,12 +22,10 @@ end
22
22
  # :nocov:
23
23
 
24
24
  RSpec.describe ChefGen::FlavorBase do
25
+ include ChefDKGeneratorContext
26
+ include DummyRecipe
27
+
25
28
  before do
26
- @ctx = double('ChefDK generator context')
27
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
28
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
29
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
30
- @recipe = double('Chef recipe').as_null_object
31
29
  @orig_stdout = $stdout
32
30
  $stdout = File.open(File::NULL, 'w')
33
31
  end
@@ -161,4 +159,9 @@ RSpec.describe ChefGen::FlavorBase do
161
159
  template.next_steps = 'do something amazing'
162
160
  template.generate
163
161
  end
162
+
163
+ it 'proxies to the ChefDK generator context' do
164
+ template = ChefGen::Flavor::Amazing.new(@recipe)
165
+ template.generator_context
166
+ end
164
167
  end
@@ -6,6 +6,8 @@ require 'support/fixtures/lib/chef_gen/flavor/bar'
6
6
  require 'support/fixtures/lib/chef_gen/flavor/baz'
7
7
 
8
8
  RSpec.describe ChefGen::Flavors do
9
+ include ChefDKGeneratorContext
10
+
9
11
  before do
10
12
  ChefGen::Flavors.clear_plugins
11
13
  ENV.delete('CHEFGEN_FLAVOR')
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::Attributes do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(attributes).each do |dname|
31
26
  it "should create the directory #{dname}" do
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::ChefSpec do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(spec spec/recipes).each do |dname|
31
26
  it "should create the directory #{dname}" do
@@ -18,13 +18,8 @@ module ChefGen
18
18
  end
19
19
 
20
20
  RSpec.describe ChefGen::Snippet::CookbookBase do
21
- before do
22
- @ctx = double('ChefDK generator context')
23
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
24
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
25
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
26
- @recipe = double('Chef recipe').as_null_object
27
- end
21
+ include ChefDKGeneratorContext
22
+ include DummyRecipe
28
23
 
29
24
  %w(Gemfile Rakefile Berksfile Guardfile README.md
30
25
  CHANGELOG.md metadata.rb).each do |fname|
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::ExampleFile do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(files files/default).each do |dname|
31
26
  it "should create the directory #{dname}" do
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::ExampleTemplate do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(templates templates/default).each do |dname|
31
26
  it "should create the directory #{dname}" do
@@ -0,0 +1,30 @@
1
+ require 'chef_gen/flavor_base'
2
+ require 'chef_gen/snippets'
3
+
4
+ module ChefGen
5
+ module Flavor
6
+ class Awesome < FlavorBase
7
+ include ChefGen::Snippet::GitInit
8
+
9
+ class << self
10
+ # :nocov:
11
+ def description
12
+ 'my awesome template'
13
+ end
14
+ # :nocov:
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ # rubocop:disable Style/RegexpLiteral
21
+ RSpec.describe ChefGen::Snippet::GitInit do
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
24
+
25
+ it 'should execute git init' do
26
+ expect(@recipe).to receive(:execute).with('initialize git repo')
27
+ template = ChefGen::Flavor::Awesome.new(@recipe)
28
+ template.generate
29
+ end
30
+ end
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::Recipes do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(recipes).each do |dname|
31
26
  it "should create the directory #{dname}" do
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::ResourceProvider do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(resources providers).each do |dname|
31
26
  it "should create the directory #{dname}" do
@@ -18,13 +18,8 @@ module ChefGen
18
18
  end
19
19
 
20
20
  RSpec.describe ChefGen::Snippet::StandardIgnore do
21
- before do
22
- @ctx = double('ChefDK generator context')
23
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
24
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
25
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
26
- @recipe = double('Chef recipe').as_null_object
27
- end
21
+ include ChefDKGeneratorContext
22
+ include DummyRecipe
28
23
 
29
24
  it 'should create a chefignore file' do
30
25
  expect(@recipe).to receive(:file).with(/chefignore$/)
@@ -18,13 +18,8 @@ module ChefGen
18
18
  end
19
19
 
20
20
  RSpec.describe ChefGen::Snippet::StyleRubocop do
21
- before do
22
- @ctx = double('ChefDK generator context')
23
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
24
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
25
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
26
- @recipe = double('Chef recipe').as_null_object
27
- end
21
+ include ChefDKGeneratorContext
22
+ include DummyRecipe
28
23
 
29
24
  %w(.rubocop.yml).each do |fname|
30
25
  it "should add a template for #{fname}" do
@@ -19,13 +19,8 @@ end
19
19
 
20
20
  # rubocop:disable Style/RegexpLiteral
21
21
  RSpec.describe ChefGen::Snippet::TestKitchen do
22
- before do
23
- @ctx = double('ChefDK generator context')
24
- allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
25
- allow(@ctx).to receive(:cookbook_name).and_return('foo')
26
- allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
27
- @recipe = double('Chef recipe').as_null_object
28
- end
22
+ include ChefDKGeneratorContext
23
+ include DummyRecipe
29
24
 
30
25
  %w(test test/integration test/integration/default
31
26
  test/integration/default/serverspec
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'rspec/core/shared_context'
2
+
1
3
  if ENV['COVERAGE']
2
4
  require 'simplecov'
3
5
  require 'simplecov-console'
@@ -36,3 +38,26 @@ module LittlePlugger
36
38
  end
37
39
  end
38
40
  end
41
+
42
+ # a shared context that stubs a ChefDK Generator context
43
+ module ChefDKGeneratorContext
44
+ extend RSpec::Core::SharedContext
45
+
46
+ before do
47
+ @ctx = double('ChefDK generator context')
48
+ allow(@ctx).to receive(:cookbook_root).and_return('/nonexistent')
49
+ allow(@ctx).to receive(:cookbook_name).and_return('foo')
50
+ allow(@ctx).to receive(:have_git).and_return(true)
51
+ allow(@ctx).to receive(:skip_git_init).and_return(false)
52
+ allow(ChefDK::Generator).to receive(:context).and_return(@ctx)
53
+ end
54
+ end
55
+
56
+ # a shared context that allows a recipe double to receive unknown methods
57
+ module DummyRecipe
58
+ extend RSpec::Core::SharedContext
59
+
60
+ before do
61
+ @recipe = double('Chef recipe').as_null_object
62
+ end
63
+ end
@@ -1 +1,3 @@
1
- # [PH]
1
+ template 'README.md' do
2
+ source 'README_md.erb'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-gen-flavors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James FitzGibbon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: little-plugger
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0.8'
223
+ - !ruby/object:Gem::Dependency
224
+ name: aruba
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '0.6'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '0.6'
223
237
  description: |-
224
238
  chef-gen-flavors is a framework for creating custom templates for the
225
239
  'chef generate' command provided by ChefDK.
@@ -245,7 +259,6 @@ files:
245
259
  - ".rubocop.yml"
246
260
  - ".travis.yml"
247
261
  - Gemfile
248
- - Gemfile.lock
249
262
  - Guardfile
250
263
  - History.md
251
264
  - LICENSE
@@ -253,6 +266,10 @@ files:
253
266
  - README.md
254
267
  - Rakefile
255
268
  - chef-gen-flavors.gemspec
269
+ - features/generate.feature
270
+ - features/step_definitions/chef.rb
271
+ - features/step_definitions/knife.rb
272
+ - features/support/env.rb
256
273
  - lib/chef_gen/flavor.rb
257
274
  - lib/chef_gen/flavor_base.rb
258
275
  - lib/chef_gen/flavors.rb
@@ -261,6 +278,7 @@ files:
261
278
  - lib/chef_gen/snippet/cookbook_base.rb
262
279
  - lib/chef_gen/snippet/example_file.rb
263
280
  - lib/chef_gen/snippet/example_template.rb
281
+ - lib/chef_gen/snippet/git_init.rb
264
282
  - lib/chef_gen/snippet/recipes.rb
265
283
  - lib/chef_gen/snippet/resource_provider.rb
266
284
  - lib/chef_gen/snippet/standard_ignore.rb
@@ -274,6 +292,7 @@ files:
274
292
  - spec/lib/chef_gen/snippet/cookbook_base_spec.rb
275
293
  - spec/lib/chef_gen/snippet/example_file_spec.rb
276
294
  - spec/lib/chef_gen/snippet/example_template_spec.rb
295
+ - spec/lib/chef_gen/snippet/git_init_spec.rb
277
296
  - spec/lib/chef_gen/snippet/recipes_spec.rb
278
297
  - spec/lib/chef_gen/snippet/resource_provider_spec.rb
279
298
  - spec/lib/chef_gen/snippet/standard_ignore_spec.rb
@@ -284,6 +303,7 @@ files:
284
303
  - spec/support/fixtures/code_generator/recipes/cookbook.rb
285
304
  - spec/support/fixtures/code_generator_2/metadata.rb
286
305
  - spec/support/fixtures/code_generator_2/recipes/cookbook.rb
306
+ - spec/support/fixtures/code_generator_2/templates/default/README_md.erb
287
307
  - spec/support/fixtures/lib/chef_gen/flavor/bar.rb
288
308
  - spec/support/fixtures/lib/chef_gen/flavor/baz.rb
289
309
  - spec/support/fixtures/lib/chef_gen/flavor/foo.rb
data/Gemfile.lock DELETED
@@ -1,242 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- chef-gen-flavors (0.3.0.20150514061941)
5
- bogo-ui (~> 0.1)
6
- little-plugger (~> 1.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- ast (2.0.0)
12
- astrolabe (1.3.0)
13
- parser (>= 2.2.0.pre.3, < 3.0)
14
- bogo (0.1.22)
15
- hashie
16
- multi_json
17
- bogo-ui (0.1.10)
18
- bogo
19
- command_line_reporter
20
- paint
21
- builder (3.2.2)
22
- celluloid (0.16.0)
23
- timers (~> 4.0.0)
24
- chef (12.3.0)
25
- chef-zero (~> 4.1)
26
- diff-lcs (~> 1.2, >= 1.2.4)
27
- erubis (~> 2.7)
28
- ffi-yajl (>= 1.2, < 3.0)
29
- highline (~> 1.6, >= 1.6.9)
30
- mixlib-authentication (~> 1.3)
31
- mixlib-cli (~> 1.4)
32
- mixlib-config (~> 2.0)
33
- mixlib-log (~> 1.3)
34
- mixlib-shellout (>= 2.0.0.rc.0, < 3.0)
35
- net-ssh (~> 2.6)
36
- net-ssh-multi (~> 1.1)
37
- ohai (~> 8.0)
38
- plist (~> 3.1.0)
39
- pry (~> 0.9)
40
- rspec-core (~> 3.2)
41
- rspec-expectations (~> 3.2)
42
- rspec-mocks (~> 3.2)
43
- rspec_junit_formatter (~> 0.2.0)
44
- serverspec (~> 2.7)
45
- specinfra (~> 2.10)
46
- chef-dk (0.5.1)
47
- chef (~> 12.0, >= 12.2.1)
48
- cookbook-omnifetch (~> 0.2)
49
- diff-lcs (~> 1.0)
50
- ffi-yajl (~> 1.0)
51
- mixlib-cli (~> 1.5)
52
- mixlib-shellout (>= 2.0.0.rc.0, < 3.0.0)
53
- paint (~> 1.0)
54
- solve (~> 1.2)
55
- chef-zero (4.2.1)
56
- ffi-yajl (>= 1.1, < 3.0)
57
- hashie (~> 2.0)
58
- mixlib-log (~> 1.3)
59
- rack
60
- uuidtools (~> 2.1)
61
- coderay (1.1.0)
62
- colored (1.2)
63
- colorize (0.7.7)
64
- command_line_reporter (3.3.5)
65
- colored (>= 1.2)
66
- cookbook-omnifetch (0.2.1)
67
- minitar (~> 0.5.4)
68
- dep-selector-libgecode (1.0.2)
69
- dep_selector (1.0.3)
70
- dep-selector-libgecode (~> 1.0)
71
- ffi (~> 1.9)
72
- diff-lcs (1.2.5)
73
- docile (1.1.5)
74
- erubis (2.7.0)
75
- ffi (1.9.8)
76
- ffi-yajl (1.4.0)
77
- ffi (~> 1.5)
78
- libyajl2 (~> 1.2)
79
- formatador (0.2.5)
80
- guard (2.12.5)
81
- formatador (>= 0.2.4)
82
- listen (~> 2.7)
83
- lumberjack (~> 1.0)
84
- nenv (~> 0.1)
85
- notiffany (~> 0.0)
86
- pry (>= 0.9.12)
87
- shellany (~> 0.0)
88
- thor (>= 0.18.1)
89
- guard-compat (1.2.1)
90
- guard-rake (0.0.10)
91
- guard
92
- rake
93
- guard-rspec (4.5.0)
94
- guard (~> 2.1)
95
- guard-compat (~> 1.1)
96
- rspec (>= 2.99.0, < 4.0)
97
- guard-rubocop (1.2.0)
98
- guard (~> 2.0)
99
- rubocop (~> 0.20)
100
- hashie (2.1.2)
101
- highline (1.7.2)
102
- hirb (0.7.3)
103
- hitimes (1.2.2)
104
- hoe (3.13.1)
105
- rake (>= 0.8, < 11.0)
106
- hoe-gemspec (1.0.0)
107
- hoe (>= 2.2.0)
108
- ipaddress (0.8.0)
109
- json (1.8.2)
110
- libyajl2 (1.2.0)
111
- listen (2.10.0)
112
- celluloid (~> 0.16.0)
113
- rb-fsevent (>= 0.9.3)
114
- rb-inotify (>= 0.9)
115
- little-plugger (1.1.3)
116
- lumberjack (1.0.9)
117
- method_source (0.8.2)
118
- mime-types (2.5)
119
- minitar (0.5.4)
120
- mixlib-authentication (1.3.0)
121
- mixlib-log
122
- mixlib-cli (1.5.0)
123
- mixlib-config (2.1.0)
124
- mixlib-log (1.6.0)
125
- mixlib-shellout (2.0.1)
126
- multi_json (1.11.0)
127
- nenv (0.2.0)
128
- net-scp (1.2.1)
129
- net-ssh (>= 2.6.5)
130
- net-ssh (2.9.2)
131
- net-ssh-gateway (1.2.0)
132
- net-ssh (>= 2.6.5)
133
- net-ssh-multi (1.2.1)
134
- net-ssh (>= 2.6.5)
135
- net-ssh-gateway (>= 1.2.0)
136
- notiffany (0.0.6)
137
- nenv (~> 0.1)
138
- shellany (~> 0.0)
139
- ohai (8.3.0)
140
- ffi (~> 1.9)
141
- ffi-yajl (>= 1.1, < 3.0)
142
- ipaddress
143
- mime-types (~> 2.0)
144
- mixlib-cli
145
- mixlib-config (~> 2.0)
146
- mixlib-log
147
- mixlib-shellout (~> 2.0)
148
- rake (~> 10.1)
149
- systemu (~> 2.6.4)
150
- wmi-lite (~> 1.0)
151
- paint (1.0.0)
152
- parser (2.2.2.2)
153
- ast (>= 1.1, < 3.0)
154
- plist (3.1.0)
155
- powerpack (0.1.1)
156
- pry (0.10.1)
157
- coderay (~> 1.1.0)
158
- method_source (~> 0.8.1)
159
- slop (~> 3.4)
160
- rack (1.6.1)
161
- rainbow (2.0.0)
162
- rake (10.4.2)
163
- rb-fsevent (0.9.4)
164
- rb-inotify (0.9.5)
165
- ffi (>= 0.5.0)
166
- rdoc (4.2.0)
167
- json (~> 1.4)
168
- rspec (3.2.0)
169
- rspec-core (~> 3.2.0)
170
- rspec-expectations (~> 3.2.0)
171
- rspec-mocks (~> 3.2.0)
172
- rspec-core (3.2.3)
173
- rspec-support (~> 3.2.0)
174
- rspec-expectations (3.2.1)
175
- diff-lcs (>= 1.2.0, < 2.0)
176
- rspec-support (~> 3.2.0)
177
- rspec-its (1.2.0)
178
- rspec-core (>= 3.0.0)
179
- rspec-expectations (>= 3.0.0)
180
- rspec-mocks (3.2.1)
181
- diff-lcs (>= 1.2.0, < 2.0)
182
- rspec-support (~> 3.2.0)
183
- rspec-support (3.2.2)
184
- rspec_junit_formatter (0.2.2)
185
- builder (< 4)
186
- rspec-core (>= 2, < 4, != 2.12.0)
187
- rubocop (0.31.0)
188
- astrolabe (~> 1.3)
189
- parser (>= 2.2.2.1, < 3.0)
190
- powerpack (~> 0.1)
191
- rainbow (>= 1.99.1, < 3.0)
192
- ruby-progressbar (~> 1.4)
193
- ruby-progressbar (1.7.5)
194
- semverse (1.2.1)
195
- serverspec (2.15.0)
196
- multi_json
197
- rspec (~> 3.0)
198
- rspec-its
199
- specinfra (~> 2.31)
200
- shellany (0.0.1)
201
- simplecov (0.10.0)
202
- docile (~> 1.1.0)
203
- json (~> 1.8)
204
- simplecov-html (~> 0.10.0)
205
- simplecov-console (0.2.0)
206
- colorize
207
- hirb
208
- simplecov
209
- simplecov-html (0.10.0)
210
- slop (3.6.0)
211
- solve (1.2.1)
212
- dep_selector (~> 1.0)
213
- semverse (~> 1.1)
214
- specinfra (2.31.0)
215
- net-scp
216
- net-ssh
217
- systemu (2.6.5)
218
- thor (0.19.1)
219
- timers (4.0.1)
220
- hitimes
221
- uuidtools (2.1.5)
222
- wmi-lite (1.0.0)
223
- yard (0.8.7.6)
224
-
225
- PLATFORMS
226
- ruby
227
-
228
- DEPENDENCIES
229
- chef-dk (~> 0.5)
230
- chef-gen-flavors!
231
- guard (~> 2.12)
232
- guard-rake (~> 0.0)
233
- guard-rspec (~> 4.2)
234
- guard-rubocop (~> 1.2)
235
- hoe (~> 3.13)
236
- hoe-gemspec (~> 1.0)
237
- rake (~> 10.3)
238
- rdoc (~> 4.0)
239
- rspec (~> 3.1)
240
- simplecov (~> 0.9)
241
- simplecov-console (~> 0.2)
242
- yard (~> 0.8)