diff options
Diffstat (limited to 'spec/unit/puppet/util/ini_file_spec.rb')
-rw-r--r-- | spec/unit/puppet/util/ini_file_spec.rb | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/spec/unit/puppet/util/ini_file_spec.rb b/spec/unit/puppet/util/ini_file_spec.rb index f2c6e20..f30c8cd 100644 --- a/spec/unit/puppet/util/ini_file_spec.rb +++ b/spec/unit/puppet/util/ini_file_spec.rb @@ -2,8 +2,16 @@ require 'spec_helper' require 'puppet/util/ini_file' describe Puppet::Util::IniFile do + let(:subject) { Puppet::Util::IniFile.new("/my/ini/file/path") } + + before :each do + File.should_receive(:file?).with("/my/ini/file/path") { true } + described_class.should_receive(:readlines).once.with("/my/ini/file/path") do + sample_content + end + end + context "when parsing a file" do - let(:subject) { Puppet::Util::IniFile.new("/my/ini/file/path") } let(:sample_content) { template = <<-EOS # This is a comment @@ -22,19 +30,14 @@ baz=bazvalue template.split("\n") } - before :each do - File.should_receive(:file?).with("/my/ini/file/path") { true } - described_class.should_receive(:readlines).once.with("/my/ini/file/path") do - sample_content - end - end - it "should parse the correct number of sections" do - subject.section_names.length.should == 2 + # there is always a "global" section, so our count should be 3. + subject.section_names.length.should == 3 end it "should parse the correct section_names" do - subject.section_names.should == ["section1", "section2"] + # there should always be a "global" section named "" at the beginning of the list + subject.section_names.should == ["", "section1", "section2"] end it "should expose settings for sections" do @@ -45,4 +48,58 @@ baz=bazvalue end end + + context "when parsing a file whose first line is a section" do + let(:sample_content) { + template = <<-EOS +[section1] +; This is a comment +foo=foovalue + EOS + template.split("\n") + } + + it "should parse the correct number of sections" do + # there is always a "global" section, so our count should be 2. + subject.section_names.length.should == 2 + end + + it "should parse the correct section_names" do + # there should always be a "global" section named "" at the beginning of the list + subject.section_names.should == ["", "section1"] + end + + it "should expose settings for sections" do + subject.get_value("section1", "foo").should == "foovalue" + end + + end + + context "when parsing a file with a 'global' section" do + let(:sample_content) { + template = <<-EOS +foo = bar +[section1] +; This is a comment +foo=foovalue + EOS + template.split("\n") + } + + it "should parse the correct number of sections" do + # there is always a "global" section, so our count should be 2. + subject.section_names.length.should == 2 + end + + it "should parse the correct section_names" do + # there should always be a "global" section named "" at the beginning of the list + subject.section_names.should == ["", "section1"] + end + + it "should expose settings for sections" do + subject.get_value("", "foo").should == "bar" + subject.get_value("section1", "foo").should == "foovalue" + end + + end end
\ No newline at end of file |