1

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 !

Jordan Running
  • 102,619
  • 17
  • 182
  • 182
  • I have already stubbed the needed stuff in a before do block at beginning of spec file ``` before do stub_command("test -f localhost.pem").and_return(nil) end ``` – Bhavya Maheshwari Nov 19 '15 at 05:41

1 Answers1

2

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thanks, that made it work. But my other expect execute resources were passing even with command in run_execute matcher instead of resource name. – Bhavya Maheshwari Nov 19 '15 at 09:53
  • If you don't specify an explicit `command` property on an execute resource, it defaults to using the name as the command to run. – coderanger Nov 19 '15 at 17:59