Skip to content

Instantly share code, notes, and snippets.

@gsarjeant
Created October 18, 2014 02:09
Show Gist options
  • Save gsarjeant/e2a3cd812e8d44485564 to your computer and use it in GitHub Desktop.
Save gsarjeant/e2a3cd812e8d44485564 to your computer and use it in GitHub Desktop.
Sample beaker-rspec test
module_path = '/path/to/module/root/directory'
module_name = 'my_module'
# The test manifest should be a manifest in the tests directory of your module,
# which declares the class you want to include (e.g. include my_class)
test_manifest = "#{module_path}/tests/init.pp"
# Use puppet_module_install to scp the module directory from the host into the modulepath on the target VM
# NOTE: puppet_module_install is defined in beaker-rspec:
# https://github.com/puppetlabs/beaker-rspec/blob/master/lib/beaker-rspec/beaker_shim.rb
# The module name is the base name of the module directory with any leading namespace identifier removed
# e.g. gsarjeant-awesomemodule would become awesomemodule
puppet_module_install(:source => module_path, :module_name => module_name)
# Read the manifest we want to apply from the module into a variable
manifest = File.open(test_manifest).read
# Apply the solution manifest and verify that it runs cleanly.
# The "a solution manifest" shared example group is defined in
# spec/solution_manifest_spec.rb (included by spec_helper_acceptance)
# We pass the manifest under test to this group with the "let(:manifest) { solution_manifest }" declaration
# See https://gist.github.com/gsarjeant/a2807aba13f2cd326ee4 for an example
describe "My test manifest", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it_behaves_like "a puppet manifest" do
let(:manifest) { manifest }
end
end
#################################################################################################
#
# We've now used the beaker functionality to install the module on a target node.
# From this point, serverspec takes over to verify the state of the system.
#
# Change the tests below to verify the functionality of the module that you are testing
#
#################################################################################################
describe "My module results", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
# Test 1: Verify that a demo user was created.
describe user('demo') do
it { should exist }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment