Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Add chefspec to generators #266

Merged
merged 6 commits into from
Jan 9, 2015
Merged

Add chefspec to generators #266

merged 6 commits into from
Jan 9, 2015

Conversation

charlesjohnson
Copy link
Contributor

Any recipe generated by chef generate should now also automatically have a corresponding spec file template generated in spec/unit/recipes. In addition, a spec/spec_helper.rb file will be created if one does not currently exist.

I also consolidated the redundant template/recipe.rb and template/default_recipe.rb files for easier maintenance.

Charles Johnson added 4 commits December 9, 2014 18:20
- Deleted files/converge_spec.rb from generator cookbook
- Updated files/spec_helper.rb in generator cookbook
- Added templates/recipe_spec.rb.erb to generator cookbook
- Updated cookbook_spec.rb to check for Chefspec files in generated cookbooks
- Updated cookbook.rb in generator to create Chefspec skeleton files
- Update recipe generator to create Chefspec files
- Updated recipe_spec.rb to ensure that Chefspec files are created
- Updated app.rb to generate Chefspec files
- Updated app_spec.rb to test existence & content of Chefspec files
Replaced references to templates/default_recipe.rb.erb with references to templates/recipe.rb.erb in the following generators:
- app.rb
- recipe.rb
- cookbook.rb

Deleted templates/default_recipe.rb.erb
@danielsdeleo
Copy link
Contributor

Quick question, is it worth adding a flag to disable test generation? On the one hand, I definitely want ChefDK to subtly encourage you on the "good path" by generating this stuff, but on the other hand we lose a little bit of the simplicity we had before each time we add a new thing that we generate by default.

@charlesjohnson
Copy link
Contributor Author

I thought about it a lot, but decided not to feature flag the functionality. If we're going to be opinionated on this by shipping Chefspec & rspec in the DK, then I think we should go all-in and embrace it in the generator too.

If a user doesn't want the files, they can gitignore the spec directory and be done with it.

@danielsdeleo
Copy link
Contributor

Fair enough. My other sort of concern is that we're making these very berks-y, but I'm not enough of a ChefSpec expert to know if there's an agnostic way to create these. And of course once Policyfiles become the recommended path, we'll have to change everything, but that's something we already know we're gonna have to do.

helpers(ChefDK::Generator::TemplateHelper)
variables(
:recipe_name => 'default')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be available via methods in TemplateHelper. We're explicitly avoiding passing in variables to the templates.

@danielsdeleo
Copy link
Contributor

Patch is generally fine, with the exception of passing data in via variables in templates. We're using the TemplateHelper to define these as methods in the template context so we can prevent repetition of variables attributes in template resources.

- Updated app_spec.rb to check the generator context for recipe_name
- Updated cookbook_spec.rb to check the generator context for recipe_name
- Updated spec shared/a_file_generator.rb to check the generator context for recipe_name
- Added recipe_name to generator context in generator_commands/app.rb
- Added recipe_name to generator context in generator_commands/cookbook.rb
- Added recipe_name to generator context in generator_commands/cookbook_code_file.rb
- Removed variable insertion from app.rb recipe in skeleton cookbook
- Removed variable insertion from cookbook.rb recipe in skeleton cookbook
- Removed variable insertion from recipe.rb recipe in skeleton cookbook
- Updated recipe_spec.rb.erb template to use recipe_name from generator context
- Updated recipe.rb.erb template to use recipe_name from generator context
@nathenharvey
Copy link
Contributor

👍 this is awesome!

@yvovandoorn
Copy link

paging @sersut. could we include this in the next chef-dk release?

charlesjohnson added a commit that referenced this pull request Jan 9, 2015
@charlesjohnson charlesjohnson merged commit 6d3da5a into chef-boneyard:master Jan 9, 2015
nathenharvey pushed a commit to nathenharvey/chef-dk that referenced this pull request Feb 6, 2015
@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants