Skip to content

Commit e8ea66f

Browse files
committed
Fix offenses in tests
1 parent eb9c210 commit e8ea66f

14 files changed

+50
-263
lines changed

test/linters/accessibility/avoid_both_disabled_and_aria_disabled_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "test_helper"
44

5-
class AvoidBothDisabledAndAriaDisabled < LinterTestCase
5+
class AvoidBothDisabledAndAriaDisabledTest < LinterTestCase
66
def linter_class
77
ERBLint::Linters::GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled
88
end

test/linters/accessibility/avoid_generic_link_text_test.rb

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "test_helper"
44

5-
class AvoidGenericLinkTextCounterTest < LinterTestCase
5+
class AvoidGenericLinkTextTest < LinterTestCase
66
def linter_class
77
ERBLint::Linters::GitHub::Accessibility::AvoidGenericLinkText
88
end
@@ -51,8 +51,7 @@ def test_warns_when_link_text_is_banned_text_with_punctuation_and_space
5151
@linter.run(processed_source)
5252

5353
refute_empty @linter.offenses
54-
# 3 offenses, 1 related to matching counter comment not present despite violations
55-
assert_equal 4, @linter.offenses.count
54+
assert_equal 3, @linter.offenses.count
5655
end
5756

5857
def test_does_not_warn_when_banned_text_is_part_of_more_text
@@ -143,50 +142,17 @@ def test_handles_files_with_various_links
143142
@linter.run(processed_source)
144143

145144
refute_empty @linter.offenses
146-
# 3 offenses, 1 related to matching counter comment not present despite violations
147-
assert_equal 4, @linter.offenses.count
145+
assert_equal 3, @linter.offenses.count
148146
end
149147

150-
def test_does_not_warns_if_element_has_correct_counter_comment
148+
def test_does_not_warns_if_element_has_correct_counter_comment_if_config_enabled
151149
@file = <<~ERB
152150
<%# erblint:counter GitHub::Accessibility::AvoidGenericLinkTextCounter 1 %>
153151
<a>Link</a>
154152
ERB
153+
@linter.config.counter_enabled = true
155154
@linter.run(processed_source)
156155

157156
assert_equal 0, @linter.offenses.count
158157
end
159-
160-
def test_autocorrects_when_ignores_are_not_correct
161-
@file = <<~ERB
162-
<p>
163-
<a href="github.com" aria-label='Click here to learn more'>Click here</a>
164-
<a href="github.com" aria-label='Some totally different text'>Click here</a>
165-
<a href="github.com" aria-labelledby='someElement'>Click here</a>
166-
</p>
167-
<p>
168-
<%= link_to "learn more", billing_path, "aria-label": "something" %>
169-
<%= link_to "learn more", billing_path, aria: { label: "something" } %>
170-
<%= link_to "learn more", billing_path, aria: { describedby: "element123" } %>
171-
<%= link_to "learn more", billing_path, "aria-describedby": "element123" %>
172-
</p>
173-
ERB
174-
refute_equal @file, corrected_content
175-
176-
expected_content = <<~ERB
177-
<%# erblint:counter GitHub::Accessibility::AvoidGenericLinkTextCounter 3 %>
178-
<p>
179-
<a href="github.com" aria-label='Click here to learn more'>Click here</a>
180-
<a href="github.com" aria-label='Some totally different text'>Click here</a>
181-
<a href="github.com" aria-labelledby='someElement'>Click here</a>
182-
</p>
183-
<p>
184-
<%= link_to "learn more", billing_path, "aria-label": "something" %>
185-
<%= link_to "learn more", billing_path, aria: { label: "something" } %>
186-
<%= link_to "learn more", billing_path, aria: { describedby: "element123" } %>
187-
<%= link_to "learn more", billing_path, "aria-describedby": "element123" %>
188-
</p>
189-
ERB
190-
assert_equal expected_content, corrected_content
191-
end
192158
end

test/linters/accessibility/disabled_attribute_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "test_helper"
44

