diff options
| author | Markus Roberts <Markus@reality.com> | 2010-06-10 22:51:12 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | ccc869ea48397235d7ba2a5695424eee4923cb9d (patch) | |
| tree | ffd534b345923f62733e4e48cc3e36377fa059fe /spec/unit/parser/scope.rb | |
| parent | 7c6b8836453b2b1e8679923f98854be3b0022edd (diff) | |
| download | puppet-ccc869ea48397235d7ba2a5695424eee4923cb9d.tar.gz puppet-ccc869ea48397235d7ba2a5695424eee4923cb9d.tar.xz puppet-ccc869ea48397235d7ba2a5695424eee4923cb9d.zip | |
Part 2 of fix for #1175 (functions in environments)
Jesse and I are shooting for the minimal viable fix here, with the idea that
a great deal of refactoring is needed but isn't appropriate at this time. The
changes in this commit are:
* Index the function-holding modules by environment
* We need to know the "current environment" when we're defining a function so
we can attach it to the proper module, and this information isn't dynamically
available when user-defined functions are being created (we're being called by
user written code that doesn't "know" about environments) so we cheat and
stash the value in Puppet::Node::Environment
* since we must do this anyway, it turns out to be cleaner & safer to do the
same when we are evaluating a functon. This is the main change from the prior
version of this patch.
* Add a special *root* environment for the built in functions, and extend all
scopes with it.
* Index the function characteristics (name, type, docstring, etc.) by environment
* Make the autoloader environment aware, so that it uses the modulepath for the
specified environment rather than the default
* Turn off caching of the modulepath since it potentially changes for each node
* Tweak tests that weren't environment aware
Diffstat (limited to 'spec/unit/parser/scope.rb')
| -rwxr-xr-x | spec/unit/parser/scope.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb index 7093279b6..b14b2d3b6 100755 --- a/spec/unit/parser/scope.rb +++ b/spec/unit/parser/scope.rb @@ -59,10 +59,12 @@ describe Puppet::Parser::Scope do end describe "when initializing" do - it "should extend itself with its environment's Functions module" do + it "should extend itself with its environment's Functions module as well as the default" do env = Puppet::Node::Environment.new("myenv") compiler = stub 'compiler', :environment => env - mod = Module.new + mod = Module.new + root_mod = Module.new + Puppet::Parser::Functions.expects(:environment_module).with(Puppet::Node::Environment.root).returns root_mod Puppet::Parser::Functions.expects(:environment_module).with(env).returns mod Puppet::Parser::Scope.new(:compiler => compiler).metaclass.ancestors.should be_include(mod) @@ -70,7 +72,7 @@ describe Puppet::Parser::Scope do it "should extend itself with the default Functions module if it has no environment" do mod = Module.new - Puppet::Parser::Functions.expects(:environment_module).with(nil).returns mod + Puppet::Parser::Functions.expects(:environment_module).with(Puppet::Node::Environment.root).returns(mod) Puppet::Parser::Scope.new().metaclass.ancestors.should be_include(mod) end |
