Created
April 29, 2014 00:22
-
-
Save juliandunn/11387798 to your computer and use it in GitHub Desktop.
Illustration of stubbing other things, like guard expressions, in ChefSpec
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
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) # could also stub with args | |
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