debian-mirror-gitlab/spec/lib/gitlab/quick_actions/substitution_definition_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::QuickActions::SubstitutionDefinition do
2017-09-10 17:25:29 +05:30
let(:content) do
<<EOF
Hello! Let's do this!
/sub_name I like this stuff
2020-04-08 14:13:33 +05:30
/sub_name second substitution
2017-09-10 17:25:29 +05:30
EOF
end
2020-01-01 13:55:28 +05:30
2017-09-10 17:25:29 +05:30
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-03-13 15:44:24 +05:30
context 'when content contains command name' do
it 'performs the substitution by default' do
expect(subject.perform_substitution(self, content)).to eq <<EOF
2017-09-10 17:25:29 +05:30
Hello! Let's do this!
I like this stuff foo
2020-04-08 14:13:33 +05:30
/sub_name second substitution
2017-09-10 17:25:29 +05:30
EOF
2020-03-13 15:44:24 +05:30
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-09-10 17:25:29 +05:30
end
end
end