File: terminal_spec.rb

package info (click to toggle)
puppet 4.8.2-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,736 kB
  • ctags: 14,616
  • sloc: ruby: 236,754; xml: 1,586; sh: 1,178; lisp: 299; sql: 103; yacc: 72; makefile: 52
file content (42 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (3)
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
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/util/terminal'

describe Puppet::Util::Terminal do
  describe '.width' do
    before { Puppet.features.stubs(:posix?).returns(true) }

    it 'should invoke `stty` and return the width' do
      height, width = 100, 200
      subject.expects(:`).with('stty size 2>/dev/null').returns("#{height} #{width}\n")
      expect(subject.width).to eq(width)
    end

    it 'should use `tput` if `stty` is unavailable' do
      width = 200
      subject.expects(:`).with('stty size 2>/dev/null').returns("\n")
      subject.expects(:`).with('tput cols 2>/dev/null').returns("#{width}\n")
      expect(subject.width).to eq(width)
    end

    it 'should default to 80 columns if `tput` and `stty` are unavailable' do
      width = 80
      subject.expects(:`).with('stty size 2>/dev/null').returns("\n")
      subject.expects(:`).with('tput cols 2>/dev/null').returns("\n")
      expect(subject.width).to eq(width)
    end

    it 'should default to 80 columns if `tput` or `stty` raise exceptions' do
      width = 80
      subject.expects(:`).with('stty size 2>/dev/null').raises()
      subject.stubs(:`).with('tput cols 2>/dev/null').returns("#{width + 1000}\n")
      expect(subject.width).to eq(width)
    end

    it 'should default to 80 columns if not in a POSIX environment' do
      width = 80
      Puppet.features.stubs(:posix?).returns(false)
      expect(subject.width).to eq(width)
    end
  end
end