diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/haml_lint | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/haml_lint')
-rw-r--r-- | spec/haml_lint/linter/documentation_links_spec.rb | 82 | ||||
-rw-r--r-- | spec/haml_lint/linter/no_plain_nodes_spec.rb | 2 |
2 files changed, 83 insertions, 1 deletions
diff --git a/spec/haml_lint/linter/documentation_links_spec.rb b/spec/haml_lint/linter/documentation_links_spec.rb new file mode 100644 index 00000000000..68de8317b82 --- /dev/null +++ b/spec/haml_lint/linter/documentation_links_spec.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'haml_lint' +require 'haml_lint/spec' +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')" } + + 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'" } + + 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')" } + + 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')" } + + 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')" } + + 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'" } + + 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')" } + + it { is_expected.to report_lint } + end + + context 'when it is a broken code' do + let(:haml) { "= I am broken! ]]]]" } + + 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')" } + + it { is_expected.not_to report_lint } + end + + context 'when a simple help_page_path' do + let(:haml) { "- url = help_page_path('wrong.md')" } + + it { is_expected.to report_lint } + end + + context 'when link is not a string' do + let(:haml) { "- url = help_page_path(help_url)" } + + it { is_expected.not_to report_lint } + end + + context 'when link is a part of the tag' do + let(:haml) { ".data-form{ data: { url: help_page_path('wrong.md') } }" } + + it { is_expected.to report_lint } + end +end diff --git a/spec/haml_lint/linter/no_plain_nodes_spec.rb b/spec/haml_lint/linter/no_plain_nodes_spec.rb index dc647467db6..08f7e6131cc 100644 --- a/spec/haml_lint/linter/no_plain_nodes_spec.rb +++ b/spec/haml_lint/linter/no_plain_nodes_spec.rb @@ -5,7 +5,7 @@ require 'haml_lint' require 'haml_lint/spec' require Rails.root.join('haml_lint/linter/no_plain_nodes') -describe HamlLint::Linter::NoPlainNodes do +RSpec.describe HamlLint::Linter::NoPlainNodes do include_context 'linter' context 'reports when a tag has an inline plain node' do |