summaryrefslogtreecommitdiffstats
path: root/spec/unit/interface/action_builder_spec.rb
blob: 5b04df900e69f7d106628fadf3ccf04b9b10961f (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
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env rspec
require 'spec_helper'
require 'puppet/interface/action_builder'

describe Puppet::Interface::ActionBuilder do
  describe "::build" do
    it "should build an action" do
      action = Puppet::Interface::ActionBuilder.build(nil, :foo) do
      end
      action.should be_a(Puppet::Interface::Action)
      action.name.should == :foo
    end

    it "should define a method on the face which invokes the action" do
      face = Puppet::Interface.new(:action_builder_test_interface, '0.0.1')
      action = Puppet::Interface::ActionBuilder.build(face, :foo) do
        when_invoked do
          "invoked the method"
        end
      end

      face.foo.should == "invoked the method"
    end

    it "should require a block" do
      expect { Puppet::Interface::ActionBuilder.build(nil, :foo) }.
        should raise_error("Action :foo must specify a block")
    end

    describe "when handling options" do
      let :face do Puppet::Interface.new(:option_handling, '0.0.1') end

      it "should have a #option DSL function" do
        method = nil
        Puppet::Interface::ActionBuilder.build(face, :foo) do
          method = self.method(:option)
        end
        method.should be
      end

      it "should define an option without a block" do
        action = Puppet::Interface::ActionBuilder.build(face, :foo) do
          option "--bar"
        end
        action.should be_option :bar
      end

      it "should accept an empty block" do
        action = Puppet::Interface::ActionBuilder.build(face, :foo) do
          option "--bar" do
            # This space left deliberately blank.
          end
        end
        action.should be_option :bar
      end
    end

    context "inline documentation" do
      let :face do Puppet::Interface.new(:inline_action_docs, '0.0.1') end

      it "should set the summary" do
        action = Puppet::Interface::ActionBuilder.build(face, :foo) do
          summary "this is some text"
        end
        action.summary.should == "this is some text"
      end
    end
  end
end