diff --git a/README.md b/README.md index 6470c84..7c64d61 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,12 @@ structure and naming convention. | +-- _spec.rb | +-- functions + | | + | +-- _spec.rb + | + +-- hosts | - +-- _spec.rb + +-- _spec.rb ## Example groups @@ -49,6 +53,10 @@ end describe 'myfunction', :type => :puppet_function do ... end + +describe 'myhost.example.com', :type => :host do + ... +end ``` ## Defined Types & Classes diff --git a/lib/rspec-puppet/example.rb b/lib/rspec-puppet/example.rb index 9602073..55f89a2 100644 --- a/lib/rspec-puppet/example.rb +++ b/lib/rspec-puppet/example.rb @@ -2,6 +2,7 @@ require 'rspec-puppet/support' require 'rspec-puppet/example/define_example_group' require 'rspec-puppet/example/class_example_group' require 'rspec-puppet/example/function_example_group' +require 'rspec-puppet/example/host_example_group' RSpec::configure do |c| def c.escaped_path(*parts) @@ -19,4 +20,8 @@ RSpec::configure do |c| c.include RSpec::Puppet::FunctionExampleGroup, :type => :puppet_function, :example_group => { :file_path => c.escaped_path(%w[spec functions]) } + + c.include RSpec::Puppet::HostExampleGroup, :type => :host, :example_group => { + :file_path => c.escaped_path(%w[spec hosts]) + } end diff --git a/lib/rspec-puppet/example/host_example_group.rb b/lib/rspec-puppet/example/host_example_group.rb new file mode 100644 index 0000000..52fdd42 --- /dev/null +++ b/lib/rspec-puppet/example/host_example_group.rb @@ -0,0 +1,29 @@ +module RSpec::Puppet + module HostExampleGroup + include RSpec::Puppet::ManifestMatchers + include RSpec::Puppet::Support + + def subject + @catalogue ||= catalogue + end + + def catalogue + Puppet[:modulepath] = self.respond_to?(:module_path) ? module_path : RSpec.configuration.module_path + Puppet[:manifestdir] = self.respond_to?(:manifest_dir) ? manifest_dir : RSpec.configuration.manifest_dir + Puppet[:manifest] = self.respond_to?(:manifest) ? manifest : RSpec.configuration.manifest + Puppet[:templatedir] = self.respond_to?(:template_dir) ? template_dir : RSpec.configuration.template_dir + Puppet[:code] = "" + + nodename = self.class.top_level_description.downcase + + facts_val = { + 'hostname' => nodename.split('.').first, + 'fqdn' => nodename, + 'domain' => nodename.split('.').last, + } + facts_val.merge!(munge_facts(facts)) if self.respond_to?(:facts) + + build_catalog(nodename, facts_val) + end + end +end diff --git a/rspec-puppet.gemspec b/rspec-puppet.gemspec index d9292d8..fa3cb0b 100644 --- a/rspec-puppet.gemspec +++ b/rspec-puppet.gemspec @@ -9,6 +9,7 @@ Gem::Specification.new do |s| 'lib/rspec-puppet/example/class_example_group.rb', 'lib/rspec-puppet/example/define_example_group.rb', 'lib/rspec-puppet/example/function_example_group.rb', + 'lib/rspec-puppet/example/host_example_group.rb', 'lib/rspec-puppet/example.rb', 'lib/rspec-puppet/matchers/create_generic.rb', 'lib/rspec-puppet/matchers/create_resource.rb', @@ -26,8 +27,11 @@ Gem::Specification.new do |s| 'spec/classes/sysctl_common_spec.rb', 'spec/defines/sysctl_before_spec.rb', 'spec/defines/sysctl_spec.rb', - 'spec/fixtures/boolean/manifests/init.pp', - 'spec/fixtures/sysctl/manifests/init.pp', + 'spec/hosts/foo_spec.rb', + 'spec/hosts/testhost_spec.rb', + 'spec/fixtures/manifests/site.pp', + 'spec/fixtures/modules/boolean/manifests/init.pp', + 'spec/fixtures/modules/sysctl/manifests/init.pp', 'spec/functions/split_spec.rb', 'spec/spec_helper.rb', ] diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp new file mode 100644 index 0000000..0f0ec89 --- /dev/null +++ b/spec/fixtures/manifests/site.pp @@ -0,0 +1,7 @@ +node default { + notify { 'test': } +} + +node /testhost/ { + include sysctl::common +} diff --git a/spec/hosts/foo_spec.rb b/spec/hosts/foo_spec.rb new file mode 100644 index 0000000..9c1496d --- /dev/null +++ b/spec/hosts/foo_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +describe 'foo.example.com' do + it { should_not include_class('sysctl::common') } + it { should contain_notify('test') } +end diff --git a/spec/hosts/testhost_spec.rb b/spec/hosts/testhost_spec.rb new file mode 100644 index 0000000..42c2ca2 --- /dev/null +++ b/spec/hosts/testhost_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe 'testhost' do + it { should include_class('sysctl::common') } +end