sous-chefs/logrotate

Use of coerce in logrotate_app breaks specs

rmoriz opened this issue · 1 comments

With the 3.0.0 changes introdoced in dc20786#diff-b7e94f5fcd66051355907f23b26ff6ac96685ca36c95837931a588074999fbf9R26
it's a lot harder to write chefspecs when a logrotate_app resource is called with an paths array

e.g.

logrotate_app 'nginx' do                                             
  cookbook 'logrotate'                                                       
  path [                                                           
    "#{node['web']['root']}/logs/ssl-access.log",
    "#{node['web']['root']}/logs/ssl-error.log"
  ]
...
end 

In older versions when coerce was not used, one could simply write the following chef spec:

  it 'add logrotation' do
    expect(chef_run).to enable_logrotate_app('nginx').with(
      path: [
        "/path/to/www/logs/ssl-access.log",
        "/path/to/www/logs/ssl-error.log",
      ],
...
    )
  end

As coerce merges the array on assignment, this does not work anymore.
The workaround is to "deal with the internals" and format the paths as a coerced string like

  it 'add logrotation' do
    expect(chef_run).to enable_logrotate_app('nginx').with(
      path: '"/path/to/www/logs/ssl-access.log" "/path/to/www/logs/ssl-error.log"',
    ...
    )
  end

which is obviously ugly and does not represent the way, the resource is called in the recipe. Any idea to make this usable again?

Thank you.

Yeah unfortunately that's what you need to do when using ChefSpec.