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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::CLI do
describe '.run' do
context 'when command is version' do
it 'shows gem version' do
expect { described_class.run('-v') }.to output("Gitlab Ruby Gem #{Gitlab::VERSION}\n").to_stdout
end
end
context 'when command is info' do
it 'shows environment info' do
command = expect { described_class.run('info') }
command.to output(/Gitlab endpoint is/).to_stdout
command.to output(/Gitlab private token is/).to_stdout
command.to output(/Ruby Version is/).to_stdout
command.to output(/Gitlab Ruby Gem/).to_stdout
end
end
context 'when command is help' do
it 'shows available actions' do
command = expect { described_class.run('help') }
command.to output(/Help Topics/).to_stdout
command.to output(/MergeRequests/).to_stdout
end
end
context 'when command is user' do
before { stub_get('/user', 'user') }
it 'shows executed command' do
expect { described_class.run('user') }.to output(/Gitlab.user/).to_stdout
end
it 'shows user data' do
command = expect { described_class.run('user') }
command.to output(/name/).to_stdout
command.to output(/John Smith/).to_stdout
end
end
context 'when command is users' do
before { stub_get('/users', 'users') }
it 'shows executed command' do
expect { described_class.run('users') }.to output(/Gitlab.users/).to_stdout
end
it 'shows users data' do
command = expect { described_class.run('users') }
command.to output(/name/).to_stdout
command.to output(/John Smith/).to_stdout
command.to output(/Jack Smith/).to_stdout
end
end
context 'when command is create_label' do
before { stub_post('/projects/Project/labels', 'label') }
let(:args) { ['Project', 'Backlog', '#DD10AA'] }
it 'shows executed command' do
command = expect { described_class.run('create_label', args) }
command.to output(/Gitlab.create_label Project, Backlog, #DD10AA/).to_stdout
end
end
end
describe '.start' do
before { stub_get('/user', 'user') }
context 'when command with excluded fields' do
let(:args) { ['user', '--except=id,email,name'] }
it 'shows user data with excluded fields' do
command = expect { described_class.start(args) }
command.not_to output(/John Smith/).to_stdout
command.to output(/bio/).to_stdout
command.to output(/created_at/).to_stdout
end
end
context 'when command with required fields' do
let(:args) { ['user', '--only=id,email,name'] }
it 'shows user data with required fields' do
command = expect { described_class.start(args) }
command.to output(/id/).to_stdout
command.to output(/name/).to_stdout
command.to output(/email/).to_stdout
command.to output(/John Smith/).to_stdout
command.not_to output(/bio/).to_stdout
command.not_to output(/created_at/).to_stdout
end
end
context 'when command with json output' do
let(:args) { ['user', '--json'] }
it 'renders output as json' do
expected = <<~OUT
{
"cmd": "Gitlab.user",
"result": {
"bio": null,
"blocked": false,
"created_at": "2012-09-17T09:41:56Z",
"dark_scheme": false,
"email": "john@example.com",
"id": 1,
"linkedin": "",
"name": "John Smith",
"skype": "",
"theme_id": 1,
"twitter": "john",
"username": "john.smith"
}
}
OUT
expect { described_class.start(args) }.to output(expected).to_stdout
end
end
context 'when fetching project with namespace/repo' do
it 'encodes delimiter' do
stub_get('/projects/gitlab-org%2Fgitlab-ce', 'project')
args = ['project', 'gitlab-org/gitlab-ce']
expect { described_class.start(args) }.to output(/id/).to_stdout
end
end
end
end
|