Skip to content

Instantly share code, notes, and snippets.

@taglia
Forked from tansengming/crawl.rake
Created June 4, 2016 08:15
Show Gist options
  • Save taglia/0434ad81b28e79095a85b6129b019eab to your computer and use it in GitHub Desktop.
Save taglia/0434ad81b28e79095a85b6129b019eab to your computer and use it in GitHub Desktop.
Rake task to crawl you rails app for broken links
# Use this to look for broken links in your app.
# crawls the development server http://localhost:3000
# Suggestion: Also check to make sure that intentional 404s
# are handled gracefully by app.
task :crawl => :environment do
require 'anemone'
root = 'http://localhost:3000'
options = {:discard_page_bodies => true, :verbose => true}
Anemone.crawl(root, options) do |anemone|
anemone.on_every_page do |page|
raise '404 Not Found!:' + page.url.path.to_s if page.not_found?
end
anemone.after_crawl do |pages|
raise 'Error! Only found 1 page. Is the server down?' if pages.size == 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment