Sha256: 9d19a53454bb1f924cca852f16d84ae9cf03b236b50c660c9a48292cc0fc83e2

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'kontena/plugin/shell/context'

describe Kontena::Plugin::Shell::Context do

  let(:subject) { described_class.new(nil) }

  it 'creates an empty context' do
    expect(subject.context).to be_empty
  end

  it 'creates a tokenized context from string' do
    expect(described_class.new('foo "bar baz"').context).to eq(['foo', 'bar baz'])
  end

  it 'creates a tokenized context from an array' do
    expect(described_class.new(['foo', 'bar']).context).to eq(['foo', 'bar'])
  end

  describe '#up' do
    it 'goes up' do
      subject.concat(['foo', 'bar'])
      subject.up
      expect(subject.to_s).to eq 'foo'
    end
  end

  describe '#top' do
    it 'clears the context' do
      subject.concat(['foo', 'bar'])
      subject.top
      expect(subject.to_s).to eq ''
    end
  end

  describe '#concat' do
    it 'adds to the context' do
      subject.concat(['foo', 'bar'])
      expect(subject.to_s).to eq 'foo bar'
    end

    it 'only adds everything up to an option' do
      subject.concat(['foo', 'bar', '--help'])
      expect(subject.to_s).to eq 'foo bar'
    end

    it 'only adds everything up to --' do
      subject.concat(['foo', 'bar', '--', 'bar'])
      expect(subject.to_s).to eq 'foo bar'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kontena-plugin-shell-0.2.0 spec/kontena/plugin/shell/context_spec.rb
kontena-plugin-shell-0.1.3 spec/kontena/plugin/shell/context_spec.rb
kontena-plugin-shell-0.1.2 spec/kontena/plugin/shell/context_spec.rb