~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to spec/unit/provider/confine/exists.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

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
require 'puppet/provider/confine/exists'
 
6
 
 
7
describe Puppet::Provider::Confine::Exists do
 
8
    before do
 
9
        @confine = Puppet::Provider::Confine::Exists.new("/my/file")
 
10
    end
 
11
 
 
12
    it "should be named :exists" do
 
13
        Puppet::Provider::Confine::Exists.name.should == :exists
 
14
    end
 
15
 
 
16
    it "should use the 'pass?' method to test validity" do
 
17
        @confine.expects(:pass?).with("/my/file")
 
18
        @confine.valid?
 
19
    end
 
20
 
 
21
    it "should return false if the value is false" do
 
22
        @confine.pass?(false).should be_false
 
23
    end
 
24
 
 
25
    it "should return false if the value does not point to a file" do
 
26
        FileTest.expects(:exist?).with("/my/file").returns false
 
27
        @confine.pass?("/my/file").should be_false
 
28
    end
 
29
 
 
30
    it "should return true if the value points to a file" do
 
31
        FileTest.expects(:exist?).with("/my/file").returns true
 
32
        @confine.pass?("/my/file").should be_true
 
33
    end
 
34
 
 
35
    it "should produce a message saying that a file is missing" do
 
36
        @confine.message("/my/file").should be_include("does not exist")
 
37
    end
 
38
 
 
39
    describe "and the confine is for binaries" do
 
40
        before { @confine.stubs(:for_binary).returns true }
 
41
        it "should use its 'binary' method to look up the full path of the file" do
 
42
            @confine.expects(:binary).returns nil
 
43
            @confine.pass?("/my/file")
 
44
        end
 
45
 
 
46
        it "should return false if no binary can be found" do
 
47
            @confine.expects(:binary).with("/my/file").returns nil
 
48
            @confine.pass?("/my/file").should be_false
 
49
        end
 
50
 
 
51
        it "should return true if the binary can be found and the file exists" do
 
52
            @confine.expects(:binary).with("/my/file").returns "/my/file"
 
53
            FileTest.expects(:exist?).with("/my/file").returns true
 
54
            @confine.pass?("/my/file").should be_true
 
55
        end
 
56
 
 
57
        it "should return false if the binary can be found but the file does not exist" do
 
58
            @confine.expects(:binary).with("/my/file").returns "/my/file"
 
59
            FileTest.expects(:exist?).with("/my/file").returns true
 
60
            @confine.pass?("/my/file").should be_true
 
61
        end
 
62
    end
 
63
 
 
64
    it "should produce a summary containing all missing files" do
 
65
        FileTest.stubs(:exist?).returns true
 
66
        FileTest.expects(:exist?).with("/two").returns false
 
67
        FileTest.expects(:exist?).with("/four").returns false
 
68
 
 
69
        confine = Puppet::Provider::Confine::Exists.new %w{/one /two /three /four}
 
70
        confine.summary.should == %w{/two /four}
 
71
    end
 
72
 
 
73
    it "should summarize multiple instances by returning a flattened array of their summaries" do
 
74
        c1 = mock '1', :summary => %w{one}
 
75
        c2 = mock '2', :summary => %w{two}
 
76
        c3 = mock '3', :summary => %w{three}
 
77
 
 
78
        Puppet::Provider::Confine::Exists.summarize([c1, c2, c3]).should == %w{one two three}
 
79
    end
 
80
end