Official agent skill

Converting Mocks To Automockable

by bitwarden in bitwarden/ios

Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock.

OfficialGPL-3.0Auto-check passedMobile

Install Converting Mocks To Automockable

skills CLI
$ npx skills add bitwarden/ios --skill converting-mocks-to-automockable -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install bitwarden/ios converting-mocks-to-automockable --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/bitwarden/ios.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/converting-mocks-to-automockable .claude/skills/converting-mocks-to-automockable && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
converting-mocks-to-automockable
GitHub stars
696
Token cost
~3.5k tokens
SKILL.md length
1,156 words
Files
1
Skills in repo
11
Repo updated
First seen
Licence
GPL-3.0

At a glance

Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock.

  • Works in 7 steps: Assess the Candidate → Annotate the Protocol → Map the API — Bespoke to Generated → …
  • The user says convert this mock
  • SKILL.md covers Step 1: Assess the Candidate, Step 2: Annotate the Protocol, Step 3: Map the API — Bespoke… and Step 4: Delete the Bespoke Mock, plus 3 more sections
  • Calls xcodebuild

What it does

Converting Mocks To Automockable is an agent skill from bitwarden/ios, published by the product's own GitHub organization. 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.

Its SKILL.md is about 3.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering iOS development. The repository describes itself as: Bitwarden mobile apps (Password Manager and Authenticator) for iOS. The licence is GPL-3.0.

When your agent uses it

  • The user says convert this mock
  • Migrate mock to AutoMockable
  • Replace bespoke mock
  • Use Sourcery for this mock

Example prompts

  • “convert this mock”
  • “migrate mock to AutoMockable”
  • “replace bespoke mock”
  • “/converting-mocks-to-automockable”

Workflow steps

7 steps, taken from the step headings in SKILL.md.

  1. Assess the Candidate
  2. Annotate the Protocol
  3. Map the API — Bespoke to Generated
  4. Delete the Bespoke Mock
  5. Regenerate Mocks
  6. Update Tests
  7. Verify

What it can do on your machine

Read from SKILL.md and the folder at commit 08f8c1d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • xcodebuild

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Converting Mocks To Automockable loads about 3.5k tokens when it runs. Until then it costs about 133 tokens; SKILL.md has 1,156 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~133
When it runs · the whole SKILL.md, loaded when a task matches
~3.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from bitwarden/ios at commit 08f8c1d, republished under its GPL-3.0 licence (© bitwarden). 1,156 words, ~3,532 tokens.

