Module: DevDoc::Test::PseudoI18nCrawler

Defined in:
lib/dev_doc/test/pseudo_i18n_crawler.rb

Overview

Pseudo-localization hardcoded-text crawler.

Reuses the glib-web JSON-UI crawler (per-role login + fixtures + full reachability) but renders every page under the en-PSEUDO locale and reports any localizable text prop that comes back WITHOUT the ⟦ ⟧ marker — i.e. user-facing text that bypassed Rails t() and is therefore a hardcoded-string candidate, no matter which view/helper/concern/module/ service emitted it. See dev_doc/i18n/pseudo_locale.rb.

Unlike the golden-file JSON-UI crawler this does NOT assert the page log (the accented pseudo output would never match committed baselines); it drives the router directly and only collects unwrapped text.


Per-project integration

Include this module in a single integration test and supply the project's own login credentials as test cases. The host class must also include Glib::TestHelpers (for HOST / login / logout) and load fixtures. The pseudo backend must be installed — see dev_doc/i18n/pseudo_locale.rb.

# test/integration/pseudo_i18n_crawler_test.rb
require 'test_helper'
require 'dev_doc/test/pseudo_i18n_crawler'

class PseudoI18nCrawlerTest < ActionDispatch::IntegrationTest
include Glib::TestHelpers
include DevDoc::Test::PseudoI18nCrawler

self.fixture_paths = ['test/fixtures']
fixtures :all

test 'crawl superadmin' do
  crawl_pseudo(email: 'super@admin.com', password: 'password', device: 'web', version: nil)
end
end

Run with the pseudo backend enabled:

PSEUDO_I18N=1 bin/rails test test/integration/pseudo_i18n_crawler_test.rb

Findings are printed and written to test/integration/pseudo_i18n_crawler_test_results/.txt

Defined Under Namespace

Modules: ClassMethods, Scanner

Constant Summary collapse

MARKER =
''.freeze
TEXT_KEYS =

Mirrors the cop's DEFAULT_LOCALIZABLE_KEYS — keep in sync with lib/rubocop/cop/dev_doc/i18n/localizable_props.rb. The crawler can only flag hardcoded text on keys it walks, so any key the cop treats as localizable (message/description on dialogs & banners, uploadText on fields_upload, on/left/rightText on switch & toggles) must be listed.

%w[
  title
  subtitle
  subsubtitle
  label
  placeholder
  text
  message
  description
  uploadText
  leftText
  rightText
  onLabel
].to_set

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.host_classObject

Returns the value of attribute host_class.



75
76
77
# File 'lib/dev_doc/test/pseudo_i18n_crawler.rb', line 75

def host_class
  @host_class
end

Class Method Details

.included(base) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dev_doc/test/pseudo_i18n_crawler.rb', line 93

def self.included(base)
  base.extend(ClassMethods)
  PseudoI18nCrawler.host_class = base

  # Prepend the Scanner onto the crawler HTTP client exactly once, no
  # matter how many test classes include the module.
  unless Glib::JsonCrawler::Http.ancestors.include?(Scanner)
    Glib::JsonCrawler::Http.prepend(Scanner)
  end

  base.setup do
    skip 'Set PSEUDO_I18N=1 to run the pseudo-localization scan.' unless ENV['PSEUDO_I18N'] == '1'
    skip 'en-PSEUDO locale not loaded — is config/initializers/pseudo_locale.rb active?' unless ::I18n.available_locales.include?(:'en-PSEUDO')

    self.class.hits = {}
    @previous_default_locale = ::I18n.default_locale
    # The app's set_locale falls back to I18n.default_locale when no
    # `_lang` param is present (crawler URLs carry none), so this renders
    # every page in pseudo without touching the crawler's URLs.
    ::I18n.default_locale = :'en-PSEUDO'
  end

  base.teardown do
    ::I18n.default_locale = @previous_default_locale if @previous_default_locale
  end
end