-
Notifications
You must be signed in to change notification settings - Fork 170
Add chefspec to generators #266
Add chefspec to generators #266
Conversation
- 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
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. |
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. |
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') |
There was a problem hiding this comment.
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.
Patch is generally fine, with the exception of passing data in via |
- 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
👍 this is awesome! |
paging @sersut. could we include this in the next chef-dk release? |
Add chefspec to generators
* These were added in 0.3.6 via chef-boneyard#266
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.