5-
class DisabledAttribute < LinterTestCase
5+
class DisabledAttributeTest < LinterTestCase
66
def linter_class
77
ERBLint::Linters::GitHub::Accessibility::DisabledAttribute
88
end
@@ -23,7 +23,7 @@ def test_does_not_warn_if_valid_element_has_disabled_attribute
2323
assert_empty @linter.offenses
2424
end
2525

26-
def test_does_not_warn_if_link_has_href_attribute_and_has_correct_counter_comment
26+
def test_does_not_warns_if_element_has_correct_counter_comment_if_config_enabled
2727
@file = <<~ERB
2828
<%# erblint:counter GitHub::Accessibility::DisabledAttributeCounter 1 %>
2929
<a href='https://github.com/' disabled>Go to GitHub</a>

test/linters/accessibility/iframe_has_title_test.rb

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
require "test_helper"
44

5-
class IframeHasTitleCounterTest < LinterTestCase
5+
class IframeHasTitleTest < LinterTestCase
66
def linter_class
7-
ERBLint::Linters::GitHub::Accessibility::IframeHasTitleCounter
7+
ERBLint::Linters::GitHub::Accessibility::IframeHasTitle
88
end
99

1010
def test_warns_if_iframe_has_no_title
@@ -28,35 +28,13 @@ def test_does_not_warn_if_iframe_has_title_set_to_string
2828
assert_empty @linter.offenses
2929
end
3030

31-
def test_does_not_raise_when_ignore_comment_with_correct_count
31+
def test_does_not_raise_when_ignore_comment_with_correct_count_if_config_enabled
3232
@file = <<~ERB
3333
<%# erblint:counter GitHub::Accessibility::IframeHasTitleCounter 1 %>
3434
<iframe></iframe>
3535
ERB
36-
36+
@linter.config.counter_enabled = true
3737
@linter.run(processed_source)
3838
assert_empty @linter.offenses
3939
end
40-
41-
def test_does_not_autocorrect_when_ignores_are_correct
42-
@file = <<~ERB
43-
<%# erblint:counter GitHub::Accessibility::IframeHasTitleCounter 1 %>
44-
<iframe></iframe>
45-
ERB
46-
47-
assert_equal @file, corrected_content
48-
end
49-
50-
def test_does_autocorrect_when_ignores_are_not_correct
51-
@file = <<~ERB
52-
<iframe></iframe>
53-
ERB
54-
refute_equal @file, corrected_content
55-
56-
expected_content = <<~ERB
57-
<%# erblint:counter GitHub::Accessibility::IframeHasTitleCounter 1 %>
58-
<iframe></iframe>
59-
ERB
60-
assert_equal expected_content, corrected_content
61-
end
6240
end

test/linters/accessibility/image_has_alt_test.rb

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
require "test_helper"
44

5-
class ImageHasAltCounterTest < LinterTestCase
5+
class ImageHasAltTest < LinterTestCase
66
def linter_class
7-
ERBLint::Linters::GitHub::Accessibility::ImageHasAltCounter
7+
ERBLint::Linters::GitHub::Accessibility::ImageHasAlt
88
end
99

1010
def test_warns_if_image_has_no_alt_attribute
@@ -28,35 +28,13 @@ def test_does_not_warn_if_image_has_alt_attribute_set_to_string
2828
assert_empty @linter.offenses
2929
end
3030

31-
def test_does_not_raise_when_ignore_comment_with_correct_count
31+
def test_does_not_raise_when_ignore_comment_with_correct_count_if_config_enabled
3232
@file = <<~ERB
3333
<%# erblint:counter GitHub::Accessibility::ImageHasAltCounter 1 %>
3434
<img></img>
3535
ERB
36-
36+
@linter.config.counter_enabled = true
3737
@linter.run(processed_source)
3838
assert_empty @linter.offenses
3939
end
40-
41-
def test_does_not_autocorrect_when_ignores_are_correct
42-
@file = <<~ERB
43-
<%# erblint:counter GitHub::Accessibility::ImageHasAltCounter 1 %>
44-
<img></img>
45-
ERB
46-
47-
assert_equal @file, corrected_content
48-
end
49-
50-
def test_does_autocorrect_when_ignores_are_not_correct
51-
@file = <<~ERB
52-
<img></img>
53-
ERB
54-
refute_equal @file, corrected_content
55-
56-
expected_content = <<~ERB
57-
<%# erblint:counter GitHub::Accessibility::ImageHasAltCounter 1 %>
58-
<img></img>
59-
ERB
60-
assert_equal expected_content, corrected_content
61-
end
6240
end

