Cookbooks can also get the same red, green, refactor loop going the same way you would with a simple application. It's not all roses though because the loop itself takes a few minutes at a time. Even with a simple cookbook, you're looking at 3-4 minutes each run if you're constantly testing using converges.
In terms of the fastest feedback loops, you should:
- Use Chefspec to test that you're telling chef the correct things to do. These will run in a few seconds.
- Use Serverspec that chef did what you told it to. This will take 3-4 minutes using a container.
Adding Chefspec
spec/spec_helper.rb
require 'chefspec'
RSpec.configure do |config|
config.mock_with :rspec do |mocks|
mocks.syntax = :expect
end
config.platform = 'ubuntu'
config.version = '14.04'
end
spec/recipes/default_spec.rb
require 'spec_helper'
describe 'hello-world-cookbook::default' do
let(:chef_run) {
ChefSpec::SoloRunner.new.converge(described_recipe)
}
it 'installs a file' do
expect(chef_run).to create_file('/tmp/foobar')
end
end
Run bundle exec rspec spec
to start executing Chefspec tests. You'll see the failing test. Fix it by updating recipes/default.rb
to create a file with content and watch it go green.
How not to use ChefSpec
it 'creates file' do
expect(File.new('/tmp/foobar').exists?).to be_truthy
end
This won't work because the chef run only happens in memory as part of chefspec. No changes are actually made to the system. If you're running rspec from your terminal, then the chef run happens in memory on your system on your current OS. When you want to do this type of testing, it's easier to test this stuff in Serverspec.
Adding Serverspec
Add the following files
test/integration/default/serverspec/spec_helper.rb
require 'serverspec'
set :backend, :exec
test/integration/default/serverspec/default_spec.rb
require 'spec_helper'
describe file('/tmp/foobar') do
it { should be_readable.by_user('root') }
it { should contain('foo')}
end
Now run bundle exec kitchen verify
. test-kitchen will update the container with the new cookbook, execute the cookbook inside the container, upload the test runner inside the container, and then execute the tests. This is a great way to test modifications to the system like if files exist with the correct permissions.
Lint your cookbook
Add rubocop & foodcritic to your project by adding it to your Gemfile,
gem 'rubocop'
gem 'foodcritic'
Rubocop will sniff out smelly parts of your ruby. It occasionally gives you good advice and can be helpful to keep consistent styling. It does need to be tuned lest it constantly complain about long lines.
Run 'bundle exec rubocop' to see what it complains about out of the box. Things like Style/FrozenStringLiteralComment
are just not useful.
Foodcritic will look for Chef specific errors in your cookbook. Like if you meant to render a template but forgot to include the template file.
Some of the stuff it complains about I don't care for, so you can always ignore some by adding --tags ~RULE#
to your command. You can see what it complains about out of the box by running bundle exec foodcritic ./
.
Most of its initial complaints are about fields you should have in your metadata to be a good Chef citizen publishing open-source cookbooks. If you're using them in a private setting, then its just boilerplate.
You've now got an entire development flow for your configuration.
- Build the cookbook by running
kitchen converge
- Unit test your Chef logic by running
rspec spec
with Chefspec - Run an Integration Test by actually running Chef on the target container
- Lint your cookbook to keep it close to ruby best practices and to catch obvious Chef errors.
Stay tuned for Part 3 where we tie this into a CI workflow.
135 Comments. Leave new
Excellent article! We will be linking to this particularly great article on our website. Keep up the good writing. rainews24
My colleague shared your article with me and I found it very useful after reading it. Great article, it helped me a lot. I also hope to make a beautiful website like your blog, hope you can give me some advice, my website:
elongate on binance
Reading your article helped me a lot, but I still had some doubts at the time, could I ask you for advice? Thanks.
For my thesis, I consulted a lot of information, read your article made me feel a lot, benefited me a lot from it, thank you for your help. Thanks!
I have read your article carefully and I agree with you very much. So, do you allow me to do this? I want to share your article link to my website: gate io
Nice post. I learn something new and challenging on blogs I stumbleupon on a daily basis. one tv racing
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me? https://www.gate.io/es/signup/XwNAU
Can you be more specific about the content of your enticle? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/en/register?ref=P9L9FQKY
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me? https://www.gate.io/fr/signup/XwNAU
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me? https://www.gate.io/fr/signup/XwNAU
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.com/lv/register?ref=B4EPR6J0
The Elitepipe Plastic Factory’s manufacturing facilities are equipped with state-of-the-art machinery, enabling efficient production processes and consistent product quality. Elitepipe Plastic Factory
تم تصميم تركيبات إيليت بايب Elite Pipe لتكون سهلة الاستخدام ، مما يسهل التثبيت السهل ويضمن صيانة خالية من المتاعب طوال عمرها الافتراضي.
ElitePipe Plastic Factory is your ultimate destination for top-quality plastic piping solutions in Iraq. We take immense pride in offering a comprehensive range of products and services tailored to meet your diverse needs. Here’s what we have to offer: 🌊 HDPE Pipes: Our High-Density Polyethylene (HDPE) pipes are engineered for reliable water supply, irrigation, and industrial applications. With exceptional durability and corrosion resistance, they are built to withstand the toughest conditions. 🏢 UPVC Pipes: Unplasticized Polyvinyl Chloride (UPVC) pipes are the ideal choice for sewerage, drainage, and plumbing systems. These rigid pipes ensure long-lasting performance and efficient wastewater management. 🌾 Agriculture Pipes: We provide high-quality pipes specifically designed for agricultural purposes. Our range includes LDPE pipes for drip irrigation, ensuring optimal water conservation and improved crop yield. 💡 HDPE Cable Ducts: Designed for the telecommunications industry, our HDPE cable ducts offer reliable protection for underground cables. With excellent impact resistance and flexibility, they ensure seamless cable installation. 🔩 Welding Machines: Our advanced Butt Welding Machines and Electrofusion Welding EF Machines guarantee precise and secure connections, making installation hassle-free and efficient. 🔌 Fittings and Electrofusion Fittings: We offer a wide selection of fittings compatible with our piping systems, ensuring leak-proof joints and seamless integration. Our electrofusion fittings provide a reliable and efficient method of connecting pipes. 🌱 Sprinkler Pipes: For efficient irrigation systems, our sprinkler pipes deliver uniform water distribution, helping you maintain lush green landscapes and maximize water efficiency. 🏭 GRP Pipes: Our Glass Reinforced Plastic (GRP) pipes are the preferred choice for industrial applications, offering excellent resistance to corrosion and high-pressure environments. ⚙️ Valves: We provide a range of valves engineered for precision control and efficient flow management, ensuring smooth operation and reliable performance. At Elite Pipe Plastic Factory, we are committed to delivering exceptional quality, reliable products, and excellent customer service. Trust us to be your partner in building a sustainable future. Contact us today to explore our product range and experience our industry-leading solutions! 🌟
With a focus on excellence, Elitepipe Plastic Factory has gained a reputation for producing top-notch HDPE and uPVC products that meet rigorous quality standards. Elitepipe Plastic Factory
مع التركيز على التميز ، اكتسب مصنع إيليت بايب Elite Pipe سمعة طيبة في إنتاج منتجات HDPE و uPVC عالية الجودة التي تلبي معايير الجودة الصارمة.
The Elitepipe Plastic Factory’s manufacturing facilities are equipped with state-of-the-art machinery, enabling efficient production processes and consistent product quality. Elitepipe Plastic Factory
Elitepipe Plastic Factory’s commitment to customer satisfaction is evident in their prompt delivery schedules and exceptional after-sales service. Elitepipe Plastic Factory
I like the efforts you have put in this, regards for all the great content.
مع التركيز على التميز ، اكتسب مصنع إيليت بايب Elite Pipe سمعة طيبة في إنتاج منتجات HDPE و uPVC عالية الجودة التي تلبي معايير الجودة الصارمة.
Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Elitepipe Plastic Factory’s fittings undergo rigorous quality control processes to ensure that they meet the most stringent performance and durability requirements. Elitepipe Plastic Factory
Pretty! This has been a really wonderful post. Many thanks for providing these details.
مع التركيز على التميز ، اكتسب مصنع إيليت بايب Elite Pipe سمعة طيبة في إنتاج منتجات HDPE و uPVC عالية الجودة التي تلبي معايير الجودة الصارمة.
إن تركيبات uPVC التي ينتجها مصنع إيليت بايب Elite Pipe مقاومة للغاية للتآكل ، وتوفر حلولاً موثوقة وخالية من الصيانة لأنظمة الري والسباكة.
Your article gave me a lot of inspiration, I hope you can explain your point of view in more detail, because I have some doubts, thank you.
Your article gave me a lot of inspiration, I hope you can explain your point of view in more detail, because I have some doubts, thank you.
Your article gave me a lot of inspiration, I hope you can explain your point of view in more detail, because I have some doubts, thank you.
Thank you very much for sharing, I learned a lot from your article. Very cool. Thanks. nimabi
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.com/pt-PT/register?ref=V3MG69RO
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.com/id/join?ref=W0BCQMF1
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Love this appreciation for great content
Let’s spread the love! Tag a friend who would appreciate this post as much as you did.
Let me know what type of content you’d like to see more of in the future!
What type of content would you like to see more of in the future? Let us know in the comments!
Your blog post was fantastic, thanks for the great content!
This blog post is worth the read – trust us!
From start to finish, this blog post had us hooked. The content was insightful, entertaining, and had us feeling grateful for all the amazing resources out there. Keep up the great work!
Drop a link to your favorite blog post of yours in the comments below, I’d love to read more.
Let’s spread the love! Tag a friend who would appreciate this post as much as you did.
I couldn’t stop scrolling and reading, your content is truly one-of-a-kind. Thank you for all the time and effort you put into creating such amazing content.
Keep up the amazing work!
Your blog posts never fail to entertain and educate me. I especially enjoyed the recent one about [insert topic]. Keep up the great work!
Wow, this blogger is seriously impressive!
Their posts always leave us feeling informed and entertained. We’re big fans of their style and creativity.
From start to finish, your content is simply amazing. You have a talent for making complex topics easy to understand and I always come away with valuable insights.
Every time I read a new post, I feel like I’ve learned something valuable or gained a new perspective. Thank you for consistently putting out such great content!
Every time I read a new post, I feel like I’ve learned something valuable or gained a new perspective. Thank you for consistently putting out such great content!
Your content always manages to captivate and educate me. Keep up the fantastic work!
Keep up the fantastic work and continue to inspire us all!
I can’t get enough of your insightful articles and engaging stories. Thank you for sharing your passion with the world!
I want to express my appreciation for the writer of this blog post. It’s clear they put a lot of effort and thought into their work, and it shows. From the informative content to the engaging writing style, I thoroughly enjoyed reading it.
I want to express my appreciation for the writer of this blog post. It’s clear they put a lot of effort and thought into their work, and it shows. From the informative content to the engaging writing style, I thoroughly enjoyed reading it.
I want to express my appreciation for the writer of this blog post. It’s clear they put a lot of effort and thought into their work, and it shows. From the informative content to the engaging writing style, I thoroughly enjoyed reading it.
Love this appreciation for great content
This blog post has left us feeling grateful and inspired
This blog post has left us feeling grateful and inspired
This blog post is packed with great content!
Looking forward to your next post. Keep up the good work!
Keep up the amazing work! Can’t wait to see what you have in store for us next.
Keep up the fantastic work and continue to inspire us all!
Every time I read one of your posts, I come away with something new and interesting to think about. Thanks for consistently putting out such great content!
Your blog posts never fail to entertain and educate me. I especially enjoyed the recent one about [insert topic]. Keep up the great work!
I can’t get enough of your insightful articles and engaging stories. Thank you for sharing your passion with the world!
We just wanted to take a moment to acknowledge all the hard work and effort you’ve been putting in lately. Keep up the amazing job, you’re doing great!
I just wanted to take a moment to say how much I appreciate your blog posts. They’re always well-written, informative, and keep me coming back for more. Keep up the great work!
Wow, this blogger is seriously impressive!
Your blog post had me hooked from the very beginning!
Your blog posts never fail to entertain and educate me. I especially enjoyed the recent one about [insert topic]. Keep up the great work!
It’s always a joy to stumble upon content that genuinely makes an impact and leaves you feeling inspired. Keep up the great work!
From the insightful commentary to the captivating writing, every word of this post is top-notch. Kudos to the author for producing such fantastic content.
Leave a comment and let us know what your favorite blog post has been so far!
From start to finish, this blog post had us hooked. The content was insightful, entertaining, and had us feeling grateful for all the amazing resources out there. Keep up the great work!
This blog post is packed with great content!
It means so much to receive positive feedback and know that my content is appreciated. I strive to bring new ideas and insights to my readers.
From the insightful commentary to the captivating writing, every word of this post is top-notch. Kudos to the author for producing such fantastic content.
Your words have resonated with us and we can’t wait to read more of your amazing content. Thank you for sharing your expertise and passion with the world.
From start to finish, your content is simply amazing. You have a talent for making complex topics easy to understand and I always come away with valuable insights.
From start to finish, your content is simply amazing. You have a talent for making complex topics easy to understand and I always come away with valuable insights.
Keep up the amazing work!
Thank you for creating such valuable content. Your hard work and dedication are appreciated by so many.
Your blog post was fantastic, thanks for the great content!
I appreciate the effort that goes into creating high-quality content, and this post was no exception. The insights and information were top-notch and made for a really engaging read. Keep up the great work!
This blog post has left us feeling grateful and inspired
It means so much to receive positive feedback and know that my content is appreciated. I strive to bring new ideas and insights to my readers.
Your blog post had me hooked from the very beginning!
Love this appreciation for great content
Your blog is always a highlight of my day
Their posts always leave us feeling informed and entertained. We’re big fans of their style and creativity.
Your blog post had me hooked from the very beginning!
I couldn’t stop scrolling and reading, your content is truly one-of-a-kind. Thank you for all the time and effort you put into creating such amazing content.
I can’t get enough of your insightful articles and engaging stories. Thank you for sharing your passion with the world!
Thank you for the amazing blog post!
Your blog post had me hooked from the very beginning!
We just wanted to take a moment to acknowledge all the hard work and effort you’ve been putting in lately. Keep up the amazing job, you’re doing great!
Keep up the fantastic work!
Keep up the incredible work! I can’t wait to see what you write next.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
What type of content would you like to see more of in the future? Let us know in the comments!
Let us know in the comments which of their posts has resonated with you the most.
Let me know what type of content you’d like to see more of in the future!
Looking forward to your next post. Keep up the good work!
Leave a comment and let us know what your favorite blog post has been so far!
Your blog posts never fail to entertain and educate me. I especially enjoyed the recent one about [insert topic]. Keep up the great work!
Every time I read a new post, I feel like I’ve learned something valuable or gained a new perspective. Thank you for consistently putting out such great content!
Your blog is always a highlight of my day
Your blog posts never fail to entertain and educate me. I especially enjoyed the recent one about [insert topic]. Keep up the great work!
Your writing style is so engaging and easy to follow I find myself reading through each post without even realizing I’ve reached the end
It’s clear that you have a deep understanding of this topic and your insights and perspective are invaluable Thank you for sharing your knowledge with us
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
The point of view of your article has taught me a lot, and I already know how to improve the paper on gate.oi, thank you.
Thank you very much for sharing, I learned a lot from your article. Very cool. Thanks.
Thank you very much for sharing, I learned a lot from your article. Very cool. Thanks.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
HDPE Pipes : High-density polyethylene pipes are known for flexibility and durability in pressure systems. ElitePipe Factory in Iraq specializes in manufacturing HDPE pipes.
Corrugated Metal Pipes : These durable, flexible pipes are commonly used for culverts and drainage systems. ElitePipe Factory in Iraq provides top-quality corrugated metal pipes.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your shening. I am worried that I lack creative ideas. It is your enticle that makes me full of hope. Thank you. But, I have a question, can you help me?
gluco6 reviews : https://gluco6reviews.usaloves.com/
gluco6 reviews : https://gluco6reviews.usaloves.com/
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/ru/register?ref=V3MG69RO
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!
Your article helped me a lot, is there any more related content? Thanks!