rspec-let-do-blocks

A Ruby RSpec formatting rule for multi-line let declarations, method calls, hashes, and blocks.

In plain words
What is it for?
It is for formatting RSpec let and let! declarations, multi-line calls, and JSON built from Ruby hashes.
Why use it?
It keeps complex test setup readable and uses consistent block and argument formatting.

Cursor rule

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/panozzaj/cursor-rules/rspec-let-do-blocks
Clone the repo
git clone --depth 1 https://github.com/panozzaj/cursor-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 658 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.00658
Opus 5 $0.00000 $0.00329
Sonnet 5 $0.00000 $0.00132
Haiku 4.5 $0.00000 $0.00066

Measured 2d ago against content hash 77713793bc05, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rspec-let-do-blocks 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 2d ago.

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.

rules/rspec-let-do-blocks.mdc · 69 lines

What it actually says

RSpec: Use do...end for Multi-line let Declarations & Format Method Calls

  1. Use do...end for Multi-line let: When a let or let! declaration's body spans multiple lines (e.g., defining a multi-line hash/array, or a method call with multiple arguments/lines), use the do ... end block syntax instead of curly braces { ... }.

  2. Use do...end for Complex Single Lines: Even if a let body is technically a single expression, use do...end if the expression is long or complex (e.g., involves significant method chaining, complex interpolation, or nested structures) to improve readability.

  3. Format Multi-line Method Calls: When the body of a let is a method call with keyword arguments or multiple arguments that make the line long, format the call across multiple lines with one argument per line, indented.

  4. Prefer Ruby Hashes for JSON: When creating JSON strings within let blocks, prefer constructing them from Ruby hashes using .to_json for better readability and maintainability.

Good:

# Multi-line array
let(:ignore_patterns) do
  [
    { method: :get, path: %r{/ignored/.*} },
    { method: :post, path: %r{/other/} },
    { path: %r{/any_method/.*} }
  ]
end

# Multi-line method call with keyword args
let(:response) do
  Faraday::Response.new(
    status: 200,
    body: { data: :test }.to_json, # Construct JSON from hash
    response_headers: {
      'Content-Type' => 'application/json'
    }
  )
end

# Multi-line hash definition
let(:ignored_env) do
  { method: :get, url: URI('http://example.com/ignored/path'), body: nil }
end

# Complex single line expression
let(:ignored_with_params_cache_key) do
  "faraday_cache:#{Digest::MD5.hexdigest("#{ignored_env_with_params[:method]}:#{ignored_env_with_params[:url]}:#{ignored_env_with_params[:body]}")}"
end

Bad:

# Using { ... } for multi-line blocks
let(:ignore_patterns) { [
    { method: :get, path: %r{/ignored/.*} },
    { method: :post, path: %r{/other/} },
    { path: %r{/any_method/.*} }
  ] }

# Complex expression squeezed onto one line with { ... }
let(:ignored_with_params_cache_key) { "faraday_cache:#{Digest::MD5.hexdigest("#{ignored_env_with_params[:method]}:#{ignored_env_with_params[:url]}:#{ignored_env_with_params[:body]}")}" }

For simple single-line declarations, curly braces are acceptable.

let(:simple_value) { 123 }
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. 2d ago First seen · 69 lines · 658 tokens per session scan A 77713793bc05

Subscribe to this mod's changes

rspec-let-do-blocks is a cursor rule published in the GitHub repository panozzaj/cursor-rules (3 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 658 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-31.