Created
July 12, 2014 03:20
-
-
Save juliandunn/bb4036b3c2298d61e97f to your computer and use it in GitHub Desktop.
example of using Chefspec to make assertions about guards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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