test/linters/accessibility/landmark_has_label_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "test_helper"
44

5-
class LandmarkHasLabel < LinterTestCase
5+
class LandmarkHasLabelTest < LinterTestCase
66
def linter_class
77
ERBLint::Linters::GitHub::Accessibility::LandmarkHasLabel
88
end

test/linters/accessibility/link_has_href_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "test_helper"
44

5-
class LinkHasHref < LinterTestCase
5+
class LinkHasHrefTest < LinterTestCase
66
def linter_class
77
ERBLint::Linters::GitHub::Accessibility::LinkHasHref
88
end

test/linters/accessibility/nested_interactive_elements_test.rb

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
require "test_helper"
44

5-
class NestedInteractiveElementsCounter < LinterTestCase
5+
class NestedInteractiveElementsTest < LinterTestCase
66
def linter_class
7-
ERBLint::Linters::GitHub::Accessibility::NestedInteractiveElementsCounter
7+
ERBLint::Linters::GitHub::Accessibility::NestedInteractiveElements
88
end
99

1010
def test_warns_if_there_are_nested_interactive_elements
1111
@file = "<button><a href='https://github.com/'>Go to GitHub</a></button>"
1212
@linter.run(processed_source)
1313

14-
assert_equal(2, @linter.offenses.count)
14+
assert_equal(1, @linter.offenses.count)
1515
error_messages = @linter.offenses.map(&:message).sort
16-
assert_match(/If you must, add <%# erblint:counter GitHub::Accessibility::NestedInteractiveElementsCounter 1 %> to bypass this check./, error_messages.first)
1716
assert_match(/Nesting interactive elements produces invalid HTML, and ssistive technologies, such as screen readers, might ignore or respond unexpectedly to such nested controls./, error_messages.last)
1817
end
1918

@@ -24,36 +23,14 @@ def test_does_not_warn_if_there_are_not_nested_interactive_elements
2423
assert_empty @linter.offenses
2524
end
2625

27-
def test_does_not_warn_if_there_are_not_nested_interactive_elements_and_has_correct_counter_comment
26+
def test_does_not_warn_if_there_are_not_nested_interactive_elements_and_has_correct_counter_comment_with_config_enabled
2827
@file = <<~ERB
2928
<%# erblint:counter GitHub::Accessibility::NestedInteractiveElementsCounter 1 %>
3029
<button><a href='https://github.com/'>Go to GitHub</a></button>
3130
ERB
31+
@linter.config.counter_enabled = true
3232
@linter.run(processed_source)
3333

3434
assert_equal 0, @linter.offenses.count
3535
end
36-
37-
def test_does_not_autocorrect_when_ignores_are_correct
38-
@file = <<~ERB
39-
<%# erblint:counter GitHub::Accessibility::NestedInteractiveElementsCounter 1 %>
40-
<button><a href='https://github.com/'>Go to GitHub</a></button>
41-
ERB
42-
43-
assert_equal @file, corrected_content
44-
end
45-
46-
def test_does_autocorrect_when_ignores_are_not_correct
47-
@file = <<~ERB
48-
<%# erblint:counter GitHub::Accessibility::NestedInteractiveElementsCounter 3 %>
49-
<button><a href='https://github.com/'>Go to GitHub</a></button>
50-
ERB
51-
refute_equal @file, corrected_content
52-
53-
expected_content = <<~ERB
54-
<%# erblint:counter GitHub::Accessibility::NestedInteractiveElementsCounter 1 %>
55-
<button><a href='https://github.com/'>Go to GitHub</a></button>
56-
ERB
57-
assert_equal expected_content, corrected_content
58-
end
5936
end

test/linters/accessibility/no_aria_hidden_on_focusable_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
require "test_helper"
44

5-
class NoAriaHiddenOnFocusableCounterTest < LinterTestCase
5+
class NoAriaHiddenOnFocusableTest < LinterTestCase
66
def linter_class
7-
ERBLint::Linters::GitHub::Accessibility::NoAriaHiddenOnFocusableCounter
7+
ERBLint::Linters::GitHub::Accessibility::NoAriaHiddenOnFocusable
88
end
99

1010
def test_does_not_warn_if_link_does_not_have_aria_hidden

test/linters/accessibility/no_aria_label_misuse_test.rb

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
require "test_helper"
44

5-
class NoAriaLabelMisuseCounterTest < LinterTestCase
5+
class NoAriaLabelMisuseTest < LinterTestCase
66
def linter_class
7-
ERBLint::Linters::GitHub::Accessibility::NoAriaLabelMisuseCounter
7+
ERBLint::Linters::GitHub::Accessibility::NoAriaLabelMisuse
88
end
99

1010
def example_invalid_case
@@ -29,7 +29,7 @@ def test_warns_if_banned_elements_have_aria_label
2929
HTML
3030

3131
@linter.run(processed_source)
32-
assert_equal @linter.offenses.length, 12
32+
assert_equal @linter.offenses.length, 11
3333
end
3434

3535
def test_warns_if_generic_elements_have_aria_label_and_no_role
@@ -39,7 +39,7 @@ def test_warns_if_generic_elements_have_aria_label_and_no_role
3939
HTML
4040

4141
@linter.run(processed_source)
42-
assert_equal 3, @linter.offenses.length
42+
assert_equal 2, @linter.offenses.length
4343
end
4444

4545
def test_warns_if_generic_elements_have_aria_label_and_prohibited_role
@@ -61,7 +61,7 @@ def test_warns_if_generic_elements_have_aria_label_and_prohibited_role
6161
HTML
6262

6363
@linter.run(processed_source)
64-
assert_equal 15, @linter.offenses.length
64+
assert_equal 14, @linter.offenses.length
6565
end
6666

6767
def test_does_not_warn_if_generic_elements_have_aria_label_and_allowed_role
@@ -75,37 +75,14 @@ def test_does_not_warn_if_generic_elements_have_aria_label_and_allowed_role
7575
assert_empty @linter.offenses
7676
end
7777

78-
def test_does_not_raise_when_ignore_comment_with_correct_count
78+
def test_does_not_raise_when_ignore_comment_with_correct_count_and_config_enabled
7979
@file = <<~ERB
8080
<%# erblint:counter GitHub::Accessibility::NoAriaLabelMisuseCounter 2 %>
8181
<span aria-label="This is a bad idea">Some text</span>
8282
<span aria-label="This is still a bad idea">More text</span>
8383
ERB
84-
84+
@linter.config.counter_enabled = true
8585
@linter.run(processed_source)
8686
assert_empty @linter.offenses
8787
end
88-
89-
def test_does_not_autocorrect_when_ignores_are_correct
90-
@file = <<~ERB
91-
<%# erblint:counter GitHub::Accessibility::NoAriaLabelMisuseCounter 1 %>
92-
<span aria-label="This is a bad idea">Some text</span>
93-
ERB
94-
95-
assert_equal @file, corrected_content
96-
end
97-
98-
def test_does_autocorrect_when_ignores_are_not_correct
99-
@file = <<~ERB
100-
<%# erblint:counter GitHub::Accessibility::NoAriaLabelMisuseCounter 3 %>
101-
<span aria-label="This is a bad idea">Some text</span>
102-
ERB
103-
refute_equal @file, corrected_content
104-
105-
expected_content = <<~ERB
106-
<%# erblint:counter GitHub::Accessibility::NoAriaLabelMisuseCounter 1 %>
107-
<span aria-label="This is a bad idea">Some text</span>
108-
ERB
109-
assert_equal expected_content, corrected_content
110-
end
11188
end

0 commit comments

Comments
 (0)