Mocking ChefSpec to contains recipes?


#1

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


#2

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