summaryrefslogtreecommitdiffstats
path: root/spec/unit/face/indirector_spec.rb
blob: bb06fcfe2cad14ab11fc46965633e0c8a750142c (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
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env rspec
require 'spec_helper'
require 'puppet/face/indirector'

describe Puppet::Face::Indirector do
  subject do
    instance = Puppet::Face::Indirector.new(:test, '0.0.1')
    indirection = stub('indirection',
                       :name => :stub_indirection,
                       :reset_terminus_class => nil)
    instance.stubs(:indirection).returns indirection
    instance
  end

  it "should be able to return a list of indirections" do
    Puppet::Face::Indirector.indirections.should be_include("catalog")
  end

  it "should be able to return a list of terminuses for a given indirection" do
    Puppet::Face::Indirector.terminus_classes(:catalog).should be_include("compiler")
  end

  describe "as an instance" do
    it "should be able to determine its indirection" do
      # Loading actions here an get, um, complicated
      Puppet::Face.stubs(:load_actions)
      Puppet::Face::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection)
    end
  end

  [:find, :search, :save, :destroy].each do |method|
    it "should define a '#{method}' action" do
      Puppet::Face::Indirector.should be_action(method)
    end

    it "should call the indirection method with options when the '#{method}' action is invoked" do
      subject.indirection.expects(method).with(:test, "myargs", {})
      subject.send(method, :test, "myargs")
    end
    it "should forward passed options" do
      subject.indirection.expects(method).with(:test, "action", {'one'=>'1'})
      subject.send(method, :test, 'action', {'one'=>'1'})
    end
  end

  it "should be able to override its indirection name" do
    subject.set_indirection_name :foo
    subject.indirection_name.should == :foo
  end

  it "should be able to set its terminus class" do
    subject.indirection.expects(:terminus_class=).with(:myterm)
    subject.set_terminus(:myterm)
  end

  it "should define a class-level 'info' action" do
    Puppet::Face::Indirector.should be_action(:info)
  end
end