Search code examples
chef-infradevopschefspec

Chef spec error: expected "execute[..]" with action :run to be in Chef run. Other execute resources:


I am getting chefspec error as shown in title. Below are recipe resource and spec for which I am getting error:

Resource:

execute 'generate ssl cert for simple https file server' do
  cwd '/root/git/chef-bluecloud/bin/'
  command  <<-EOH
    openssl req -new -days 365 -nodes -x509 \
    -subj "/C=US/ST=NY/L=Somers/O=IBM/CN=bluecloud.xyz.com" \
    -keyout localhost.pem \
    -out localhost.pem
  EOH
  not_if 'test -f localhost.pem' # TODO: use ruby code instead of bash ::File.exists(...)
end

Spec:

it 'checks ssl cert generation for simple https file server' do
  expect(chef_run).to run_execute('openssl req -new -days 365 -nodes -x509 \
  -subj "/C=US/ST=NY/L=Somers/O=IBM/CN=bluecloud.xyz.com" \
  -keyout localhost.pem \
  -out localhost.pem \
  ').with(cwd:'/root/git/chef-bluecloud/bin/')
  expect(chef_run).to_not run_execute('openssl null').with(cwd:'/root/git/chef-bluecloud/bin/')
end

Any ideas on how to resolve it ? Thanks !


Solution

  • The value you give to a ChefSpec resource matcher is the name of the resource, which in this case is 'generate ssl cert for simple https file server'. So your matcher should look like run_execute('generate ssl cert for simple https file server').with(command: 'openssl etc etc').

    I'm not sure what your goal with the second expect is.