Skip to content

Instantly share code, notes, and snippets.

@juliandunn
Created April 29, 2014 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliandunn/11387798 to your computer and use it in GitHub Desktop.
Save juliandunn/11387798 to your computer and use it in GitHub Desktop.
Illustration of stubbing other things, like guard expressions, in ChefSpec
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) # 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