~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to spec/unit/parser/ast/match_operator.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../../spec_helper'
 
4
 
 
5
describe Puppet::Parser::AST::MatchOperator do
 
6
    before :each do
 
7
        @scope = Puppet::Parser::Scope.new()
 
8
 
 
9
        @lval = stub 'lval'
 
10
        @lval.stubs(:safeevaluate).with(@scope).returns("this is a string")
 
11
 
 
12
        @rval = stub 'rval'
 
13
        @rval.stubs(:evaluate_match)
 
14
 
 
15
        @operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => "=~"
 
16
    end
 
17
 
 
18
    it "should evaluate the left operand" do
 
19
        @lval.expects(:safeevaluate).with(@scope)
 
20
 
 
21
        @operator.evaluate(@scope)
 
22
    end
 
23
 
 
24
    it "should fail for an unknown operator" do
 
25
        lambda { operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :operator => "unknown", :rval => @rval }.should raise_error
 
26
    end
 
27
 
 
28
    it "should evaluate_match the left operand" do
 
29
        @rval.expects(:evaluate_match).with("this is a string", @scope).returns(:match)
 
30
 
 
31
        @operator.evaluate(@scope)
 
32
    end
 
33
 
 
34
    { "=~" => true, "!~" => false }.each do |op, res|
 
35
        it "should return #{res} if the regexp matches with #{op}" do
 
36
            match = stub 'match'
 
37
            @rval.stubs(:evaluate_match).with("this is a string", @scope).returns(match)
 
38
 
 
39
            operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
 
40
            operator.evaluate(@scope).should == res
 
41
        end
 
42
 
 
43
        it "should return #{!res} if the regexp doesn't match" do
 
44
            @rval.stubs(:evaluate_match).with("this is a string", @scope).returns(nil)
 
45
 
 
46
            operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
 
47
            operator.evaluate(@scope).should == !res
 
48
        end
 
49
    end
 
50
end