3
require File.dirname(__FILE__) + '/../../../spec_helper'
5
require 'puppet/provider/confine/exists'
7
describe Puppet::Provider::Confine::Exists do
9
@confine = Puppet::Provider::Confine::Exists.new("/my/file")
12
it "should be named :exists" do
13
Puppet::Provider::Confine::Exists.name.should == :exists
16
it "should use the 'pass?' method to test validity" do
17
@confine.expects(:pass?).with("/my/file")
21
it "should return false if the value is false" do
22
@confine.pass?(false).should be_false
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
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
35
it "should produce a message saying that a file is missing" do
36
@confine.message("/my/file").should be_include("does not exist")
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")
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
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
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
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
69
confine = Puppet::Provider::Confine::Exists.new %w{/one /two /three /four}
70
confine.summary.should == %w{/two /four}
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}
78
Puppet::Provider::Confine::Exists.summarize([c1, c2, c3]).should == %w{one two three}