debian-mirror-gitlab/spec/haml_lint/linter/documentation_links_spec.rb

99 lines
3 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# 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'
2021-01-03 14:25:43 +05:30
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')" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.not_to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
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'" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.not_to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'when link_to points to the existing file path without .md extension' do
let(:haml) { "= link_to 'Description', #{link_pattern}('README')" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.not_to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'when anchor is not correct' do
let(:haml) { "= link_to 'Description', #{link_pattern}('README.md', anchor: 'wrong')" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.to report_lint }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
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'" }
2020-07-28 23:09:34 +05:30
it { is_expected.to report_lint }
end
2021-01-03 14:25:43 +05:30
context 'when link with wrong file path is assigned to a variable' do
let(:haml) { "- my_link = link_to 'Description', #{link_pattern}('wrong.md')" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'when it is a broken code' do
let(:haml) { "= I am broken! ]]]]" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.not_to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'when anchor belongs to a different element' do
let(:haml) { "= link_to 'Description', #{link_pattern}('README.md'), target: (anchor: 'blank')" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.not_to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context "when a simple #{link_pattern}" do
let(:haml) { "- url = #{link_pattern}('wrong.md')" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'when link is not a string' do
let(:haml) { "- url = #{link_pattern}(help_url)" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.not_to report_lint }
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'when link is a part of the tag' do
let(:haml) { ".data-form{ data: { url: #{link_pattern}('wrong.md') } }" }
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
it { is_expected.to report_lint }
end
2021-06-08 01:23:25 +05:30
context 'when the second link is invalid' do
let(:haml) { ".data-form{ data: { url: #{link_pattern}('README.md'), wrong_url: #{link_pattern}('wrong.md') } }" }
it { is_expected.to report_lint }
end
2020-07-28 23:09:34 +05:30
end
2021-01-03 14:25:43 +05:30
context 'help_page_path' do
it_behaves_like 'link validation rules', 'help_page_path'
end
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
context 'help_page_url' do
it_behaves_like 'link validation rules', 'help_page_url'
2020-07-28 23:09:34 +05:30
end
end