Chefspec + Berksfile - Cookbook not found

Ohai Chefs,

I’m trying to TDD a cookbook for my company’s website. I’m using Berksfile to manage cookbook dependencies and I’m trying to get Chefspec to work.

Converging the cookbook on a VM works just fine, but when I run rspec I get a Cookbook not found error.

There’s additional information on this gist: https://gist.github.com/4072082

Do I need to require something from berkshelf in the specs? I tried including require ‘berkshelf’ at the top of the recipe to no avail.

Appreciate your thoughts/guidance.

Thanks!

Cassiano Leal

Hey Cassiano,

It looks like you're attempting to test on your own machine - this will be a problem. We generally use Vagrant virtual machines to test our cookbooks.

The reason your cookbook is not found is because the cookbook_path attribute in your machines Knife config does not contain the path to the cookbook you are testing.

Berkshelf will automatically make the cookbooks acailable to your Vagrant VM so you could run your specs within the Vagrant VM.

There is also the Test-Kitchen approach which I would recommend you looking into!

Jamie Winsor
@resetexistence

On Nov 19, 2012, at 5:53 AM, Cassiano Leal cassianoleal@gmail.com wrote:

Ohai Chefs,

I'm trying to TDD a cookbook for my company's website. I'm using Berksfile to manage cookbook dependencies and I'm trying to get Chefspec to work.

Converging the cookbook on a VM works just fine, but when I run rspec I get a Cookbook not found error.

There's additional information on this gist: https://gist.github.com/4072082

Do I need to require something from berkshelf in the specs? I tried including require 'berkshelf' at the top of the recipe to no avail.

Appreciate your thoughts/guidance.

Thanks!

Cassiano Leal

Hi Jamie,

You're correct, I am trying to run it on my own machine. :slight_smile:

I'm definitely going to have a look into Test Kitchen (it's in my to-learn list), but I was trying to start small to learn incrementally. I can write simple cookbooks, LWRPs, etc, and TDD is my current step.

What's the best approach to running chefspec inside the Vagrant VM?

I'm guessing:

  • vagrant ssh
  • cd /vagrant
  • rspec

But that's not very CI-friendly. Is there some less manual way?

Thanks!
Cassiano

--
Cassiano Leal

On Monday, November 19, 2012 at 12:21, Jamie Winsor wrote:

Hey Cassiano,

It looks like you're attempting to test on your own machine - this will be a problem. We generally use Vagrant virtual machines to test our cookbooks.

The reason your cookbook is not found is because the cookbook_path attribute in your machines Knife config does not contain the path to the cookbook you are testing.

Berkshelf will automatically make the cookbooks acailable to your Vagrant VM so you could run your specs within the Vagrant VM.

There is also the Test-Kitchen approach which I would recommend you looking into!

Jamie Winsor
@resetexistence

On Nov 19, 2012, at 5:53 AM, Cassiano Leal <cassianoleal@gmail.com (mailto:cassianoleal@gmail.com)> wrote:

Ohai Chefs,

I'm trying to TDD a cookbook for my company's website. I'm using Berksfile to manage cookbook dependencies and I'm trying to get Chefspec to work.

Converging the cookbook on a VM works just fine, but when I run rspec I get a Cookbook not found error.

There's additional information on this gist: https://gist.github.com/4072082

Do I need to require something from berkshelf in the specs? I tried including require 'berkshelf' at the top of the recipe to no avail.

Appreciate your thoughts/guidance.

Thanks!

Cassiano Leal

Without some glue code I think that's what you'll need to do.

Jamie Winsor
@resetexistence

On Nov 19, 2012, at 9:42 AM, Cassiano Leal cassianoleal@gmail.com wrote:

Hi Jamie,

You're correct, I am trying to run it on my own machine. :slight_smile:

I'm definitely going to have a look into Test Kitchen (it's in my to-learn list), but I was trying to start small to learn incrementally. I can write simple cookbooks, LWRPs, etc, and TDD is my current step.

What's the best approach to running chefspec inside the Vagrant VM?

I'm guessing:

  • vagrant ssh
  • cd /vagrant
  • rspec

But that's not very CI-friendly. Is there some less manual way?

Thanks!
Cassiano

--
Cassiano Leal

On Monday, November 19, 2012 at 12:21, Jamie Winsor wrote:

Hey Cassiano,

It looks like you're attempting to test on your own machine - this will be a problem. We generally use Vagrant virtual machines to test our cookbooks.

The reason your cookbook is not found is because the cookbook_path attribute in your machines Knife config does not contain the path to the cookbook you are testing.

Berkshelf will automatically make the cookbooks acailable to your Vagrant VM so you could run your specs within the Vagrant VM.

There is also the Test-Kitchen approach which I would recommend you looking into!

Jamie Winsor
@resetexistence

On Nov 19, 2012, at 5:53 AM, Cassiano Leal cassianoleal@gmail.com wrote:

Ohai Chefs,

I'm trying to TDD a cookbook for my company's website. I'm using Berksfile to manage cookbook dependencies and I'm trying to get Chefspec to work.

Converging the cookbook on a VM works just fine, but when I run rspec I get a Cookbook not found error.

There's additional information on this gist: https://gist.github.com/4072082

Do I need to require something from berkshelf in the specs? I tried including require 'berkshelf' at the top of the recipe to no avail.

Appreciate your thoughts/guidance.

Thanks!

Cassiano Leal