Skip to content

Instantly share code, notes, and snippets.

@sroegner
Created December 3, 2012 21:31
Show Gist options
  • Save sroegner/4198268 to your computer and use it in GitHub Desktop.
Save sroegner/4198268 to your computer and use it in GitHub Desktop.
reproducing rspec-hiera-puppet example
>>> ./modules/example/spec/classes/example_spec.rb
describe "example" do
let(:hiera_data) { { :foo_message => "bar" } }
it { should contain_notify("foo").with_message("bar") }
end
>>> ./modules/example/spec/manifests/site.pp #this just exists because rspec-puppet appears to insist on it?)
>>> ./modules/example/spec/spec_helper.rb
dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift File.join(dir, 'lib')
require 'rspec-puppet'
require 'rspec-hiera-puppet'
specdir = File.expand_path(File.dirname(File.dirname(__FILE__)))
RSpec.configure do |rspec_cfg|
Puppet::Util::Log.level = :debug
Puppet::Util::Log.newdestination(:console)
rspec_cfg.before :each do |x|
rspec_cfg.module_path = File.join(specdir, '..', '..', 'modules')
rspec_cfg.manifest_dir = File.join(specdir, 'spec', 'manifests')
end
end
>>> ./modules/example/manifests/init.pp
class example {
notify { 'foo': message => hiera('foo_message') }
}
----------------------------
➜ example rspec -r $PWD/spec/spec_helper.rb
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`.
*** Mocha deprecation warning: Test::Unit or MiniTest must be loaded *before* Mocha.
*** Mocha deprecation warning: If you're integrating with a test library other than Test::Unit or MiniTest, you should use `require 'mocha/api'` instead of `require 'mocha'`.
Warning: Could not retrieve fact ipaddress
Debug: importing '/home/sroegner/Code/puppet/testing/modules/example/spec/manifests/site.pp' in environment production
Debug: importing '/home/sroegner/Code/puppet/testing/modules/example/manifests/init.pp' in environment production
Debug: Automatically imported example from example into production
SELF: Scope(Class[Example]) key: foo_message, default:
Debug: hiera(): Hiera YAML backend starting
Debug: hiera(): Looking up foo_message in YAML backend
Debug: hiera(): Looking for data source common
Debug: hiera(): Cannot find datafile /var/lib/hiera/common.yaml, skipping
Error: Could not find data item foo_message in any Hiera data file and no default supplied at /home/sroegner/Code/puppet/testing/modules/example/manifests/init.pp:2 on node xsr
F
Failures:
1) example
Failure/Error: it { should contain_notify("foo").with_message("bar") }
Puppet::Error:
Could not find data item foo_message in any Hiera data file and no default supplied at /home/sroegner/Code/puppet/testing/modules/example/manifests/init.pp:2 on node xsr
# ./spec/classes/example_spec.rb:4:in `block (2 levels) in <top (required)>'
Finished in 0.10883 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/classes/example_spec.rb:4 # example
@KartikTalwar
Copy link

I'd be interested in knowing the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment