diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-21 06:09:41 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-21 06:09:41 +0000 |
commit | 54cf74492603787dc62f75a7af87380f117e6364 (patch) | |
tree | 0586c891c171859f1a3c29298bcf739f8c59a462 /spec/haml_lint | |
parent | 965a92325a3e5a63c53885c217f092faee6ac0b0 (diff) | |
download | gitlab-ce-54cf74492603787dc62f75a7af87380f117e6364.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/haml_lint')
-rw-r--r-- | spec/haml_lint/linter/documentation_links_spec.rb | 98 |
1 files changed, 54 insertions, 44 deletions
diff --git a/spec/haml_lint/linter/documentation_links_spec.rb b/spec/haml_lint/linter/documentation_links_spec.rb index 68de8317b82..5de455b6e8c 100644 --- a/spec/haml_lint/linter/documentation_links_spec.rb +++ b/spec/haml_lint/linter/documentation_links_spec.rb @@ -8,75 +8,85 @@ require Rails.root.join('haml_lint/linter/documentation_links') RSpec.describe HamlLint::Linter::DocumentationLinks do include_context 'linter' - context 'when link_to points to the existing file path' do - let(:haml) { "= link_to 'Description', help_page_path('README.md')" } + shared_examples 'link validation rules' do |link_pattern| + context 'when link_to points to the existing file path' do + let(:haml) { "= link_to 'Description', #{link_pattern}('README.md')" } - it { is_expected.not_to report_lint } - end + it { is_expected.not_to report_lint } + end - context 'when link_to points to the existing file with valid anchor' do - let(:haml) { "= link_to 'Description', help_page_path('README.md', anchor: 'overview'), target: '_blank'" } + context 'when link_to points to the existing file with valid anchor' do + let(:haml) { "= link_to 'Description', #{link_pattern}('README.md', anchor: 'overview'), target: '_blank'" } - it { is_expected.not_to report_lint } - end + it { is_expected.not_to report_lint } + end - context 'when link_to points to the existing file path without .md extension' do - let(:haml) { "= link_to 'Description', help_page_path('README')" } + context 'when link_to points to the existing file path without .md extension' do + let(:haml) { "= link_to 'Description', #{link_pattern}('README')" } - it { is_expected.not_to report_lint } - end + it { is_expected.not_to report_lint } + end - context 'when anchor is not correct' do - let(:haml) { "= link_to 'Description', help_page_path('README.md', anchor: 'wrong')" } + context 'when anchor is not correct' do + let(:haml) { "= link_to 'Description', #{link_pattern}('README.md', anchor: 'wrong')" } - it { is_expected.to report_lint } + it { is_expected.to report_lint } - context 'when help_page_path has multiple options' do - let(:haml) { "= link_to 'Description', help_page_path('README.md', key: :value, anchor: 'wrong')" } + context "when #{link_pattern} has multiple options" do + let(:haml) { "= link_to 'Description', #{link_pattern}('README.md', key: :value, anchor: 'wrong')" } + + it { is_expected.to report_lint } + end + end + + context 'when file path is wrong' do + let(:haml) { "= link_to 'Description', #{link_pattern}('wrong.md'), target: '_blank'" } it { is_expected.to report_lint } end - end - context 'when file path is wrong' do - let(:haml) { "= link_to 'Description', help_page_path('wrong.md'), target: '_blank'" } + context 'when link with wrong file path is assigned to a variable' do + let(:haml) { "- my_link = link_to 'Description', #{link_pattern}('wrong.md')" } - it { is_expected.to report_lint } - end + it { is_expected.to report_lint } + end - context 'when link with wrong file path is assigned to a variable' do - let(:haml) { "- my_link = link_to 'Description', help_page_path('wrong.md')" } + context 'when it is a broken code' do + let(:haml) { "= I am broken! ]]]]" } - it { is_expected.to report_lint } - end + it { is_expected.not_to report_lint } + end - context 'when it is a broken code' do - let(:haml) { "= I am broken! ]]]]" } + context 'when anchor belongs to a different element' do + let(:haml) { "= link_to 'Description', #{link_pattern}('README.md'), target: (anchor: 'blank')" } - it { is_expected.not_to report_lint } - end + it { is_expected.not_to report_lint } + end - context 'when anchor belongs to a different element' do - let(:haml) { "= link_to 'Description', help_page_path('README.md'), target: (anchor: 'blank')" } + context "when a simple #{link_pattern}" do + let(:haml) { "- url = #{link_pattern}('wrong.md')" } - it { is_expected.not_to report_lint } - end + it { is_expected.to report_lint } + end - context 'when a simple help_page_path' do - let(:haml) { "- url = help_page_path('wrong.md')" } + context 'when link is not a string' do + let(:haml) { "- url = #{link_pattern}(help_url)" } - it { is_expected.to report_lint } - end + it { is_expected.not_to report_lint } + end - context 'when link is not a string' do - let(:haml) { "- url = help_page_path(help_url)" } + context 'when link is a part of the tag' do + let(:haml) { ".data-form{ data: { url: #{link_pattern}('wrong.md') } }" } - it { is_expected.not_to report_lint } + it { is_expected.to report_lint } + end end - context 'when link is a part of the tag' do - let(:haml) { ".data-form{ data: { url: help_page_path('wrong.md') } }" } + context 'help_page_path' do + it_behaves_like 'link validation rules', 'help_page_path' + end - it { is_expected.to report_lint } + context 'help_page_url' do + it_behaves_like 'link validation rules', 'help_page_url' end end |