mocking-dependencies-in-tests

mocking-dependencies-in-tests is a cursor rule for Cursor from PaulJPhilp/EffectPatterns. It costs 707 tokens per session, scanned A, original, MIT.

A testing pattern that replaces a real service, such as an email sender, with a test version. This keeps the test focused on the code being checked.

In plain words
What is it for?
Use it to provide mock services for unit tests and isolate one component from its dependencies.
Why use it?
It prevents tests from sending real messages or depending on external systems, making them safer and more predictable.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it to provide mock services for unit tests and isolate one component from its dependencies.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/pauljphilp/effectpatterns/mocking-dependencies-in-tests
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.

Clone the repo
git clone --depth 1 https://github.com/PaulJPhilp/EffectPatterns

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for mocking-dependencies-in-tests

README.md
[![agentmods](https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/mocking-dependencies-in-tests.svg)](https://agentmods.dev/rules/pauljphilp/effectpatterns/mocking-dependencies-in-tests)
Your own site
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/mocking-dependencies-in-tests"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/mocking-dependencies-in-tests.svg" alt="Measured on agentmods" height="20"></a>
Per session 707 This file is loaded in full into every session.
When invoked 707 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00707 $0.00707
Opus 5 $0.00353 $0.00353
Sonnet 5 $0.00141 $0.00141
Haiku 4.5 $0.00071 $0.00071

Measured 4d ago against content hash 24e7080d569a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

mocking-dependencies-in-tests 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 4d 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.

content/published/rules/cursor/mocking-dependencies-in-tests.mdc · 79 lines

How it starts

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

description: Provide mock service implementations via a test-specific Layer to isolate the unit under test. globs: "**/*.ts" alwaysApply: true

Mocking Dependencies in Tests

Rule: Provide mock service implementations via a test-specific Layer to isolate the unit under test.

Example

We want to test a Notifier service that uses an EmailClient to send emails. In our test, we provide a mock EmailClient that doesn't actually send emails but just returns a success value.

import { Effect, Layer } from "effect";

// --- The Services ---
interface EmailClientService {
  send: (address: string, body: string) => Effect.Effect<void>;
}

class EmailClient extends Effect.Service<EmailClientService>()("EmailClient", {
  sync: () => ({
    send: (address: string, body: string) =>
      Effect.sync(() => Effect.log(`Sending email to ${address}: ${body}`)),
  }),
}) {}

interface NotifierService {
  notifyUser: (userId: number, message: string) => Effect.Effect<void>;
}

class Notifier extends Effect.Service<NotifierService>()("Notifier", {
  effect: Effect.gen(function* () {
    const emailClient = yield* EmailClient;
    return {
      notifyUser: (userId: number, message: string) =>
        emailClient.send(`user-${userId}@example.com`, message),
    };
  }),
  dependencies: [EmailClient.Default],
}) {}

// Create a program that uses the Notifier service
const program = Effect.gen(function* () {
  yield* Effect.log("Using default EmailClient implementation...");
  const notifier = yield* Notifier;
  yield* notifier.notifyUser(123, "Your invoice is ready.");

  // Create mock EmailClient that logs differently
  yield* Effect.log("\nUsing mock EmailClient implementation...");
  const mockEmailClient = Layer.succeed(EmailClient, {
    send: (address: string, body: string) =>
      // Directly return the Effect.log without nesting it in Effect.sync
      Effect.log(`MOCK: Would send to ${address} with body: ${body}`),
  } as EmailClientService);

  // Run the same notification with mock client
  yield* Effect.gen(function* () {
    const notifier = yield* Notifier;
    yield* notifier.notifyUser(123, "Your invoice is ready.");
  }).pipe(Effect.provide(mockEmailClient));
});

// Run the program
Effect.runPromise(Effect.provide(program, Notifier.Default));

Read the full file on GitHub · 79 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. 4d ago First seen · 79 lines · 707 tokens per session scan A 24e7080d569a

Subscribe to this mod's changes

mocking-dependencies-in-tests is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (796 stars, last pushed 2mo ago), licensed MIT. It adds 707 tokens to every session, about $0.0035 per session on Opus 5. 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-09-03.