|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "./cop_test" |
| 4 | +require "minitest/autorun" |
| 5 | +require "rubocop/cop/github/accessibility/link_has_href" |
| 6 | + |
| 7 | +class LinkHasHref < CopTest |
| 8 | + def cop_class |
| 9 | + RuboCop::Cop::GitHub::Accessibility::LinkHasHref |
| 10 | + end |
| 11 | + |
| 12 | + def test_link_has_href_offense |
| 13 | + offenses = erb_investigate cop, <<-ERB, "app/views/products/index.html.erb" |
| 14 | + <%= link_to 'Go to GitHub' %> |
| 15 | + ERB |
| 16 | + |
| 17 | + assert_equal 1, offenses.count |
| 18 | + assert_equal "Links should go somewhere, you probably want to use a `<button>` instead.", offenses[0].message |
| 19 | + |
| 20 | + offenses = erb_investigate cop, <<-ERB, "app/views/products/index.html.erb" |
| 21 | + <%= link_to 'Go to GitHub', '#' %> |
| 22 | + ERB |
| 23 | + |
| 24 | + assert_equal 1, offenses.count |
| 25 | + assert_equal "Links should go somewhere, you probably want to use a `<button>` instead.", offenses[0].message |
| 26 | + end |
| 27 | + |
| 28 | + def test_link_has_href_no_offense |
| 29 | + offenses = erb_investigate cop, <<-ERB, "app/views/products/index.html.erb" |
| 30 | + <%= link_to 'Go to GitHub', 'https://github.com/' %> |
| 31 | + ERB |
| 32 | + |
| 33 | + assert_equal 0, offenses.count |
| 34 | + end |
| 35 | +end |
0 commit comments