Sha256: a11b10f0a637a34d1d0ad874d6b5b1d073f69173d943c40e416a2df862296cab

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# coding: utf-8

RSpec.describe TTY::Pager::SystemPager, '#available' do
  let(:execs)   { ['less', 'more'] }

  subject(:pager) { described_class }

  it 'finds available command' do
    allow(pager).to receive(:executables).and_return(execs)
    allow(pager).to receive(:command_exists?).with('less') { true }
    allow(pager).to receive(:command_exists?).with('more') { false }
    expect(pager.available).to eql('less')
  end

  it "doesn't find command" do
    allow(pager).to receive(:executables).and_return(execs)
    allow(pager).to receive(:command_exists?) { false }
    expect(pager.available).to be_nil
  end

  it "takes precedence over other commands" do
    allow(pager).to receive(:command_exists?).with('more') { true }
    expect(pager.available('more')).to eql('more')
  end

  it "allows to query for available command" do
    allow(pager).to receive(:available).with('less') { true }
    expect(pager.available?('less')).to eq(true)
  end

  context "when given a multi-word executable" do
    let(:execs) { ["diff-so-fancy | less --tabs=4 -RFX"] }

    subject(:pager) { described_class }

    it "finds the command" do
      allow(pager).to receive(:executables).and_return(execs)
      allow(pager).to receive(:command_exists?).with("diff-so-fancy") { true }
      expect(pager.available).to eql(execs.first)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-pager-0.7.0 spec/unit/system/available_spec.rb
tty-pager-0.6.0 spec/unit/system/available_spec.rb