-
-
Save mraaroncruz/0e7c6799e23018d4f56cff81b967da34 to your computer and use it in GitHub Desktop.
Rake task to crawl you rails app for broken links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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