Sha256: e333f15d21ca25ca77ff181b01aac1c20b0e612dfe7cabc379fa0ace089b0bd5

Contents?: true

Size: 1008 Bytes

Versions: 11

Compression:

Stored size: 1008 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

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

  subject(:editor) { described_class }

  before { allow(editor).to receive(:executables).and_return(execs) }

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

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

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

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

  context 'when custom command' do
    before { allow(system).to receive(:exists?).with(name).and_return(true) }

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tty-0.5.0 spec/tty/system/editor/available_spec.rb
tty-0.4.0 spec/tty/system/editor/available_spec.rb
tty-0.3.2 spec/tty/system/editor/available_spec.rb
tty-0.3.1 spec/tty/system/editor/available_spec.rb
tty-0.3.0 spec/tty/system/editor/available_spec.rb
tty-0.2.1 spec/tty/system/editor/available_spec.rb
tty-0.2.0 spec/tty/system/editor/available_spec.rb
tty-0.1.3 spec/tty/system/editor/available_spec.rb
tty-0.1.2 spec/tty/system/editor/available_spec.rb
tty-0.1.1 spec/tty/system/editor/available_spec.rb
tty-0.1.0 spec/tty/system/editor/available_spec.rb