diff options
Diffstat (limited to 'spec/rubocop/cop/gitlab/doc_url_spec.rb')
-rw-r--r-- | spec/rubocop/cop/gitlab/doc_url_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/doc_url_spec.rb b/spec/rubocop/cop/gitlab/doc_url_spec.rb new file mode 100644 index 00000000000..4a7ef14ccbc --- /dev/null +++ b/spec/rubocop/cop/gitlab/doc_url_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' +require_relative '../../../../rubocop/cop/gitlab/doc_url' + +RSpec.describe RuboCop::Cop::Gitlab::DocUrl, feature_category: :not_owned do + context 'when string literal is added with docs url prefix' do + context 'when inlined' do + it 'registers an offense' do + expect_offense(<<~RUBY) + 'See [the docs](https://docs.gitlab.com/ee/user/permissions#roles).' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `#help_page_url` instead of directly including link. See https://docs.gitlab.com/ee/development/documentation/#linking-to-help-in-ruby. + RUBY + end + end + + context 'when multilined' do + it 'registers an offense' do + expect_offense(<<~'RUBY') + 'See the docs: ' \ + 'https://docs.gitlab.com/ee/user/permissions#roles' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `#help_page_url` instead of directly including link. See https://docs.gitlab.com/ee/development/documentation/#linking-to-help-in-ruby. + RUBY + end + end + + context 'with heredoc' do + it 'registers an offense' do + expect_offense(<<~RUBY) + <<-HEREDOC + See the docs: + https://docs.gitlab.com/ee/user/permissions#roles + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `#help_page_url` instead of directly including link. See https://docs.gitlab.com/ee/development/documentation/#linking-to-help-in-ruby. + HEREDOC + RUBY + end + end + end + + context 'when string literal is added without docs url prefix' do + context 'when inlined' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + '[The DevSecOps Platform](https://about.gitlab.com/)' + RUBY + end + end + + context 'when multilined' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + 'The DevSecOps Platform: ' \ + 'https://about.gitlab.com/' + RUBY + end + end + + context 'with heredoc' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + <<-HEREDOC + The DevSecOps Platform: + https://about.gitlab.com/ + HEREDOC + RUBY + end + end + end +end |