Download SKILL.mdSave it as .claude/skills/converting-mocks-to-automockable/SKILL.md (or your agent's skills folder).
name
converting-mocks-to-automockable
description
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 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:

PatternWhy 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 stateEach 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.

swift
// 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 patternGenerated 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 = falsevar fooCalled: Bool { fooCallsCount > 0 } — same name, same semantics, no change needed in tests
var fooCalledCount: Int = 0var 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 behaviorvar fooClosure: ((ArgTypes) -> ReturnType)?
Stored-property return values

Some bespoke mocks expose a plain stored property that a method simply returns:

swift
// Bespoke
var fooStatus: FooStatus = .idle

func getFooStatus(_ context: BarContext?) -> FooStatus {
    fooStatus
}

Tests write directly to the stored property:

swift
mockService.fooStatus = .active

The generated mock drops the stored property and routes through ReturnValue named after the method:

swift
// Generated
var getFooStatusReturnValue: FooStatus!

Tests update to:

swift
mockService.getFooStatusReturnValue = .active

The generated property name comes from the method (getFooStatus + ReturnValue), not from the old stored property name (fooStatus). They'll often differ — always read the generated output to confirm the exact name rather than guessing from the bespoke property.

Parameter capture: single vs. multiple

For a method with one named parameter, Sourcery generates a property named {methodName}Received{Label} — using the parameter's label, not a generic ReceivedArguments:

swift
// Protocol: func doThing(name: String) async throws
// Generated:
var doThingReceivedName: (String)?

For a method with multiple parameters, Sourcery collapses them into a single labeled tuple named ReceivedArguments. Bespoke mocks often spread these across several named properties — update all of them to go through the tuple:

swift
// Bespoke — separate property per argument
var doThingName: String?
var doThingCount: Int?
var doThingEnabled: Bool?

func doThing(name: String, count: Int, enabled: Bool) async {
    doThingName = name
    doThingCount = count
    doThingEnabled = enabled
}

// Generated — one tuple property, labeled with the parameter names
var doThingReceivedArguments: (name: String, count: Int, enabled: Bool)?
swift
// Before
mockService.doThingName == "hello"
mockService.doThingCount == 3
mockService.doThingEnabled == true

// After
mockService.doThingReceivedArguments?.name == "hello"
mockService.doThingReceivedArguments?.count == 3
mockService.doThingReceivedArguments?.enabled == true

Nil checks via optional chaining preserve the original semantics: mockService.doThingReceivedArguments?.name is nil both when the method was never called (whole tuple is nil) and when it was called with a nil argument — matching what the bespoke mockService.doThingName would have been.

Throwing methods
swift
// Bespoke
var fetchFoosResult: Result<[Foo], Error> = .success([])
func fetchFoos() async throws -> [Foo] {
    return try fetchFoosResult.get()
}

// Generated equivalent — two separate properties
mockService.fetchFoosReturnValue = []          // set return value
mockService.fetchFoosThrowableError = someErr  // or set error to throw

When both are set, the generated mock checks for ThrowableError first and throws it, ignoring ReturnValue.

Void-return throwing methods
swift
// Bespoke
var deleteFooCalled = false
var deleteFooError: Error?
func deleteFoo() async throws {
    deleteFooCalled = true
    if let error = deleteFooError { throw error }
}

// Generated equivalent
mockService.deleteFooThrowableError = someErr  // nil by default (no throw)
Methods with return values (non-throwing)
swift
// Bespoke
var isEnabledResult: Bool = false
func isEnabled() -> Bool { isEnabledResult }

// Generated equivalent
mockService.isEnabledReturnValue = false  // note: implicitly unwrapped optional, crashes if not set

Always set ReturnValue before the test exercises that method — it's T!, not T?. If you need to vary behavior across calls (e.g. return different values on successive invocations), use isEnabledClosure instead.

Show full SKILL.md (526 more words)Show less
Watch out: bespoke defaults vs. generated nil

Bespoke mocks often supply safe default return values (e.g. var isEnabledResult: Result<Bool, Error> = .success(false)). Every test that calls through to that method was silently relying on that default. The generated mock starts with isEnabledReturnValue: Bool! — nil — and will crash at runtime the first time a test exercises that path without setting it first.

After converting, look for this pattern: any test in the file that calls the subject under test but does not set *ReturnValue for a method that returns a non-optional. Check both:

  • The test body itself
  • Any shared setUp() that might need a default added

Don't just look at the test files — look at the production code too. A test might not reference a mock method directly, yet still exercise it indirectly through the subject under test. For each non-optional-returning method on the protocol, search the production implementations of the subjects that use this mock:

bash
grep -rn "<mockPropertyName>\." <path/to/subject/implementation>

If the subject calls any of those methods anywhere in its implementation, every test that exercises that code path will crash without a default. Add the appropriate defaults to setUp() to cover the whole suite.

The fix is to set a sensible default in the shared setup, covering all tests that don't care about that method's return value. The pattern differs by test framework:

XCTest:

swift
override func setUp() {
    super.setUp()
    mockService = MockFooService()
    mockService.isEnabledReturnValue = false  // safe default for tests that don't configure it
}

Swift Testing:

swift
struct FooTests {
    var mockService: MockFooService

    init() {
        mockService = MockFooService()
        mockService.isEnabledReturnValue = false  // safe default for tests that don't configure it
    }
}

Tests that need a specific value override it in their own body as before.

Step 4: Delete the Bespoke Mock

Remove the bespoke mock:

  • If it's a standalone file (MockFoo.swift), delete the entire file.
  • If it's defined inside another file, remove the class definition.

Check that no other code imports or references the bespoke mock class directly.

After deleting a standalone file, regenerate the Xcode project so the stale file reference is removed — otherwise the build will fail with "Build input file cannot be found":

bash
# Match to the framework where the mock lived
mint run xcodegen --spec project-pm.yml
mint run xcodegen --spec project-bwa.yml
mint run xcodegen --spec project-bwk.yml

Step 5: Regenerate Mocks

Run Sourcery manually to generate the new mock before updating tests, so you can see exactly what was generated:

bash
# Match to the framework where the protocol lives
# Requires BUILD_DIR — see the script header for the standalone one-liner
./Scripts/generate-mocks.sh BitwardenShared
./Scripts/generate-mocks.sh BitwardenKit
./Scripts/generate-mocks.sh AuthenticatorShared
./Scripts/generate-mocks.sh AuthenticatorBridgeKit

After running, find the new Mock<ProtocolName> block in the appropriate Sourcery/Generated/AutoMockable.generated.swift and read it to confirm the property names before updating tests.

Step 6: Update Tests

With the generated mock's actual property names in hand, update each test that used the bespoke mock. Translate according to the mapping in Step 3.

Common things to change:

  • Replace Result-based setup with ReturnValue/ThrowableError
  • Replace bespoke parameter capture properties with Received{Label} (single param) or ReceivedArguments tuple (multiple params)
Adding the import

Generated mocks live in BitwardenSharedMocks (or AuthenticatorSharedMocks, etc.), not in the test target directly. Any test file that references the generated mock class needs:

swift
@testable import BitwardenSharedMocks

This applies to:

  • Test files (*Tests.swift) that declare or use the mock
  • TestHelpers/ files that reference the mock class (e.g., factories that return a mock as a fallback)

If you see cannot find type 'MockFoo' in scope after deleting a bespoke mock, a missing import is almost always the cause. Check every file that previously had access to the bespoke mock via co-location.

Step 7: Verify

Format, lint, then run the affected tests:

bash
mint run swiftformat .
mint run swiftlint

Run the affected test suite (read simulator config from the project files):

bash
DEVICE=$(tr -d '\n' < .test-simulator-device-name)
OS=$(tr -d '\n' < .test-simulator-ios-version)
xcodebuild test \
  -workspace Bitwarden.xcworkspace \
  -scheme Bitwarden \
  -testPlan Bitwarden-Default \
  -only-testing "<TargetTests>/<TestClassName>" \
  -destination "platform=iOS Simulator,name=$DEVICE,OS=$OS"

Fix any compile errors or test failures from the API translation.

© bitwarden, GPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/converting-mocks-to-automockable of bitwarden/ios.

Open the folder on GitHubat commit 08f8c1d

Compare with similar skills

Converting Mocks To Automockable next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Converting Mocks To Automockable compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Converting Mocks To Automockable this skillbitwarden/ios696—~3.5kAutomated safety check: PassGPL-3.0
Swiftui Protwostraws/SwiftUI-Agent-Skill5.2k2 repos~1.5kAutomated safety check: PassMIT
Swiftui UI PatternsAFK-surf/OpenBridge4304 repos~887Automated safety check: PassMIT
Swiftui Performance Auditharperreed/dotfiles3348 repos~1.4kAutomated safety check: PassNone
Swift Testing ExpertAvdLee/Swift-Testing-Agent-Skill4701 repos~1.2kAutomated safety check: PassMIT
Hig Project Contextraintree-technology/hig-doctor1435 repos~1.2kAutomated safety check: PassMIT

Similar skills

  • Swiftui Pro

    twostraws/SwiftUI-Agent-Skill

    Comprehensively reviews SwiftUI code for best practices on modern APIs, maintainability, and performance.

    5.2k GitHub starsUsed in 2 repos~1.5k tokens
    MobileAuto-check passed
  • Swiftui UI Patterns

    AFK-surf/OpenBridge

    Best practices and example-driven guidance for building SwiftUI views and components.

    430 GitHub starsUsed in 4 repos~887 tokens
    MobileAuto-check passed
  • Swiftui Performance Audit

    harperreed/dotfiles

    Audit and improve SwiftUI runtime performance from code review and architecture.

    334 GitHub starsUsed in 8 repos~1.4k tokens
    MobileAuto-check passed
  • Swift Testing Expert

    AvdLee/Swift-Testing-Agent-Skill

    Expert guidance for Swift Testing: test structure, expect/require macros, traits and tags, parameterized tests, test plans, parallel execution, async waiting patterns, and XCTest migration.

    470 GitHub starsUsed in 1 repo~1.2k tokens
    MobileAuto-check passed
  • Hig Project Context

    raintree-technology/hig-doctor

    Create or update a shared Apple design context document that other HIG skills use to tailor guidance.

    143 GitHub starsUsed in 5 repos~1.2k tokens
    MobileAuto-check passed
  • Swift Testing Pro

    twostraws/Swift-Testing-Agent-Skill

    Writes, reviews, and improves Swift Testing code using modern APIs and best practices.

    453 GitHub stars~1.1k tokensUpdated 4 mo ago
    MobileAuto-check passed

More from bitwarden/ios

All 11 skills in this repo
  • Testing iOS Code

    bitwarden/ios

    Official

    Write tests, add test coverage, unit test, or add missing tests for Bitwarden iOS.

    696 GitHub stars~1.8k tokensUpdated today
    Auto-check passed
  • Official

    Build the Bitwarden iOS app, capture all compiler and lint warnings, categorize them into Swift 6 concurrency vs actionable, and interactively fix the actionable ones.

    696 GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • Build Test Verify

    bitwarden/ios

    Official

    Build the project, run tests, lint, format, spell check, generate mocks, or verify the build passes for Bitwarden iOS.

    696 GitHub stars~1.3k tokensUpdated today
    Auto-check passed
  • Official

    Evaluates a bitwarden/ios "Update SDK to" PR against the sdk-swift commit range for compile-time, runtime and serialization breaking changes, maps affected symbols to iOS call sites, and applies…

    696 GitHub stars~2.6k tokensUpdated today
    Auto-check passed
  • Fixing Flaky Tests

    bitwarden/ios

    Official

    Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS.

    696 GitHub stars~2.3k tokensUpdated today
    Auto-check passed
  • Official

    Implement, write code, add a new screen, create a feature, new view, new processor, or wire up a new service in Bitwarden iOS.

    696 GitHub stars~1.9k tokensUpdated today
    Auto-check passed

Categories

Questions about Converting Mocks To Automockable

What does Converting Mocks To Automockable do?

Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock. Converting Mocks To Automockable is an agent skill from bitwarden/ios, published by the product's own GitHub organization. Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock.

When should I use Converting Mocks To Automockable?

Converting Mocks To Automockable fits situations like: the user says convert this mock; migrate mock to AutoMockable; replace bespoke mock; use Sourcery for this mock.

How do I install Converting Mocks To Automockable in Claude Code?

Run `npx skills add bitwarden/ios --skill converting-mocks-to-automockable -a claude-code`. Or copy the skill folder (.claude/skills/converting-mocks-to-automockable in bitwarden/ios) into .claude/skills/converting-mocks-to-automockable in your project. Claude Code loads it when a task matches its description.

How do I install Converting Mocks To Automockable in Codex?

Run `npx skills add bitwarden/ios --skill converting-mocks-to-automockable -a codex`. Or copy the skill folder (.claude/skills/converting-mocks-to-automockable in bitwarden/ios) into .agents/skills/converting-mocks-to-automockable in your project. Codex loads it when a task matches its description.

Can I use Converting Mocks To Automockable in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add bitwarden/ios --skill converting-mocks-to-automockable -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/converting-mocks-to-automockable, .gemini/skills/converting-mocks-to-automockable, .github/skills/converting-mocks-to-automockable and .opencode/skills/converting-mocks-to-automockable in your project.

What does Converting Mocks To Automockable need to run?

Going by SKILL.md and its folder, Converting Mocks To Automockable needs the command-line tools its instructions call (xcodebuild).

Does Converting Mocks To Automockable access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Converting Mocks To Automockable safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Converting Mocks To Automockable use?

Converting Mocks To Automockable is published under the GPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Converting Mocks To Automockable use?

About 3.5k tokens (SKILL.md is roughly 14k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Converting Mocks To Automockable?

Skills that share tags, products or a category with Converting Mocks To Automockable: Swiftui Pro (twostraws/SwiftUI-Agent-Skill, 5.2k stars), Swiftui UI Patterns (AFK-surf/OpenBridge, 430 stars), Swiftui Performance Audit (harperreed/dotfiles, 334 stars) and Swift Testing Expert (AvdLee/Swift-Testing-Agent-Skill, 470 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Converting Mocks To Automockable?

bitwarden (a GitHub organization, an official publisher) maintains it in bitwarden/ios, which has 696 GitHub stars. The repository holds 11 skills in this directory. The repository was last updated on October 9, 2026.

Source: bitwarden/ios on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.