Welcome to mirror list, hosted at ThFree Co, Russian Federation.

no_plain_nodes_spec.rb « linter « haml_lint « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08f7e6131ccdec29681c4eca4b8a252a202fb9f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true

require 'spec_helper'
require 'haml_lint'
require 'haml_lint/spec'
require Rails.root.join('haml_lint/linter/no_plain_nodes')

RSpec.describe HamlLint::Linter::NoPlainNodes do
  include_context 'linter'

  context 'reports when a tag has an inline plain node' do
    let(:haml) { '%tag Hello Tanuki' }
    let(:message) { "`Hello Tanuki` is a plain node. Please use an i18n method like `= _('Hello Tanuki')`" }

    it { is_expected.to report_lint message: message }
  end

  context 'reports when a tag has multiline plain nodes' do
    let(:haml) { <<-HAML }
      %tag
        Hello
        Tanuki
    HAML

    it { is_expected.to report_lint count: 1 }
  end

  context 'reports when a tag has an inline plain node with interpolation' do
    let(:haml) { '%tag Hello #{"Tanuki"}!' } # rubocop:disable Lint/InterpolationCheck

    it { is_expected.to report_lint }
  end

  context 'does not report when a tag has an inline script' do
    let(:haml) { '%tag= "Hello Tanuki"' }

    it { is_expected.not_to report_lint }
  end

  context 'does not report when a tag is empty' do
    let(:haml) { '%tag' }

    it { is_expected.not_to report_lint }
  end

  context 'reports multiple when a tag has multiline plain nodes split by non-text nodes' do
    let(:haml) { <<-HAML }
      %tag
        Hello
        .split-node There
        Tanuki
    HAML

    it { is_expected.to report_lint count: 3 }
  end

  context 'does not report when a html entity' do
    let(:haml) { '%tag &nbsp;' }

    it { is_expected.not_to report_lint }
  end

  context 'does report when something that looks like a html entity' do
    let(:haml) { '%tag &some text;' }

    it { is_expected.to report_lint }
  end

  context 'does not report multiline when one or more html entities' do
    %w(&nbsp;&gt; &#x000A9; &#187;).each do |elem|
      let(:haml) { <<-HAML }
        %tag
          #{elem}
      HAML

      it elem do
        is_expected.not_to report_lint
      end
    end
  end

  context 'does report multiline when one or more html entities amidst plain text' do
    %w(&nbsp;Test Test&gt; &#x000A9;Hello &nbsp;Hello&#187;).each do |elem|
      let(:haml) { <<-HAML }
        %tag
          #{elem}
      HAML

      it elem do
        is_expected.to report_lint
      end
    end
  end
end