File: shell_spec.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (88 lines) | stat: -rw-r--r-- 2,302 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Shell do
  before do
    described_class.setup
  end

  describe '.execute' do
    context 'when invalid command' do
      it 'raises RuntimeError' do
        expect { described_class.execute 'foobar', [] }.to raise_error(RuntimeError)
      end
    end
  end

  describe '.history' do
    before do
      @history = described_class.history
    end

    it 'returns a Gitlab::Shell::History instance' do
      expect(@history).to be_a Gitlab::Shell::History
    end

    it 'responds to :save' do
      expect(@history).to respond_to :save
    end

    it 'responds to :load' do
      expect(@history).to respond_to :load
    end

    it 'responds to :<<' do
      expect(@history).to respond_to :<<
    end
  end

  describe '.setup' do
    it 'sets the Readline completion_proc' do
      completion = Readline.completion_proc
      expect(completion).to be_truthy
      expect(completion).to be_a Proc
    end

    it 'sets the Readline completion_append_character' do
      completion_character = Readline.completion_append_character
      expect(completion_character).to eq(' ')
    end
  end

  describe '.completion' do
    before do
      @comp = described_class.completion
    end

    it 'returns a Proc object' do
      expect(@comp).to be_a Proc
    end

    context 'when called with an argument' do
      it 'returns an Array of matching commands' do
        completed_cmds = @comp.call 'issue'
        expect(completed_cmds).to be_a Array
        expect(completed_cmds.sort).to eq(%w[issue issue_label_event issue_label_events issue_links issue_note issue_notes issue_state_event issue_state_events issues])
      end
    end
  end

  describe '.parse_input' do
    context 'with arguments' do
      it 'sets command & arguments' do
        described_class.parse_input('create_branch 1 "api" "master"')
        expect(described_class.command).to eq('create_branch')
        expect(described_class.arguments).to eq(%w[1 api master])
      end
    end

    context 'without arguments' do
      it 'sets command & empty arguments' do
        described_class.parse_input('exit')
        expect(described_class.command).to eq('exit')
        expect(described_class.arguments).to be_empty
      end
    end
  end
end