diff options
author | Luke Kanies <luke@madstop.com> | 2007-08-23 13:25:40 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-08-23 13:25:40 -0500 |
commit | 724fef1269bd593496bca9827a0ad7d9361e92d4 (patch) | |
tree | 8b8fb73ee625680bcbc3913e2ee007c8b344f44f /spec/unit | |
parent | 3d68ed66ca7545c26b83a4c921d21f5aad710ee0 (diff) | |
download | puppet-724fef1269bd593496bca9827a0ad7d9361e92d4.tar.gz puppet-724fef1269bd593496bca9827a0ad7d9361e92d4.tar.xz puppet-724fef1269bd593496bca9827a0ad7d9361e92d4.zip |
Everything up to the parser (and the Modules) is ready to support multiple environments, including the parser having an environment setting. I have also created my first spec-based tests, for the interpreter (and deleted the old test/unit tests).
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/parser/interpreter.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb index 0e32b8c5b..7328e2651 100755 --- a/spec/unit/parser/interpreter.rb +++ b/spec/unit/parser/interpreter.rb @@ -2,6 +2,40 @@ require File.dirname(__FILE__) + '/../../spec_helper' +describe Puppet::Parser::Interpreter, " when initializing" do + it "should default to neither code nor file" do + interp = Puppet::Parser::Interpreter.new + interp.code.should be_nil + interp.file.should be_nil + end + + it "should set the code to parse" do + interp = Puppet::Parser::Interpreter.new :Code => :code + interp.code.should equal(:code) + end + + it "should set the file to parse" do + interp = Puppet::Parser::Interpreter.new :Manifest => :file + interp.file.should equal(:file) + end + + it "should set code and ignore manifest when both are present" do + interp = Puppet::Parser::Interpreter.new :Code => :code, :Manifest => :file + interp.code.should equal(:code) + interp.file.should be_nil + end + + it "should default to usenodes" do + interp = Puppet::Parser::Interpreter.new + interp.usenodes?.should be_true + end + + it "should allow disabling of usenodes" do + interp = Puppet::Parser::Interpreter.new :UseNodes => false + interp.usenodes?.should be_false + end +end + describe Puppet::Parser::Interpreter, " when creating parser instances" do before do @interp = Puppet::Parser::Interpreter.new @@ -92,3 +126,45 @@ describe Puppet::Parser::Interpreter, " when managing parser instances" do @interp.send(:parser, :second_env).should equal(other_parser) end end + +describe Puppet::Parser::Interpreter, " when compiling configurations" do + before do + @interp = Puppet::Parser::Interpreter.new + end + + it "should create a configuration with the node, parser, and whether to use ast nodes" do + node = mock('node') + node.expects(:environment).returns(:myenv) + compile = mock 'compile' + compile.expects(:compile).returns(:config) + parser = mock 'parser' + @interp.expects(:parser).with(:myenv).returns(parser) + @interp.expects(:usenodes?).returns(true) + Puppet::Parser::Configuration.expects(:new).with(node, parser, :ast_nodes => true).returns(compile) + @interp.compile(node) + + # Now try it when usenodes is true + @interp = Puppet::Parser::Interpreter.new :UseNodes => false + node.expects(:environment).returns(:myenv) + compile.expects(:compile).returns(:config) + @interp.expects(:parser).with(:myenv).returns(parser) + @interp.expects(:usenodes?).returns(false) + Puppet::Parser::Configuration.expects(:new).with(node, parser, :ast_nodes => false).returns(compile) + @interp.compile(node).should equal(:config) + end +end + +describe Puppet::Parser::Interpreter, " when returning configuration version" do + before do + @interp = Puppet::Parser::Interpreter.new + end + + it "should ask the appropriate parser for the configuration version" do + node = mock 'node' + node.expects(:environment).returns(:myenv) + parser = mock 'parser' + parser.expects(:version).returns(:myvers) + @interp.expects(:parser).with(:myenv).returns(parser) + @interp.configuration_version(node).should equal(:myvers) + end +end |