spec/unit/parser/ast/arithmetic_operator.rb in puppet-0.24.9 vs spec/unit/parser/ast/arithmetic_operator.rb in puppet-0.25.0

- old
+ new

@@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::ArithmeticOperator do - ast = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @scope = Puppet::Parser::Scope.new() @one = stub 'lval', :safeevaluate => 1 @two = stub 'rval', :safeevaluate => 2 @@ -15,38 +15,38 @@ it "should evaluate both branches" do lval = stub "lval" lval.expects(:safeevaluate).with(@scope).returns(1) rval = stub "rval" rval.expects(:safeevaluate).with(@scope).returns(2) - + operator = ast::ArithmeticOperator.new :rval => rval, :operator => "+", :lval => lval operator.evaluate(@scope) end it "should fail for an unknown operator" do lambda { operator = ast::ArithmeticOperator.new :lval => @one, :operator => "%", :rval => @two }.should raise_error end it "should call Puppet::Parser::Scope.number?" do - Puppet::Parser::Scope.expects(:number?).with(1).returns(1) - Puppet::Parser::Scope.expects(:number?).with(2).returns(2) - + Puppet::Parser::Scope.expects(:number?).with(1).returns(1) + Puppet::Parser::Scope.expects(:number?).with(2).returns(2) + ast::ArithmeticOperator.new(:lval => @one, :operator => "+", :rval => @two).evaluate(@scope) end - %w{ + - * / << >>}.each do |op| - it "should call ruby Numeric '#{op}'" do - one = stub 'one' - two = stub 'two' - operator = ast::ArithmeticOperator.new :lval => @one, :operator => op, :rval => @two - Puppet::Parser::Scope.stubs(:number?).with(1).returns(one) - Puppet::Parser::Scope.stubs(:number?).with(2).returns(two) - one.expects(:send).with(op,two) - operator.evaluate(@scope) - end - end + %w{ + - * / << >>}.each do |op| + it "should call ruby Numeric '#{op}'" do + one = stub 'one' + two = stub 'two' + operator = ast::ArithmeticOperator.new :lval => @one, :operator => op, :rval => @two + Puppet::Parser::Scope.stubs(:number?).with(1).returns(one) + Puppet::Parser::Scope.stubs(:number?).with(2).returns(two) + one.expects(:send).with(op,two) + operator.evaluate(@scope) + end + end it "should work even with numbers embedded in strings" do two = stub 'two', :safeevaluate => "2" one = stub 'one', :safeevaluate => "1" operator = ast::ArithmeticOperator.new :lval => two, :operator => "+", :rval => one @@ -63,10 +63,10 @@ it "should work for variables too" do @scope.expects(:lookupvar).with("one").returns(1) @scope.expects(:lookupvar).with("two").returns(2) one = ast::Variable.new( :value => "one" ) two = ast::Variable.new( :value => "two" ) - + operator = ast::ArithmeticOperator.new :lval => one, :operator => "+", :rval => two operator.evaluate(@scope).should == 3 end end