Sha256: 796f24f585416592c6bfff7cca358d4ee650bcd1d0172b923056d0d35c780156

Contents?: true

Size: 1.74 KB

Versions: 19

Compression:

Stored size: 1.74 KB

Contents

#!/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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-2.6.18 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.17 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.16 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.15 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.14 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.13 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.12 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.11 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.10 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.9 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.8 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.7 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.6 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.5 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.4 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.3 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.2 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.1 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.6.0 spec/unit/parser/ast/in_operator_spec.rb