Skip to content

Commit

Permalink
Fix html5_validator option and change html5_validator_service_url
Browse files Browse the repository at this point in the history
  • Loading branch information
spk committed Jul 3, 2020
1 parent d8fe05b commit ac1a71b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/validate_website/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def not_found_error(location)
# @param [Nokogiri::HTML::Document] original_doc
# @param [String] The raw HTTP response body of the page
# @param [String] url
# @param [Regexp] Errors to ignore
# @param [Hash] Validator options
#
def validate(doc, body, url, ignore = nil)
validator = Validator.new(doc, body, ignore: ignore)
def validate(doc, body, url, options)
validator = Validator.new(doc, body, options)
if validator.valid?
print color(:success, '.', options[:color]) # rspec style
else
Expand Down
3 changes: 2 additions & 1 deletion lib/validate_website/crawl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def on_every_html_page(crawler)
end

if validate?(page)
validate(page.doc, page.body, page.url, options[:ignore])
validate(page.doc, page.body, page.url,
options.slice(:ignore, :html5_validator))
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/validate_website/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def check_static_file(file)

def check_page(file, page)
if page.html? && options[:markup]
validate(page.doc, page.body, file, options[:ignore])
validate(page.doc, page.body, file,
options.slice(:ignore, :html5_validator))
end
check_static_not_found(page.links) if options[:not_found]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/validate_website/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ValidateWebsite
class Validator
extend ValidatorClassMethods

@html5_validator_service_url = 'https://checker.html5.org/'
@html5_validator_service_url = 'https://validator.nu/'
XHTML_SCHEMA_PATH = File.expand_path('../../data/schemas', __dir__)
@mutex = Mutex.new

Expand Down
16 changes: 16 additions & 0 deletions test/crawler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ def validator
@validate_website.history_count.must_equal 98
end

it 'can change validator' do
name = 'html5-fail'
file = File.join('test', 'data', "#{name}.html")
page = FakePage.new(name,
body: File.open(file).read,
content_type: 'text/html')
validator_res = File.join('test', 'data', 'validator.nu-failure.json')
stub_request(:any, /#{validator.html5_validator_service_url}/)
.to_return(body: File.open(validator_res).read)
@validate_website.site = page.url
_out, _err = capture_io do
@validate_website.crawl(html5_validator: :nu, ignore: /Warning/)
end
@validate_website.errors_count.must_equal 1
end

it 'crawl when URLs are not ascii only' do
name = 'cozy-community'
file = File.join('test', 'data', "#{name}.html")
Expand Down
18 changes: 18 additions & 0 deletions test/static_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
end
end

it 'can change validator' do
validator_res = File.join('test', 'data', 'validator.nu-failure.json')
stub_request(:any,
/#{ValidateWebsite::Validator.html5_validator_service_url}/)
.to_return(body: File.open(validator_res).read)
pattern = File.join(File.dirname(__FILE__), 'data',
'html5-fail.html')
Dir.chdir('test/data') do
_out, _err = capture_io do
@validate_website.crawl(pattern: pattern,
site: 'http://w3.org/',
ignore: /Warning/,
html5_validator: :nu)
end
@validate_website.errors_count.must_equal 1
end
end

it 'ignore' do
pattern = File.join(File.dirname(__FILE__), 'data',
'w3.org-xhtml1-strict-errors.html')
Expand Down

0 comments on commit ac1a71b

Please sign in to comment.