blob: 9d3cab712f0d47c3c8c68a3ba7c63d7e40a55497 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/parser/ast/in_operator'
describe Puppet::Parser::AST::InOperator do
before :each do
@scope = Puppet::Parser::Scope.new()
@lval = stub 'lval'
@lval.stubs(:safeevaluate).with(@scope).returns("left")
@rval = stub 'rval'
@rval.stubs(:safeevaluate).with(@scope).returns("right")
@operator = Puppet::Parser::AST::InOperator.new :lval => @lval, :rval => @rval
end
it "should evaluate the left operand" do
@lval.expects(:safeevaluate).with(@scope).returns("string")
@operator.evaluate(@scope)
end
it "should evaluate the right operand" do
@rval.expects(:safeevaluate).with(@scope).returns("string")
@operator.evaluate(@scope)
end
it "should raise an argument error if lval is not a string" do
@lval.expects(:safeevaluate).with(@scope).returns([12,13])
lambda { @operator.evaluate(@scope) }.should raise_error
end
it "should raise an argument error if rval doesn't support the include? method" do
@rval.expects(:safeevaluate).with(@scope).returns(stub('value'))
lambda { @operator.evaluate(@scope) }.should raise_error
end
it "should not raise an argument error if rval supports the include? method" do
@rval.expects(:safeevaluate).with(@scope).returns(stub('value', :include? => true))
lambda { @operator.evaluate(@scope) }.should_not raise_error
end
it "should return rval.include?(lval)" do
lval = stub 'lvalue', :is_a? => true
@lval.stubs(:safeevaluate).with(@scope).returns(lval)
rval = stub 'rvalue'
@rval.stubs(:safeevaluate).with(@scope).returns(rval)
rval.expects(:include?).with(lval).returns(:result)
@operator.evaluate(@scope).should == :result
end
end
|