Sha256: 91802639c5da2a061eaa9a51484be68f2ad5c16f50131d7251828de569bd3233

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env rspec
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")
      subject.width.should == 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")
      subject.width.should == 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")
      subject.width.should == 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")
      subject.width.should == width
    end

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

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
puppet-2.7.26 spec/unit/util/terminal_spec.rb
puppet-2.7.25 spec/unit/util/terminal_spec.rb
puppet-2.7.24 spec/unit/util/terminal_spec.rb
puppet-2.7.23 spec/unit/util/terminal_spec.rb
puppet-2.7.22 spec/unit/util/terminal_spec.rb
puppet-2.7.21 spec/unit/util/terminal_spec.rb
puppet-2.7.20 spec/unit/util/terminal_spec.rb
puppet-2.7.20.rc1 spec/unit/util/terminal_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/terminal_spec.rb
puppet-2.7.19 spec/unit/util/terminal_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/terminal_spec.rb
puppet-2.7.18 spec/unit/util/terminal_spec.rb
puppet-2.7.17 spec/unit/util/terminal_spec.rb
puppet-2.7.16 spec/unit/util/terminal_spec.rb
puppet-2.7.14 spec/unit/util/terminal_spec.rb