0

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  
    -> Cheffile

I have added require 'chefspec/librarian' to resolve the dependency cookbooks but this assumes that Cheffile is in the same directory cookbook1.

Is there a way I can specify the path of the Cheffile to ChefSpec::ServerRunner.

Hazem Abdullah
  • 1,837
  • 4
  • 23
  • 41
  • Yes, the cheffile is supposed to be in the root of your cookbook_path directory. So set cookbook_path to mycookbooks. [see here](https://github.com/sethvargo/chefspec#configuration) – Tensibai Nov 13 '15 at 13:29
  • `config.cookbook_path = 'path to mycookbooks folder'` , this is how I have tried to configure the cookbook path ( used both the relative and absolute path for this.) when I run `rspec` I get the following error. `/gems/ruby-2.2.3/gems/librarian-0.1.2/lib/librarian/dsl/receiver.rb:30:in `read': No such file or directory @ rb_sysopen - /path/to/cookbook1/Cheffile (Errno::ENOENT)` – sandeep srivastav vaddiparthy Nov 13 '15 at 18:11

1 Answers1

0

Call Dir.chdir before creating the runner object. The relevant code in ChefSpec is here and you can see it uses Dir.pwd to initialize Librarian.

coderanger
  • 52,400
  • 4
  • 52
  • 75