1

I am trying to test that linux-image-extra-#{node['kernel']['release']} will be installed by my cookbook and I'm trying to mock up #{node['kernel']['release'] using Fauxhai. So far I have;

    describe 'my-cookbook::recipe' do
      let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04').converge(described_recipe) }   

      before do
            Fauxhai.mock(platform: 'ubuntu', version: '14.04') do |node|
              node['kernel']['release'] = '3.13.0-66'
            end
          end

        it 'installs linux extra image package do'
            expect(chef_run).to install_package("linux-image-extra-#{node['kernel']['release']}-generic")
        end
    end

Unfortunately It isn't picking up the attribute and is producing an error that shows this;

Failure/Error: expect(chef_run).to install_package("linux-image-extra-#{node['kernel']['release']}-generic")

Ste-3PO
  • 1,165
  • 1
  • 9
  • 18

1 Answers1

0

The way you set platform data from Fauxhai with ChefSpec is to pass a platform and version option to the Solo/ServerRunner constructor.

let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04').converge(described_recipe) }

More to the point, you are using == when you mean =. Fix all of the above. Also you need to specify a level when setting a node attribute. But really just use the Fauxhai data for now.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thanks for your reply. I have that already in my test; sorry I should have included that in my question. I'll update it now. – Ste-3PO Sep 27 '16 at 10:42