File: help_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 (51 lines) | stat: -rw-r--r-- 1,571 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Help do
  describe '.ri_cmd' do
    context 'when ri command found' do
      it 'returns the path to RI' do
        allow(described_class).to receive(:`).with(/which ri/).and_return('/usr/bin/ri')
        expect(described_class.ri_cmd).to eq('/usr/bin/ri')
      end
    end

    context 'when ri command NOT found' do
      it 'raises RuntimeError' do
        allow(described_class).to receive(:`).with(/which ri/).and_return('')
        expect { described_class.ri_cmd }.to raise_error RuntimeError
      end
    end
  end

  describe '.change_help_output!' do
    before do
      @cmd = 'create_branch'
      @help_output = "Gitlab.#{@cmd}(4, 'new-branch', 'master')"
      @help_output_with_options = 'Gitlab.groups({ per_page: 3 })'
    end

    it 'returns a String of modified output' do
      described_class.change_help_output! @cmd, @help_output
      expect(@help_output).to eq("Gitlab.create_branch(4, 'new-branch', 'master')")
    end

    it 'formats options hash and return a String of modified output' do
      described_class.change_help_output! 'groups', @help_output_with_options
      expect(@help_output_with_options).to eq('Gitlab.groups({ per_page: 3 })')
    end
  end

  describe '.namespace' do
    before do
      @cmd = 'create_tag'
      @namespace = described_class.namespace @cmd
    end

    it 'returns the full namespace for a command' do
      expect(@namespace).to be_a String
      expect(@namespace).to eq("Gitlab::Client::Tags.#{@cmd}")
    end
  end
end