Skip to content

Instantly share code, notes, and snippets.

@dougneal
Created January 18, 2016 15:41
Show Gist options
  • Save dougneal/98185d1b2fd00dede5d2 to your computer and use it in GitHub Desktop.
Save dougneal/98185d1b2fd00dede5d2 to your computer and use it in GitHub Desktop.
Ensure that a specific provider is selected during an rspec test
# If your test depends on a specific provider being used, or a provider which has
# a specific attribute, such as versionable, the provider will fail the selection
# round if its commands aren't present on the system that the test is running on.
# For example, if running your rspec tests on your OS X development machine,
# and your manifests include :
# package { 'java':
# ensure => '1.7.0+update67'
# }
#
# The test will fail with the error:
# Parameter ensure failed on Package[oracle-j2sdk1.7]: Provider must have features 'versionable' to set 'ensure' to '1.7.0+update67'
#
# Use rspec-mocks to stub out the suitability check of the provider:
# https://github.com/puppetlabs/puppet/blob/master/lib/puppet/confiner.rb#L43
#
it {
allow(Puppet::Type.type(:package).provider(:apt)).to receive(:suitable?) { true }
is_expected.to compile.with_all_deps
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment