diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2010-07-19 14:57:23 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-19 19:56:06 -0700 |
| commit | 539d71635132bd5f772a550b7bfff530e8b59b68 (patch) | |
| tree | 1f1ae2297bf9b13f62473f918f3ae4d172326fa9 /spec/unit/parser | |
| parent | d2da1d45aaf44de7fd0648b3bab48887838549d8 (diff) | |
| download | puppet-539d71635132bd5f772a550b7bfff530e8b59b68.tar.gz puppet-539d71635132bd5f772a550b7bfff530e8b59b68.tar.xz puppet-539d71635132bd5f772a550b7bfff530e8b59b68.zip | |
[#4287] Fix the undefined evaluate_match error when comparing functions
Ticket #4238 introduced a problem that a function couldn't compare to
another value until after it was evaluated, and AST::Function didn't have the
evaluate_match method. This change moves that method from AST::Leaf to AST.
The special casing necessary for doing comparisons between AST objects
feels messy and could probably be encapsulated better. I've created
ticket #4291 to remind us to refactor this at some point.
Paired with: Nick Lewis
Signed-off-by: Matt Robinson <matt@puppetlabs.com>
Diffstat (limited to 'spec/unit/parser')
| -rwxr-xr-x | spec/unit/parser/ast/leaf_spec.rb | 57 | ||||
| -rw-r--r-- | spec/unit/parser/ast_spec.rb | 70 |
2 files changed, 70 insertions, 57 deletions
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb index d21cbf573..6729cd278 100755 --- a/spec/unit/parser/ast/leaf_spec.rb +++ b/spec/unit/parser/ast/leaf_spec.rb @@ -13,63 +13,6 @@ describe Puppet::Parser::AST::Leaf do Puppet::Parser::AST::Leaf.new(:value => "value").should respond_to(:evaluate_match) end - describe "when evaluate_match is called" do - it "should evaluate itself" do - @leaf.expects(:safeevaluate).with(@scope) - - @leaf.evaluate_match("value", @scope) - end - - it "should match values by equality" do - @value.stubs(:==).returns(false) - @leaf.stubs(:safeevaluate).with(@scope).returns(@value) - @value.expects(:==).with("value") - - @leaf.evaluate_match("value", @scope) - end - - it "should downcase the evaluated value if wanted" do - @leaf.stubs(:safeevaluate).with(@scope).returns(@value) - @value.expects(:downcase).returns("value") - - @leaf.evaluate_match("value", @scope) - end - - it "should convert values to number" do - @leaf.stubs(:safeevaluate).with(@scope).returns(@value) - Puppet::Parser::Scope.expects(:number?).with(@value).returns(2) - Puppet::Parser::Scope.expects(:number?).with("23").returns(23) - - @leaf.evaluate_match("23", @scope) - end - - it "should compare 'numberized' values" do - @leaf.stubs(:safeevaluate).with(@scope).returns(@value) - two = stub_everything 'two' - one = stub_everything 'one' - - Puppet::Parser::Scope.stubs(:number?).with(@value).returns(one) - Puppet::Parser::Scope.stubs(:number?).with("2").returns(two) - - one.expects(:==).with(two) - - @leaf.evaluate_match("2", @scope) - end - - it "should match undef if value is an empty string" do - @leaf.stubs(:safeevaluate).with(@scope).returns("") - - @leaf.evaluate_match(:undef, @scope).should be_true - end - - it "should downcase the parameter value if wanted" do - parameter = stub 'parameter' - parameter.expects(:downcase).returns("value") - - @leaf.evaluate_match(parameter, @scope) - end - end - describe "when converting to string" do it "should transform its value to string" do value = stub 'value', :is_a? => true diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb index b743cea2e..29dce2b9c 100644 --- a/spec/unit/parser/ast_spec.rb +++ b/spec/unit/parser/ast_spec.rb @@ -39,3 +39,73 @@ describe Puppet::Parser::AST do end end + +describe 'AST Generic Child' do + before :each do + @value = stub 'value' + class Evaluateable < Puppet::Parser::AST + attr_accessor :value + def safeevaluate(*options) + return value + end + end + @evaluateable = Evaluateable.new(:value => @value) + @scope = stubs 'scope' + end + + describe "when evaluate_match is called" do + it "should evaluate itself" do + @evaluateable.expects(:safeevaluate).with(@scope) + + @evaluateable.evaluate_match("value", @scope) + end + + it "should match values by equality" do + @value.expects(:==).with("value").returns(true) + + @evaluateable.evaluate_match("value", @scope) + end + + it "should downcase the evaluated value if wanted" do + @value.expects(:downcase).returns("value") + + @evaluateable.evaluate_match("value", @scope) + end + + it "should convert values to number" do + Puppet::Parser::Scope.expects(:number?).with(@value).returns(2) + Puppet::Parser::Scope.expects(:number?).with("23").returns(23) + + @evaluateable.evaluate_match("23", @scope) + end + + it "should compare 'numberized' values" do + two = stub_everything 'two' + one = stub_everything 'one' + + Puppet::Parser::Scope.stubs(:number?).with(@value).returns(one) + Puppet::Parser::Scope.stubs(:number?).with("2").returns(two) + + one.expects(:==).with(two) + + @evaluateable.evaluate_match("2", @scope) + end + + it "should match undef if value is an empty string" do + @evaluateable.value = '' + @evaluateable.evaluate_match(:undef, @scope).should be_true + end + + it "should downcase the parameter value if wanted" do + parameter = stub 'parameter' + parameter.expects(:downcase).returns("value") + + @evaluateable.evaluate_match(parameter, @scope) + end + + it "should not match '' if value is undef" do + @evaluateable.value = :undef + @evaluateable.evaluate_match('', @scope).should be_false + end + end +end |
