2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-24 23:11:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::QuickActions::SubstitutionDefinition do
|
|
|
|
let(:content) do
|
|
|
|
<<EOF
|
|
|
|
Hello! Let's do this!
|
|
|
|
/sub_name I like this stuff
|
|
|
|
EOF
|
|
|
|
end
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2017-07-24 23:11:22 -04:00
|
|
|
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
|
|
|
|
|
2020-02-13 07:08:49 -05:00
|
|
|
context 'when content contains command name' do
|
|
|
|
it 'performs the substitution by default' do
|
|
|
|
expect(subject.perform_substitution(self, content)).to eq <<EOF
|
2017-07-24 23:11:22 -04:00
|
|
|
Hello! Let's do this!
|
|
|
|
I like this stuff foo
|
|
|
|
EOF
|
2020-02-13 07:08:49 -05:00
|
|
|
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
|
2017-07-24 23:11:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#match' do
|
|
|
|
it 'checks the content for the command' do
|
|
|
|
expect(subject.match(content)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the match data' do
|
|
|
|
data = subject.match(content)
|
|
|
|
expect(data).to be_a(MatchData)
|
|
|
|
expect(data[1]).to eq('I like this stuff')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is nil if content does not have the command' do
|
|
|
|
expect(subject.match('blah')).to be_falsey
|
|
|
|
end
|
2020-02-13 07:08:49 -05:00
|
|
|
|
|
|
|
it 'is nil if content contains the command as prefix' do
|
|
|
|
expect(subject.match('/sub_namex')).to be_falsey
|
|
|
|
end
|
2017-07-24 23:11:22 -04:00
|
|
|
end
|
|
|
|
end
|