summaryrefslogtreecommitdiffstats
path: root/spec/unit/file_collection/lookup.rb
blob: 81cc618727cc281bf257820789f93009f8c47248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_collection/lookup'

class LookupTester
    include Puppet::FileCollection::Lookup
end

describe Puppet::FileCollection::Lookup do
    before do
        @tester = LookupTester.new

        @file_collection = mock 'file_collection'
        Puppet::FileCollection.stubs(:collection).returns @file_collection
    end

    it "should use the file collection to determine the index of the file name" do
        @file_collection.expects(:index).with("/my/file").returns 50

        @tester.file = "/my/file"
        @tester.file_index.should == 50
    end

    it "should return nil as the file name if no index is set" do
        @tester.file.should be_nil
    end

    it "should use the file collection to convert the index to a file name" do
        @file_collection.expects(:path).with(25).returns "/path/to/file"

        @tester.file_index = 25

        @tester.file.should == "/path/to/file"
    end

    it "should support a line attribute" do
        @tester.line = 50
        @tester.line.should == 50
    end

    it "should default to the global file collection" do
        Puppet::FileCollection.expects(:collection).returns "collection"
        @tester.file_collection.should == "collection"
    end
end