Sha256: 6370bbf15877480c8d1a65b7fddac39a0e62d1a6dbc6997e466fc7b7d27629c5

Contents?: true

Size: 1.71 KB

Versions: 35

Compression:

Stored size: 1.71 KB

Contents

#!/usr/bin/env rspec
require '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

35 entries across 35 versions & 3 rubygems

Version Path
puppet-2.7.26 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.25 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.24 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.23 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.22 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.21 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.20 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.20.rc1 spec/unit/parser/ast/in_operator_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.19 spec/unit/parser/ast/in_operator_spec.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/in_operator_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/parser/ast/in_operator_spec.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.18 spec/unit/parser/ast/in_operator_spec.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/in_operator_spec.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.17 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.16 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.14 spec/unit/parser/ast/in_operator_spec.rb
puppet-2.7.13 spec/unit/parser/ast/in_operator_spec.rb