On Sep 27, 2008, at 4:21 AM, Brice Figureau wrote:
> +
> + it "should return 3 for 1 + 2" do
> + operator =
> Puppet::Parser::AST::ArithmeticOperator.new :lval => @one, :operator
> => "+", :rval => @two
> + operator.evaluate(@scope).should == 3
> + end
It *might* be better here to just test that the appropriate methods
are called on the numbers, rather than test the outcome. Not that the
outcome is likely to change, mind you, but our real test is that we're
passing through to someone else, not that a specific number shows up.
As before, I'm not particular about it, but that's how I'd do it, and
I think it does a better job of specifying that this is an interface
between Puppet and Ruby.
> diff --git a/spec/unit/parser/ast/minus.rb b/spec/unit/parser/ast/
> minus.rb
> new file mode 100644
> index 0000000..83bd92d
> --- /dev/null
> +++ b/spec/unit/parser/ast/minus.rb
> @@ -0,0 +1,36 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../../spec_helper'
> +
> +describe Puppet::Parser::AST::Minus do
> + before :each do
> + @scope = Puppet::Parser::Scope.new()
> + end
> +
> + it "should evaluate its argument" do
> + value = stub "value"
> + value.expects(:safeevaluate).with(@scope).returns(123)
> +
> + operator = Puppet::Parser::AST::Minus.new :value => value
> + operator.evaluate(@scope)
> + end
> +
> + it "should fail if argument is not a string or integer" do
> + array_ast = stub 'array_ast', :safeevaluate => [2]
> + operator = Puppet::Parser::AST::Minus.new :value => array_ast
> + lambda { operator.evaluate(@scope) }.should raise_error
> + end
> +
> + it "should work with integer as string" do
> + string = stub 'string', :safeevaluate => "123"
> + operator = Puppet::Parser::AST::Minus.new :value => string
> + operator.evaluate(@scope).should == -123
> + end
> +
> + it "should work with integers" do
> + int = stub 'int', :safeevaluate => 123
> + operator = Puppet::Parser::AST::Minus.new :value => int
> + operator.evaluate(@scope).should == -123
> + end
> +
> +end
> diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
> index ec8ab6d..143bfaf 100755
> --- a/spec/unit/parser/scope.rb
> +++ b/spec/unit/parser/scope.rb
> @@ -34,4 +34,54 @@ describe Puppet::Parser::Scope do
> end
>
> end
> +
> + describe Puppet::Parser::Scope, "when calling number?" do
> +
> + it "should return nil if called with anything not a number"
> do
> + Puppet::Parser::Scope.number?([2]).should == nil
> + end
Again, you can do '.should be_nil' here.
And if you find that you'd like something like that but custom
(e.g., .should be_float), you can add new matchers to RSpec:
http://tuples.us/2007/10/23/if-you-arent-writing-matchers-you-arent-using-rspec/
--
I object to doing things that computers can do. --Olin Shivers
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---