Sha256: aa6538850c6198161f1bd020ee07b2d7f0e2e1fe9f86edf1d485133780c963cc

Contents?: true

Size: 1.81 KB

Versions: 92

Compression:

Stored size: 1.81 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/parser/ast/in_operator'

describe Puppet::Parser::AST::InOperator do
  before :each do
    node     = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    @scope   = Puppet::Parser::Scope.new(compiler)

    @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

92 entries across 92 versions & 2 rubygems

Version Path
puppet-3.8.7 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.6 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.5 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.4 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.3 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.2 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.1 spec/unit/parser/ast/in_operator_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/parser/ast/in_operator_spec.rb