Sha256: 1895eeb6dfe2626cef44839fb17bd27fd8b790909300b8342c03565f9880699b

Contents?: true

Size: 1.61 KB

Versions: 19

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

describe Puppet::Parser::AST::MatchOperator do
  before :each do
    @scope = Puppet::Parser::Scope.new

    @lval = stub 'lval'
    @lval.stubs(:safeevaluate).with(@scope).returns("this is a string")

    @rval = stub 'rval'
    @rval.stubs(:evaluate_match)

    @operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => "=~"
  end

  it "should evaluate the left operand" do
    @lval.expects(:safeevaluate).with(@scope)

    @operator.evaluate(@scope)
  end

  it "should fail for an unknown operator" do
    lambda { operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :operator => "unknown", :rval => @rval }.should raise_error
  end

  it "should evaluate_match the left operand" do
    @rval.expects(:evaluate_match).with("this is a string", @scope).returns(:match)

    @operator.evaluate(@scope)
  end

  { "=~" => true, "!~" => false }.each do |op, res|
    it "should return #{res} if the regexp matches with #{op}" do
      match = stub 'match'
      @rval.stubs(:evaluate_match).with("this is a string", @scope).returns(match)

      operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
      operator.evaluate(@scope).should == res
    end

    it "should return #{!res} if the regexp doesn't match" do
      @rval.stubs(:evaluate_match).with("this is a string", @scope).returns(nil)

      operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
      operator.evaluate(@scope).should == !res
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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