summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/quick_actions/substitution_definition_spec.rb
blob: 8a4e9ab8bb778094a3eb9eb9d8dbac341485b726 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::QuickActions::SubstitutionDefinition do
  let(:content) do
    <<EOF
Hello! Let's do this!
/sub_name I like this stuff
/sub_name second substitution
EOF
  end

  subject do
    described_class.new(:sub_name, action_block: proc { |text| "#{text} foo" })
  end

  describe '#perform_substitution!' do
    it 'returns nil if content is nil' do
      expect(subject.perform_substitution(self, nil)).to be_nil
    end

    context 'when content contains command name' do
      it 'performs the substitution by default' do
        expect(subject.perform_substitution(self, content)).to eq <<EOF
Hello! Let's do this!
I like this stuff foo
/sub_name second substitution
EOF
      end
    end

    context 'when content contains command name in word' do
      let(:content) do
        <<EOF
Hello! Let's do this!
`/sub_names` I like this stuff
EOF
      end

      it 'does not perform the substitution' do
        expect(subject.perform_substitution(self, content)).to eq <<EOF
Hello! Let's do this!
`/sub_names` I like this stuff
EOF
      end
    end
  end
end