Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect result when testing conditional notification #863

Open
emiller42 opened this issue Jul 25, 2017 · 0 comments
Open

incorrect result when testing conditional notification #863

emiller42 opened this issue Jul 25, 2017 · 0 comments

Comments

@emiller42
Copy link

With a resource block in a recipe like so...

file '/etc/systemd/system/statsd.service' do
  action :delete
  notifies :run, 'execute[statsd_systemctl_daemon_reload]', :immediately
  only_if { node['platform_version'] > '7' }
end

and a test like so...

it 'deletes old systemd service' do
  file = chef_run.file('/etc/systemd/system/statsd.service')
  expect(chef_run).to delete_file('/etc/systemd/system/statsd.service')
  expect(file).to notify('execute[statsd_systemctl_daemon_reload]').to(:run).immediately
end if version >= '7.0'

it 'does not delete systemd service on rhel 6' do
  file = chef_run.file('/etc/systemd/system/statsd.service')
  expect(chef_run).to_not delete_file('/etc/systemd/system/statsd.service')
  expect(file).to_not notify('execute[statsd_systemctl_daemon_reload]').to(:run).immediately
end if version < '7.0'

I end up with a chefspec run that fails only the last notification assertion:

  1) statsd::default On redhat 6.7 does not delete systemd service on rhel 6
     Failure/Error: expect(file).to_not notify('execute[statsd_systemctl_daemon_reload]').to(:run).immediately
       expected "file[/etc/systemd/system/statsd.service]" to not notify "execute[statsd_systemctl_daemon_reload]", but it did.
     # ./spec/recipe_default_spec.rb:120:in `block (5 levels) in <top (required)>'

In an actual chef run, this resource does not send a notification when the only_if condition is not met. Am I doing something wrong with my test definition? The fact that the results for file deletion are accurate leads me to believe the conditions are evaluating as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant