Sha256: b95ad6b400fac7aab409a66fb68fcde728ab817a163ccf8a4aceae72608569bb

Contents?: true

Size: 953 Bytes

Versions: 2

Compression:

Stored size: 953 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::System::Editor, '#available' do
  let(:execs) { ['vi', 'emacs'] }
  let(:editor) { 'sublime' }
  let(:system) { TTY::System }

  subject { described_class }

  before { subject.stub(:executables).and_return(execs) }

  context 'when editor exists' do
    before {
      system.stub(:exists?).with('vi').and_return(true)
      system.stub(:exists?).with('emacs').and_return(false)
    }

    it 'finds single command' do
      expect(subject.available).to eql('vi')
    end
  end

  context 'when no command exists' do
    before { system.stub(:exists?).and_return(false) }

    it "doesn't find command" do
      expect(subject.available).to be_nil
    end
  end

  context 'when custom command' do
    before { system.stub(:exists?).with(editor).and_return(true) }

    it "takes precedence over other commands" do
      expect(subject.available(editor)).to eql(editor)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/system/editor/available_spec.rb
tty-0.0.10 spec/tty/system/editor/available_spec.rb