On Sep 30, 2008, at 8:33 AM, Brice Figureau wrote:
>
> On Tue, 2008-09-30 at 14:20 +0200, Brice Figureau wrote:
>> On Mon, 2008-09-29 at 13:09 -0500, Luke Kanies wrote:
>>> 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.
>>
>> Unfortunately the following doesn't work:
>>
>> it "should return 3 for 1 + 2" do
>> operator = AST::ArithmeticOperator.new :lval =>
>> @one, :operator => "+", :rval => @two
>> 1.expects(:+).with(3)
>> operator.evaluate(@scope)
>> end
>>
>> It doesn't seem possible to pose expectations on Fixnums.
>> I tried every possible ways, like:
>> Fixnum.expects(:+)
>> or (since that's really send that is called)
>> 1.expects(:send)
>> or
>> Fixnum.expects(:send)
>>
>> The error message is:
>> "no virtual class for Fixnum"
>
> I workarounded (if that word exists) with the following:
> 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)
>
> 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
>
> which I don't find really satifying, since it imposes that the test
> has
> knowledge of the inner working of AST::ArithmeticOperator :-(
You're right, that is a bit messier than we might like.
I'd say it's your call on whether to keep your old, explicit tests or
metaprogram them.
--
I had a linguistics professor who said that it's man's ability to use
language that makes him the dominant species on the planet. That may
be. But I think there's one other thing that separates us from animals.
We aren't afraid of vacuum cleaners. --Jeff Stilson
---------------------------------------------------------------------
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
-~----------~----~----~----~------~----~------~--~---