Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

converting-mocks-to-automockable

БесплатноБез исполняемых скриптовНе проверен

Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock. Use this skill whenever the user says "convert this mock", "migrate mock to…

bitwardenот bitwarden★ 748 звёзд на GitHub

Об этом скилле

Converting Bespoke Mocks to AutoMockable

This skill guides you through assessing whether a hand-written mock can be replaced with a Sourcery-generated one, performing the migration, and updating affected tests.

Step 1: Assess the Candidate

Read the bespoke mock file and locate its corresponding protocol. Scan for these disqualifying patterns — if any are present, keep the mock as bespoke:

Pattern Why it can't be auto-generated
Mock executes passed-in closure parameters (e.g., runs a () async throws -> T argument) Closures passed as arguments are non-escaping; Sourcery stubs these with fatalError
Mock accumulates all calls into a combined array (e.g., var alerts: [Alert]) AutoMockable stores last call's args, not a merged collection across overloads
Methods with overloaded signatures that share state Each overload gets a separate mock; shared logic must be bespoke

If none apply, proceed — AutoMockable handles value returns, throws, async results, and call tracking out of the box.

Step 2: Annotate the Protocol

Add // sourcery: AutoMockable as a trailing comment on the protocol's opening line. Do not put it on the line above.

// Before
protocol FeatureService: AnyObject {

// After
protocol FeatureService: AnyObject { // sourcery: AutoMockable

If the protocol already has a comment on that line (e.g., // sourcery: AutoMockable is already there), skip this step.

Step 3: Map the API — Bespoke to Generated

The generated mock's property names follow deterministic patterns. Use this table to translate test code:

Bespoke pattern Generated equivalent
var fooResult: Result<T, Error> = .success(x) var fooReturnValue: T! = x (for the value)
var fooResult: Result<T, Error> = .failure(e) var fooThrowableError: (any Error)? = e
var fooCalled: Bool = false var fooCalled: Bool { fooCallsCount > 0 } — same name, same semantics, no change needed in tests
var fooCalledCount: Int = 0 var fooCallsCount = 0 — note the naming difference (Calls not Called)
fooBarCalled = false (mid-test reset between assertions) fooBarCallsCount = 0 — fooCalled is computed, so it can't be assigned; reset the underlying count instead
var fooHandler: (() -> Void)? (side-effect hook, no args) var fooClosure: ((ArgTypes) async throws -> ReturnType)? — generated closure takes the method's arguments; use _, _ if the handler doesn't need them
var fooParam: T? (captures a single named arg, e.g. foo(name: String)) var fooReceivedName: (String)? — uses the parameter label, not ReceivedArguments
var fooParam1: T1? + var fooParam2: T2? (captures multiple args) var fooReceivedArguments: (param1: T1, param2: T2)? — collapses all args into a labeled tuple
var fooValue: T = default (stored property returned by a method named getBar) var getBarReturnValue: T! — derives from the method name, not the stored property name
Custom closure to inject behavior var fooClosure: ((ArgTypes) -> ReturnType)?

Stored-property return values

Some bespoke mocks expose a plain stored property that a method simpl

Полный SKILL.md на GitHub

Установить converting-mocks-to-automockable в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл converting-mocks-to-automockable?

Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock. Use this skill whenever the user says "convert this mock", "migrate mock to AutoMockable", "replace bespoke mock", "use Sourcery for this mock", or mentions wanting to convert a Mock*.swift file to use `// sourcery: AutoMockable`. Also use this skill proactively when you notice a new protocol being created without the annotation, or when an existing bespoke mock is being modified and AutoMockable would be sufficient.

Как установить скилл converting-mocks-to-automockable?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл converting-mocks-to-automockable запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить converting-mocks-to-automockable с