gjtorikian / html-proofer

Test your rendered HTML files to make sure they're accurate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom `Checker` class is not executed

asbjornu opened this issue · comments

I have the following custom Checker class that for some reason is not loaded or executed after upgrading to v4 of HTMLProofer:

module Html
  module Proofer
    module Unrendered
      class Error < StandardError; end

      class Checker < ::HTMLProofer::Check
        def run
          puts "Running unrendered link checker!"

          return unless @options[:check_unrendered_link]

          @html.xpath("//*[text()[contains(.,'][')]]").each do |node|
            line = node.line
            content = node.to_s
            add_issue("Contains unrendered link ][! #{content}", line: line)
          end
        end
      end
    end
  end
end

I'm currently struggling with getting the specs successful and I thought a simple require "html-proofer-unrendered-markdown" inside the spec was all that was required in order for the class to be loaded, found and executed by HTMLProofer. The way I'm executing HTMLProofer in the specs is fairly straight forward:

path = File.join(__dir__, "fixtures", file)
options = { :check_unrendered_link => check_unrendered_link }
proofer = HTMLProofer.check_file(path, options)
proofer.run

Shouldn't this work? What am I missing here?

It doesn't look like you've correctly added the check to the test.

Per the docs you should be doing something like:

HTMLProofer.check_file path, {checks: ['Checker']})

There are a number of issues with your check, not the least of which is the inheritance. Try simply:

      class Checker < ::HTMLProofer::Check

If you prefer an example, here is the test for this feature: https://github.com/gjtorikian/html-proofer/blob/4c0263ec9ab435e4a1301513d709148d1066b2ae/spec/html-proofer/check_spec.rb