Friday, April 9, 2010

Rails - Tarantula spider testing - finding broken I18n translations

Again with Tarantula - here a way to test all pages for missing translations while you are spidering.

class Relevance::Tarantula::MissingI18nTranslationHtmlHandler
  include Relevance::Tarantula

  def handle(result)
    begin
      response = result.response
      return unless response.html?
      if /translation missing/.match(response.body)
        error_result = result.dup
        error_result.success = false
        error_result.description = "Broken Translation"
        error_result
      end
    rescue 
    end
    return nil
  end
end

class TarantulaTest < ActionController::IntegrationTest
  fixtures :all
  require 'ruby-debug'
  def test_tarantula
    login_all_users
    t = tarantula_crawler(self)
    t.handlers << Relevance::Tarantula::MissingI18nTranslationHtmlHandler.new
    t.crawl "/"
  end
  def login_all_users
  end
end

No comments:

Post a Comment