3 # This is a reduced version of ruby_spec.rb just to ensure we can subclass as
5 $: << 'spec/fixtures/modules/inherit_ini_setting/lib'
6 provider_class = Puppet::Type.type(:inherit_ini_setting).provider(:ini_setting)
7 describe provider_class do
8 include PuppetlabsSpec::Files
10 let(:tmpfile) { tmpfilename('inherit_ini_setting_test') }
12 def validate_file(expected_content,tmpfile = tmpfile)
13 File.read(tmpfile).should == expected_content
18 File.open(tmpfile, 'w') do |fh|
19 fh.write(orig_content)
23 context 'when calling instances' do
24 let(:orig_content) { '' }
26 it 'should parse nothing when the file is empty' do
27 provider_class.stubs(:file_path).returns(tmpfile)
28 provider_class.instances.should == []
31 context 'when the file has contents' do
40 it 'should parse the results' do
41 provider_class.stubs(:file_path).returns(tmpfile)
42 instances = provider_class.instances
43 instances.size.should == 2
44 # inherited version of namevar flattens the names
45 names = instances.map do |instance|
46 instance.instance_variable_get(:@property_hash)[:name]
48 names.sort.should == [ 'green', 'red' ]
53 context 'when ensuring that a setting is present' do
54 let(:orig_content) { '' }
56 it 'should add a value to the file' do
57 provider_class.stubs(:file_path).returns(tmpfile)
58 resource = Puppet::Type::Inherit_ini_setting.new({
59 :setting => 'set_this',
62 provider = described_class.new(resource)
64 validate_file("set_this=to_that\n")