Skip to content

Instantly share code, notes, and snippets.

@juliandunn
Created July 12, 2014 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliandunn/bb4036b3c2298d61e97f to your computer and use it in GitHub Desktop.
Save juliandunn/bb4036b3c2298d61e97f to your computer and use it in GitHub Desktop.
example of using Chefspec to make assertions about guards
# Recipe code
service 'true_guard' do
action :start
only_if { File.exist?('/tmp/trueguard') }
end
service 'false_guard' do
action :start
not_if { File.exist?('/tmp/falseguard') }
end
require 'chefspec'
describe 'chefspecguards::default' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
it 'includes resource that have guards that evaluate to true' do
File.stub(:exist?).and_return(true)
expect(chef_run).to start_service('true_guard')
end
it 'excludes resources that have guards evaluated to false' do
File.stub(:exist?).and_return(true)
expect(chef_run).to_not start_service('false_guard')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment