[chef] Re: Re: Re: chefspec and lazy


Chronological Thread 
  • From: Peter Burkholder < >
  • To:
  • Subject: [chef] Re: Re: Re: chefspec and lazy
  • Date: Wed, 22 Oct 2014 15:45:33 -0400

Joe,

Seem the object node['cmd'] doesn't exist at compile time, so it can't be deferred for lazy evaluation if it doesn't exist. This would probably work:

node.default['cmd'] = '/bin/false'

execute 'cmd' do
  command lazy { node['cmd'] }
end

node.override['cmd'] = '/bin/true'

That said, be careful not to use node attributes as variables. They're generally intended to be used as an interface to the cookbook.

On Tue, Oct 21, 2014 at 6:48 PM, Joe Nuspl < " target="_blank"> > wrote:
I am able to reproduce the issue with the following snippet:

execute 'cmd' do
  command lazy { node['cmd'] }
end

node.default['cmd'] = '/bin/true'

The corresponding spec is:

describe ‘test::lazy' do
  subject do
    ChefSpec::Runner.new.converge(described_recipe)
  end

  it { should run_execute('cmd') }
end




Can you share a bit more of the code you have under test?

On Tue, Oct 21, 2014 at 5:34 PM, Joe Nuspl < " target="_blank"> > wrote:
I’m trying to write a unit test for a recipe that uses http://docs.getchef.com/resource_common.html#lazy-attribute-evaluation

It fails with:

Failure/Error: runner.converge(described_recipe)
NoMethodError:
 undefined method `lazy' for Chef::Resource::Execute

Any ideas on how to make this work?

Joe






Archive powered by MHonArc 2.6.16.

§