Skip to content

Commit

Permalink
Merge pull request #145 from domcleal/catalogue-method
Browse files Browse the repository at this point in the history
Expose 'catalogue' method as consistent API in example groups
  • Loading branch information
timtim123456 committed Jan 25, 2014
2 parents a3161d3 + 7dddebd commit bab2839
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/rspec-puppet/example/class_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module ClassExampleGroup
include RSpec::Puppet::ManifestMatchers
include RSpec::Puppet::Support

def subject
@catalogue ||= catalogue(:class)
def catalogue
@catalogue ||= load_catalogue(:class)
end

alias_method :subject, :catalogue
end
end
6 changes: 4 additions & 2 deletions lib/rspec-puppet/example/define_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module DefineExampleGroup
include RSpec::Puppet::ManifestMatchers
include RSpec::Puppet::Support

def subject
@catalogue ||= catalogue(:define)
def catalogue
@catalogue ||= load_catalogue(:define)
end

alias_method :subject, :catalogue
end
end
6 changes: 4 additions & 2 deletions lib/rspec-puppet/example/host_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module HostExampleGroup
include RSpec::Puppet::ManifestMatchers
include RSpec::Puppet::Support

def subject
@catalogue ||= catalogue(:host)
def catalogue
@catalogue ||= load_catalogue(:host)
end

alias_method :subject, :catalogue
end
end
2 changes: 1 addition & 1 deletion lib/rspec-puppet/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Support

@@cache = {}

def catalogue(type)
def load_catalogue(type)
vardir = setup_puppet

code = [import_str, pre_cond, test_manifest(type)].join("\n")
Expand Down
21 changes: 21 additions & 0 deletions spec/classes/test_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe 'test::bare_class' do
describe 'rspec group' do
it 'should have a catalogue method' do
catalogue.should be_a(Puppet::Resource::Catalog)
end

it 'subject should return a catalogue' do
subject.should be_a(Puppet::Resource::Catalog)
end

describe 'derivative group' do
subject { catalogue.resource('Notify', 'foo') }

it 'can redefine subject' do
subject.should be_a(Puppet::Resource)
end
end
end
end
16 changes: 16 additions & 0 deletions spec/defines/test_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'spec_helper'

describe 'sysctl' do
let(:title) { 'vm.swappiness' }
let(:params) { {:value => '60'} }

describe 'rspec group' do
it 'should have a catalogue method' do
catalogue.should be_a(Puppet::Resource::Catalog)
end

it 'subject should return a catalogue' do
subject.should be_a(Puppet::Resource::Catalog)
end
end
end
13 changes: 13 additions & 0 deletions spec/hosts/test_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe 'foo.example.com' do
describe 'rspec group' do
it 'should have a catalogue method' do
catalogue.should be_a(Puppet::Resource::Catalog)
end

it 'subject should return a catalogue' do
subject.should be_a(Puppet::Resource::Catalog)
end
end
end

0 comments on commit bab2839

Please sign in to comment.