summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/console_spec.rb
blob: f043433b4c5d23c7bb7996742a69cb5b946f1ccf (plain)
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 'fast_spec_helper'

RSpec.describe Gitlab::Console do
  describe '.welcome!' do
    context 'when running in the Rails console' do
      before do
        allow(Gitlab::Runtime).to receive(:console?).and_return(true)
        allow(Gitlab::Metrics::BootTimeTracker.instance).to receive(:startup_time).and_return(42)
      end

      shared_examples 'console messages' do
        it 'prints system info' do
          expect($stdout).to receive(:puts).ordered.with(include("--"))
          expect($stdout).to receive(:puts).ordered.with(include("Ruby:"))
          expect($stdout).to receive(:puts).ordered.with(include("GitLab:"))
          expect($stdout).to receive(:puts).ordered.with(include("GitLab Shell:"))
          expect($stdout).to receive(:puts).ordered.with(include("PostgreSQL:"))
          expect($stdout).to receive(:puts).ordered.with(include("--"))
          expect($stdout).not_to receive(:puts).ordered

          described_class.welcome!
        end
      end

      # This is to add line coverage, not to actually verify behavior on macOS.
      context 'on darwin' do
        before do
          stub_const('RUBY_PLATFORM', 'x86_64-darwin-19')
        end

        it_behaves_like 'console messages'
      end

      it_behaves_like 'console messages'
    end

    context 'when not running in the Rails console' do
      before do
        allow(Gitlab::Runtime).to receive(:console?).and_return(false)
      end

      it 'does not print anything' do
        expect($stdout).not_to receive(:puts)

        described_class.welcome!
      end
    end
  end
end