testing-language

Testing rules for handling languages and locales consistently in a Ruby on Rails test suite. They set English as the test language while allowing the application to support English and German.

In plain words
What is it for?
Use them to configure Rails tests, set the default and active locale, detect locales in application requests, and create localized test data with FactoryBot.
Why use it?
Tests can become unreliable when the active language changes between examples or differs between the test and application settings. These rules make locale setup and cleanup explicit.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/wintermeyer/cursor-rails-rules/testing-language
Clone the repo
git clone --depth 1 https://github.com/wintermeyer/cursor-rails-rules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,537 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01537
Opus 5 $0.00000 $0.00768
Sonnet 5 $0.00000 $0.00307
Haiku 4.5 $0.00000 $0.00154

Measured yesterday against content hash f7c921f54585, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

testing-language scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/testing-language.mdc · 251 lines

How it starts

The opening of the file, as written. The whole thing — 251 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Testing Language Standards

Standards for language handling in tests

Configuration

  1. Test Environment Setup
# test/test_helper.rb
module ActiveSupport
  class TestCase
    # Run tests in parallel
    parallelize(workers: :number_of_processors)

    # Include FactoryBot syntax methods
    include FactoryBot::Syntax::Methods

    # Force English locale for all tests
    setup do
      I18n.locale = :en
      I18n.default_locale = :en
      Rails.application.config.i18n.default_locale = :en
      Rails.application.config.i18n.locale = :en
      Rails.application.config.i18n.available_locales = [:en, :de]
    end

    teardown do
      I18n.locale = :en
    end
  end
end
  1. Application Controller
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  before_action :set_locale

  private

  def set_locale
    return if Rails.env.test? # Skip locale detection in test environment
    I18n.locale = extract_locale_from_accept_language_header || I18n.default_locale
  end
end

Factory Setup

  1. User Factory
# test/factories/users.rb
FactoryBot.define do
  factory :user do
    first_name { Faker::Name.first_name }
    last_name { Faker::Name.last_name }
    email { Faker::Internet.email }
    password { "password123" }
    lang { "en" }  # Default to English

    trait :german do
      lang { "de" }
      after(:build) do |user|
        # Use German Faker data for consistency
        Faker::Config.locale = "de"
        user.first_name = Faker::Name.first_name
        user.last_name = Faker::Name.last_name
        Faker::Config.locale = "en"  # Reset to English
      end
    end
  end
end

Testing Guidelines

  1. Translation Testing
# test/models/article_test.rb
class ArticleTest < ActiveSupport::TestCase
  test "article title is translated" do
    article = create(:article, title_en: "English Title", title_de: "Deutscher Titel")

    # Always test English first
    assert_equal "English Title", article.title

    # Test other languages explicitly
    I18n.with_locale(:de) do
      assert_equal "Deutscher Titel", article.title
    end

    # Reset to English
    assert_equal "English Title", article.title
  end
end

Read the full file on GitHub · 251 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 251 lines · 0 tokens per session scan A f7c921f54585

Subscribe to this mod's changes

testing-language is a cursor rule published in the GitHub repository wintermeyer/cursor-rails-rules (37 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,537 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.