File: describe_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (97 lines) | stat: -rw-r--r-- 2,638 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'spec_helper'

require 'puppet/application/describe'

describe Puppet::Application::Describe do
  before :each do
    @describe = Puppet::Application[:describe]
  end

  it "should declare a main command" do
    expect(@describe).to respond_to(:main)
  end

  it "should declare a preinit block" do
    expect(@describe).to respond_to(:preinit)
  end

  [:providers,:list,:meta].each do |option|
    it "should declare handle_#{option} method" do
      expect(@describe).to respond_to("handle_#{option}".to_sym)
    end

    it "should store argument value when calling handle_#{option}" do
      expect(@describe.options).to receive(:[]=).with("#{option}".to_sym, 'arg')
      @describe.send("handle_#{option}".to_sym, 'arg')
    end
  end


  describe "in preinit" do
    it "should set options[:parameters] to true" do
      @describe.preinit

      expect(@describe.options[:parameters]).to be_truthy
    end
  end

  describe "when handling parameters" do
    it "should set options[:parameters] to false" do
      @describe.handle_short(nil)

      expect(@describe.options[:parameters]).to be_falsey
    end
  end

  describe "during setup" do
    it "should collect arguments in options[:types]" do
      allow(@describe.command_line).to receive(:args).and_return(['1','2'])
      @describe.setup

      expect(@describe.options[:types]).to eq(['1','2'])
    end
  end

  describe "when running" do

    before :each do
      @typedoc = double('type_doc')
      allow(TypeDoc).to receive(:new).and_return(@typedoc)
    end

    it "should call list_types if options list is set" do
      @describe.options[:list] = true

      expect(@typedoc).to receive(:list_types)

      @describe.run_command
    end

    it "should call format_type for each given types" do
      @describe.options[:list] = false
      @describe.options[:types] = ['type']

      expect(@typedoc).to receive(:format_type).with('type', @describe.options)
      @describe.run_command
    end
  end

  it "should format text with long non-space runs without garbling" do
    @f = Formatter.new(76)

    @teststring = <<TESTSTRING
. 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 nick@magpie.puppetlabs.lan
**this part should not repeat!**
TESTSTRING

    @expected_result = <<EXPECTED
.
1234567890123456789012345678901234567890123456789012345678901234567890123456
7890123456789012345678901234567890 nick@magpie.puppetlabs.lan
**this part should not repeat!**
EXPECTED

    result = @f.wrap(@teststring, {:indent => 0, :scrub => true})
    expect(result).to eql(@expected_result)
  end
end