Welcome to mirror list, hosted at ThFree Co, Russian Federation.

debug_spec.rb « tooling « lib « tooling « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c506a93a24a15abf8c6b87bf6cc3637e6ed09861 (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
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
# frozen_string_literal: true

require_relative '../../../../tooling/lib/tooling/debug'

RSpec.describe Tooling::Debug, feature_category: :tooling do
  let(:some_class) do
    Class.new do
      include Tooling::Debug

      def print_hello_world
        print 'hello world'
      end

      def puts_hello_world
        puts 'hello world'
      end
    end
  end

  after do
    # Ensure that debug mode is default disabled at start of specs.
    described_class.debug = false
  end

  shared_context 'when debug is enabled' do
    before do
      described_class.debug = true
    end
  end

  shared_context 'when debug is disabled' do
    before do
      described_class.debug = false
    end
  end

  shared_examples 'writes to stdout' do |str|
    it 'writes to stdout' do
      expect { subject }.to output(str).to_stdout
    end
  end

  shared_examples 'does not write to stdout' do
    it 'does not write to stdout' do
      expect { subject }.not_to output.to_stdout
    end
  end

  describe '#print' do
    subject { some_class.new.print_hello_world }

    context 'when debug is enabled' do
      include_context 'when debug is enabled'
      include_examples 'writes to stdout', 'hello world'
    end

    context 'when debug is disabled' do
      include_context 'when debug is disabled'
      include_examples 'does not write to stdout'
    end
  end

  describe '#puts' do
    subject { some_class.new.puts_hello_world }

    context 'when debug is enabled' do
      include_context 'when debug is enabled'
      include_examples 'writes to stdout', "hello world\n"
    end

    context 'when debug is disabled' do
      include_context 'when debug is disabled'
      include_examples 'does not write to stdout'
    end
  end
end