Skip to content

Instantly share code, notes, and snippets.

@petems
Created January 15, 2015 19:53
Show Gist options
  • Save petems/d686a656a43e18cc7db4 to your computer and use it in GitHub Desktop.
Save petems/d686a656a43e18cc7db4 to your computer and use it in GitHub Desktop.
Mocking validate_cmd in Puppet
require 'spec_helper'
describe 'sudo::sudoers', :type => :define do
let(:title) { 'world.domination' }
if (Puppet.version >= '3.5.0')
context "validating content with puppet #{Puppet.version}" do
let(:params) { { :users => ['joe'] } }
let(:facts) {{ :puppetversion => Puppet.version }}
it {
should contain_file('/etc/sudoers.d/world_domination').with_validate_cmd('/usr/sbin/visudo -c -f %')
}
end
else
context "validating content with puppet #{Puppet.version}" do
let(:params) { { :users => ['joe'] } }
let(:facts) {{ :puppetversion => Puppet.version }}
it {
allow(Puppet::Util::Execution).to receive(:execute).with("/usr/sbin/visudo -c -f %").
and_return 1
should contain_file('/etc/sudoers.d/world_domination').with_validate_cmd(nil)
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment