# Mocking ChefSpec to contains recipes?

**URL:** <https://discourse.chef.io/t/mocking-chefspec-to-contains-recipes/3660>\
**Category:** Chef Infra (archive)\
**Created:** [February 22, 2013, 10:52am UTC](https://discourse.chef.io/t/mocking-chefspec-to-contains-recipes/3660 "2013-02-22T10:52:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnold\_Krille](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/arnold_krille/32/285_2.png) [@Arnold\_Krille](https://discourse.chef.io/u/Arnold_Krille)\
**Post date:** [February 22, 2013, 10:52am UTC](https://discourse.chef.io/t/mocking-chefspec-to-contains-recipes/3660/1 "2013-02-22T10:52:16Z")

</div>

Hi all,

I am trying to write chefspec tests for my backuppc-recipes. As this recipe  
should be as much self-configuring as possible, the backup client already  
detects when the node has (for example) the mysql::server recipe applied and  
then installes automysqlbackup and adds the necessary directories to the  
paths-to-backup.  
That is actually working well, but now I want to write a chefspec for that. I  
have:

require ‘chefspec’

describe ‘backuppc::client’ do  
it “should add automysqlbackup when mysql-server-cookbook is on the node” do

```
chef_run = ChefSpec::ChefRunner.new(
    :platform => 'ubuntu',
    :version => '12.04',
    :step_into => ['backuppc_sshkey']
) do |node|
  node.set['cpu']['total'] = 1
  node.set['recipes'] = ['mysql::server']
end
chef_run.converge 'backuppc::client'

chef_run.should upgrade_package 'automysqlbackup'

```

end  
end

But that test fails. How can I get chefspec/fauxhai to pretend that there are  
other recipes already applied to the node?

Have fun,

Arnold

---

<div class="post-metadata">

**Author:** ![Arnold\_Krille](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/arnold_krille/32/285_2.png) [@Arnold\_Krille](https://discourse.chef.io/u/Arnold_Krille)\
**Post date:** [February 22, 2013, 11:43am UTC](https://discourse.chef.io/t/mocking-chefspec-to-contains-recipes/3660/2 "2013-02-22T11:43:15Z")

</div>

Hi again,

On Friday 22 February 2013 11:52:16 Arnold Krille wrote:

> I am trying to write chefspec tests for my backuppc-recipes. As this recipe  
> should be as much self-configuring as possible, the backup client already  
> detects when the node has (for example) the mysql::server recipe applied and  
> then installes automysqlbackup and adds the necessary directories to the  
> paths-to-backup.  
> That is actually working well, but now I want to write a chefspec for that.  
> I have:  
>   
> But that test fails. How can I get chefspec/fauxhai to pretend that there  
> are other recipes already applied to the node?

Of course after a night of thinking, the writing of the previous mail and some  
more thinking the idea struck: Just converge with several cookbooks.

Took me another hour to get the list-argument right, but thats due to my poor  
ruby skill...

Have fun,

Arnold
