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

Test Kitchen integration tests with Chefspec: testing cookbook with dependencies

I understand that Test Kitchen follows the sequence create node > converge cookbook > run tests What is the best practice to create a test that assumes a strong external dependency? An example is the Kafka cookbook…
0
votes
1 answer

Could not find a valid gem 'fauxhai' (~> 3.2) in any repository

I am trying to install chefspec(4.6.1) along with fauxhai(3.2.0) in a cookbook. I am facing the following issue "Could not find a valid gem 'fauxhai' (~> 3.2) in any repository". I already had installed chefspec4.4.0 along with fauxhai2.3.0 in other…
pavan kumar
  • 102
  • 1
  • 2
  • 11
0
votes
2 answers

Accessing environment variable in chefSpec

I am trying to write some test for my recipe using ChefSpec. This is piece of code I am trying to test: file node[:storm][:job_dir] + node[:storm_work_gen][:jar_name] do owner node[:storm][:user] group node[:storm][:user] action :delete …
user3394555
  • 77
  • 10
0
votes
1 answer

Recipe Compile Error in /Users/saddam/cookbooks/apache/recipes/configure_apache.rb

Chef::Exceptions::ValidationFailed ---------------------------------- Option cookbook_name must be a kind of [String]! You passed :apache. Relevant File Content: ---------------------- /Users/saddam/cookbooks/apache/recipes/configure_apache.rb: …
sk. saddam
  • 33
  • 1
  • 4
0
votes
1 answer

ChefSpec unable to find cookbook

When I run my unit test case (written in ChefSpec) I get the following error: Chef::Exceptions::CookbookNotFound: Cookbook azuredns not found. If you're loading azuredns from another cook book, make sure you configure the dependency in your…
Shaffan
  • 53
  • 10
0
votes
2 answers

"uninitialized constant" on depend cookbook

I have a guard that uses a helper library from one of my cookbook dependencies. When I create a stub for this call I receive the following error during the test run: uninitialized constant Chef::Acme Stub: before(:each) do …
chief7
  • 14,263
  • 14
  • 47
  • 80
0
votes
1 answer

Expect raised error at compile time with ChefSpec

My Chef cookbook is raising a compile time error which I want to expect in a ChefSpec test. Cookbook Snippet if !windows_version.windows_server_2012_r2? error = "Not supported on this version of Windows" raise error end windows_package…
chief7
  • 14,263
  • 14
  • 47
  • 80
0
votes
1 answer

Mock Chef::ReservedNames::Win32::Version.new in Chef unit/rspec test?

I found Fauxhai works for mocking the information in "node" but it doesn't mock Chef::ReservedNames::Win32::Version.new. Is there anyway to mock this?
chief7
  • 14,263
  • 14
  • 47
  • 80
0
votes
1 answer

Verify package from node attributes was installed

I have a cookbook that installs a list of packages provided by node attributes. Is it possible to test this type of package installation with chefspec? As it is now, I receive an error: 1) foo::default installs test-package-1 Failure/Error:…
ben lemasurier
  • 2,582
  • 4
  • 22
  • 37
0
votes
1 answer

How can I test for data_bag modifications in ChefSpec?

I have a recipe that modifies a DataBag value, and I'm trying to write a test for that. The relevant part of the recipe is: def get_deployment_data(data_bag_name) data_bag_item(data_bag_name, 'deployment') end # Update master data…
Andrew Cooper
  • 32,176
  • 5
  • 81
  • 116
0
votes
1 answer

Specify Cheffile to ChefSpec Server Runner

I'm trying to add some unit tests for a cookbook of mine (say cookbook1) with ChefSpec::ServerRunner. My directory structure is as follows: mycookbooks ->cookbook1 ->->recipes ->->spec ->cookbook2 …
0
votes
1 answer

Executing chef test from a rakefile

I have some chef unit tests that I can run via the command : chef exec rspec However, I am trying to run these from TeamCity and I am using a rakefile. When I try to execute the rakefile the require 'chefspec' line in the test file causes an error…
user3464189
  • 183
  • 1
  • 1
  • 11
0
votes
1 answer

new_resource assignment in chefspec test

I'm stuck on a chefspec test which steps into my lwrp below and asserts that it creates a directory. describe 'mw-tomcat::chefspec' do let(:chef) do ChefSpec::SoloRunner.new(step_into: ['mw_tomcat_tree']) do |node| …
Edward
  • 33
  • 8
0
votes
2 answers

chefspec NoMethodError for cron_d

I have a successful resource: (converged, worked as expected) cron_d 'zk_metric' do minute '*' command “something something" end But after adding spec it 'add cron_d' do expect(chef_run).to create_cron_d('zk_metric') end chefspec got the…
digit plumber
  • 1,140
  • 2
  • 14
  • 27
0
votes
1 answer

chefspec for testing databag in recipe

I have this piece of code in my recipe now i want to write a chefspec to test the code before it is being executed on the node. I have googled for some sample spec recipe but i couldn't find anything related to databags. userlist =…
bbsys
  • 33
  • 1
  • 8
1 2 3
8
9