Questions tagged [chefspec]

ChefSpec is a unit testing framework for testing Chef cookbooks. ChefSpec makes it easy to write examples and get fast feedback on cookbook changes without the need for virtual machines or cloud servers.

ChefSpec runs your cookbook locally using Chef Solo without actually converging a node. This has two primary benefits:

  • It's really fast!
  • Your tests can vary node attributes, operating systems, and search results to assert behavior under varying conditions.

You can install ChefSpec from Rubygems:

gem install chefspec

Or add it to your Gemfile

gem 'chefspec'

Additional Resources/Links

135 questions
0
votes
1 answer

Create chef recipe by passing values dynamically, from properties file

I created a chef recipe which has the installation of a specific rpm mentioned in it. This rpm has a version number which needs to be loaded dynamically from a properties file (which is itself created dynamically). This chef recipe then needs to be…
Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
0
votes
1 answer

ChefSpec counting resources from included recipe

I have a Chef cookbook (cookbook_alpha::default) that includes another cookbook (cookbook_bravo::default) using include_recipe 'cookbook_bravo::default'. When I'm testing cookbook_alpha using ChefSpec, all of the resources in cookbook_alpha are…
Jacques Betancourt
  • 2,652
  • 3
  • 18
  • 19
0
votes
1 answer

RSpec: undefined method `require_rspec_core' for RSpec::Support:Module (NoMethodError)

I am trying to get a HelloWorld type example running with ChefSpec. I ran $ chef generate cookbook learn_chef2 to generate a Chef cookbook with the proper directory structure. I then created a super simple Chef recipe in default.rb: package…
joeglin2000
  • 85
  • 2
  • 6
0
votes
2 answers

Chef: How to test that a node attribute is not stored on Chef Server?

After some chef zero runs (which save the node state as local .json files) I was dismayed to find this in the node files: ... "ssmtp": { "auth_username": "secret user name", "auth_password": "even-more-secret password" …
Tom Wilson
  • 797
  • 9
  • 26
0
votes
1 answer

Best Practices: Testing Chefspecs that use Berkshelf in Jenkins

I want to integrate my ChefSpecs with Jenkins in a way that there is one Jenkins job that runs all specs of all cookbooks and prints one summary. Unfortunately that doesn't seem as easy as I have thought. Writing a simple Rakefile that creates a…
Stefan Marbury
  • 187
  • 1
  • 13
0
votes
2 answers

CHEF: Generate and register node_name

I'm very new to Chef and I don't know how to I can generate and register new node_name. Here what I did: 1) sign up an account at Chef https://manage.chef.io/login and login 2) let's say I have an organization 3) on Chef UI portal, click on…
Nam Nguyen
  • 5,668
  • 14
  • 56
  • 70
0
votes
1 answer

Chefspec and stubbing shell_out commands

I've written a library method in my cookbook which would read the /etc/fstab file and modify it if there are certain options missing for mounts. When I try to write Chefspec tests, they all fail to returns the stubbed information, but rather read…
Tabiko
  • 353
  • 1
  • 3
  • 8
0
votes
1 answer

Chefspec delete file with windowslike path

Im trying to write test for file deletion: test/recipes/default.rb file 'C:/temp/1.txt' do action :delete end cat spec/default_spec.rb require_relative 'spec_helper' describe 'test::default' do #before do # allow(File).to…
user3484021
  • 27
  • 1
  • 10
0
votes
1 answer

rspec-expectations-2.99.0/lib/rspec/matchers/built_in/raise_error.rb:5: uninitialized constant RSpec::Matchers::BuiltIn::RaiseError::MatchAliases

Output error from running rspec in my cookbook directory. C:\Users\a540409\IdeaProjects\stores-v2\chef>bundle exec rspec C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-expectations-2.99.0/lib/rspec/matchers/built_in/raise_error.rb:5:in…
0
votes
0 answers

issues with multiple cookbook paths in chefspec

Some of my cookbooks are in cookbooks-org folder and some are in cookbooks folder. When I am trying to run the spec, I am getting an error saying cookbook not found for one of the cookbook. In the below case, cookbook is present in cookbook-org and…
bondy
  • 1
0
votes
1 answer

Mocking out file contents in ChefSpec

I have a chef cookbook which copies the ubutunu user's (default user of the amazon AMI am using) authorized keys file to a newly created user. ubuntu_public_key_file = "/home/ubuntu/.ssh/authorized_keys" file…
DheeDaOx
  • 3
  • 1
  • 2
-1
votes
1 answer

Chefspec unit-testing

I'm no developer and a newbie with Chef. I created a simple recipe and tested it on a test Kitchen and it works well but when I upload it to Jenkins it won't pass. Can you help me point out what I'm missing? Recipe: # Recipe:: default # Download…
greenovia
  • 1
  • 1
-1
votes
1 answer

how do i include non chef resources using chefspec

i want to write chefspec for one of the recipe which has the code to create jenkins user as shown below. jenkins_user 'test1' do full_name 'test user' email 'test1@test.com' password 'testp' end Here …
bbsys
  • 33
  • 1
  • 8
-2
votes
1 answer

Registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL does not exist error in chefspec

My recipe: instance_names.each do |instance_name| instance_name_service=instance_name.split('.')[1] instance_name_service = instance_name_service == 'MSSQLSERVER'? 'MSSQLSERVER' : "MSSQL$#{instance_name_service}" …
-3
votes
1 answer

Chefspec tests for windows machines

My chef workstation is on an ubuntu 16.04 machine. Can I run chefSpec tests on my ubuntu workstation for recipes that are intended for windows machines. I know that we can specify the "platform" and "version" in the chefspec test recipe. My question…
1 2 3
8
9