diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-02 18:52:57 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-19 12:48:07 -0700 |
commit | 7bf9673185640d1b315193bb0f9d6be3492c05d3 (patch) | |
tree | 54037cc0c2d6bbeba4bed8d1328e52b899c8787a | |
parent | da4cd4d981d8500271ea25e998faffe105e6b01c (diff) | |
download | chef-7bf9673185640d1b315193bb0f9d6be3492c05d3.tar.gz |
configuration_generator_spec uses newer rspec conventions
-rw-r--r-- | spec/unit/util/dsc/configuration_generator_spec.rb | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb index 8fcc85a71c..03f3ffe25c 100644 --- a/spec/unit/util/dsc/configuration_generator_spec.rb +++ b/spec/unit/util/dsc/configuration_generator_spec.rb @@ -20,28 +20,28 @@ require 'chef' require 'chef/util/dsc/configuration_generator' describe Chef::Util::DSC::ConfigurationGenerator do - before (:all) do - @node = Chef::Node.new - @conf_man = Chef::Util::DSC::ConfigurationGenerator.new(@node, 'tmp') + let(:conf_man) do + node = Chef::Node.new + Chef::Util::DSC::ConfigurationGenerator.new(node, 'tmp') end describe '#validate_configuration_name!' do it 'should not raise an error if a name contains all upper case letters' do - @conf_man.send(:validate_configuration_name!, "HELLO") + conf_man.send(:validate_configuration_name!, "HELLO") end it 'should not raise an error if the name contains all lower case letters' do - @conf_man.send(:validate_configuration_name!, "hello") + conf_man.send(:validate_configuration_name!, "hello") end it 'should not raise an error if no special characters are used except _' do - @conf_man.send(:validate_configuration_name!, "hello_world") + conf_man.send(:validate_configuration_name!, "hello_world") end %w{! @ # $ % ^ & * & * ( ) - = + \{ \} . ? < > \\ /}.each do |sym| it "raises an Argument error if it configuration name contains #{sym}" do expect { - @conf_man.send(:validate_configuration_name!, "Hello#{sym}") + conf_man.send(:validate_configuration_name!, "Hello#{sym}") }.to raise_error(ArgumentError) end end @@ -50,7 +50,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do describe "#get_merged_configuration_flags" do context 'when strings are used as switches' do it 'should merge the hash if there are no restricted switches' do - merged = @conf_man.send(:get_merged_configuration_flags!, {'flag' => 'a'}, 'hello') + merged = conf_man.send(:get_merged_configuration_flags!, {'flag' => 'a'}, 'hello') merged.should include(:flag) merged[:flag].should eql('a') merged.should include(:outputpath) @@ -58,25 +58,25 @@ describe Chef::Util::DSC::ConfigurationGenerator do it 'should raise an ArgumentError if you try to override outputpath' do expect { - @conf_man.send(:get_merged_configuration_flags!, {'outputpath' => 'a'}, 'hello') + conf_man.send(:get_merged_configuration_flags!, {'outputpath' => 'a'}, 'hello') }.to raise_error(ArgumentError) end it 'should be case insensitive for switches that are not allowed' do expect { - @conf_man.send(:get_merged_configuration_flags!, {'OutputPath' => 'a'}, 'hello') + conf_man.send(:get_merged_configuration_flags!, {'OutputPath' => 'a'}, 'hello') }.to raise_error(ArgumentError) end it 'should be case insensitive to switches that are allowed' do - merged = @conf_man.send(:get_merged_configuration_flags!, {'FLAG' => 'a'}, 'hello') + merged = conf_man.send(:get_merged_configuration_flags!, {'FLAG' => 'a'}, 'hello') merged.should include(:flag) end end context 'when symbols are used as switches' do it 'should merge the hash if there are no restricted switches' do - merged = @conf_man.send(:get_merged_configuration_flags!, {:flag => 'a'}, 'hello') + merged = conf_man.send(:get_merged_configuration_flags!, {:flag => 'a'}, 'hello') merged.should include(:flag) merged[:flag].should eql('a') merged.should include(:outputpath) @@ -84,31 +84,31 @@ describe Chef::Util::DSC::ConfigurationGenerator do it 'should raise an ArgumentError if you try to override outputpath' do expect { - @conf_man.send(:get_merged_configuration_flags!, {:outputpath => 'a'}, 'hello') + conf_man.send(:get_merged_configuration_flags!, {:outputpath => 'a'}, 'hello') }.to raise_error(ArgumentError) end it 'should be case insensitive for switches that are not allowed' do expect { - @conf_man.send(:get_merged_configuration_flags!, {:OutputPath => 'a'}, 'hello') + conf_man.send(:get_merged_configuration_flags!, {:OutputPath => 'a'}, 'hello') }.to raise_error(ArgumentError) end it 'should be case insensitive to switches that are allowed' do - merged = @conf_man.send(:get_merged_configuration_flags!, {:FLAG => 'a'}, 'hello') + merged = conf_man.send(:get_merged_configuration_flags!, {:FLAG => 'a'}, 'hello') merged.should include(:flag) end end context 'when there are no flags' do it 'should supply an output path if configuration_flags is an empty hash' do - merged = @conf_man.send(:get_merged_configuration_flags!, {}, 'hello') + merged = conf_man.send(:get_merged_configuration_flags!, {}, 'hello') merged.should include(:outputpath) merged.length.should eql(1) end it 'should supply an output path if configuration_flags is an empty hash' do - merged = @conf_man.send(:get_merged_configuration_flags!, nil, 'hello') + merged = conf_man.send(:get_merged_configuration_flags!, nil, 'hello') merged.should include(:outputpath) merged.length.should eql(1) end @@ -122,18 +122,16 @@ describe Chef::Util::DSC::ConfigurationGenerator do end describe '#write_document_generation_script' do - before (:each) do - @file_like_object = double("file like object") - end + let(:file_like_object) { double("file like object") } it "should write the input to a file" do - File.stub(:open).and_yield(@file_like_object) - @file_like_object.stub(:write).with(anything()) - File.stub(:join) do |a, b| + allow(File).to receive(:open).and_yield(file_like_object) + allow(File).to receive(:join) do |a, b| [a,b].join("++") end - @conf_man.send(:write_document_generation_script, 'file', 'hello') - expect(@file_like_object).to have_received(:write) + allow(file_like_object).to receive(:write) + conf_man.send(:write_document_generation_script, 'file', 'hello') + expect(file_like_object).to have_received(:write) end end @@ -141,26 +139,26 @@ describe Chef::Util::DSC::ConfigurationGenerator do it "should find the mof file" do # These tests seem way too implementation specific. Unfortunatly, File and Dir # need to be mocked because they are OS specific - - File.stub(:join) do |a, b| + allow(File).to receive(:join) do |a, b| [a,b].join("++") end - Dir.stub(:entries).with("tmp++hello") {['f1', 'f2', 'hello.mof', 'f3']} - expect(@conf_man.send(:find_configuration_document, 'hello')).to eql('tmp++hello++hello.mof') + + allow(Dir).to receive(:entries).with("tmp++hello") {['f1', 'f2', 'hello.mof', 'f3']} + expect(conf_man.send(:find_configuration_document, 'hello')).to eql('tmp++hello++hello.mof') end it "should return nil if the mof file is not found" do - File.stub(:join) do |a, b| + allow(File).to receive(:join) do |a, b| [a,b].join("++") end - Dir.stub(:entries).with("tmp++hello") {['f1', 'f2', 'f3']} - expect(@conf_man.send(:find_configuration_document, 'hello')).to be_nil + allow(Dir).to receive(:entries).with("tmp++hello") {['f1', 'f2', 'f3']} + expect(conf_man.send(:find_configuration_document, 'hello')).to be_nil end end describe "#configuration_code" do it "should build dsc" do - dsc = @conf_man.send(:configuration_code, 'archive{}', 'hello') + dsc = conf_man.send(:configuration_code, 'archive{}', 'hello') found_configuration = false dsc.split(';').each do |command| if command.downcase =~ /\s*configuration\s+'hello'\s*\{\s*node\s+'localhost'\s*\{\s*archive\s*\{\s*\}\s*\}\s*\}\s*/ |