Sha256: 2b9083223dcfd493af1f57f311a254b5d93037fb4fff575ef8751ded9d80aedd

Contents?: true

Size: 1.43 KB

Versions: 278

Compression:

Stored size: 1.43 KB

Contents

#! /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

Version data entries

278 entries across 278 versions & 1 rubygems

Version Path
puppet-6.4.0 spec/unit/util/terminal_spec.rb
puppet-6.4.0-x86-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.4.0-x64-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.4.0-universal-darwin spec/unit/util/terminal_spec.rb
puppet-6.0.7 spec/unit/util/terminal_spec.rb
puppet-6.0.7-x86-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.0.7-x64-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.0.7-universal-darwin spec/unit/util/terminal_spec.rb
puppet-5.5.12 spec/unit/util/terminal_spec.rb
puppet-5.5.12-x86-mingw32 spec/unit/util/terminal_spec.rb
puppet-5.5.12-x64-mingw32 spec/unit/util/terminal_spec.rb
puppet-5.5.12-universal-darwin spec/unit/util/terminal_spec.rb
puppet-6.3.0 spec/unit/util/terminal_spec.rb
puppet-6.3.0-x86-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.3.0-x64-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.3.0-universal-darwin spec/unit/util/terminal_spec.rb
puppet-6.2.0 spec/unit/util/terminal_spec.rb
puppet-6.2.0-x86-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.2.0-x64-mingw32 spec/unit/util/terminal_spec.rb
puppet-6.2.0-universal-darwin spec/unit/util/terminal_spec.rb