Skip to content

Instantly share code, notes, and snippets.

@mraaroncruz
Forked from tansengming/crawl.rake
Created December 9, 2017 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mraaroncruz/0e7c6799e23018d4f56cff81b967da34 to your computer and use it in GitHub Desktop.
Save mraaroncruz/0e7c6799e23018d4f56cff81b967da34 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