Skip to content
A spunky mocking library for Swift
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Carthage/Checkouts
Documentation
Moxie.xcodeproj
Sources/Moxie
Tests
.gitignore
.swift-version
.travis.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cartfile.private
Cartfile.resolved
LICENSE
Moxie.podspec
Package.swift
README.md
moxie.jpeg

README.md

Moxie

Build Status License Pod

A spunky mocking library for Swift

Moxie

Using Moxie

Let's say you have a protocol you want to mock.

protocol List {
    mutating func add(_ item: String)
    mutating func clear()

    func get(_ index: Int) -> String?
}

You can use Moxie to create a mock.

import Moxie

struct MockList: Mock, List {
    var moxie = Moxie()

    mutating func add(_ item: String) {
        record(function: "add", wasCalledWith: [item])
    }

    mutating func clear() {
        record(function: "clear")
    }

    func get(_ index: Int) -> String? {
        return value(forFunction: "get")
    }
}

Then you can use it in your tests.

func testList() {

    var mockList = MockList()

    // verifying invocations
    mockList.add("one")
    mockList.clear()

    XCTAssertTrue(mockList.invoked(function: "add"))
    XCTAssertEqual("one", mockList.parameters(forFunction: "add")[0] as? String)
    XCTAssertTrue(mockList.invoked(function: "clear"))

    // stubbing
    mockList.stub(function: "get", return: "first")

    XCTAssertEqual("first", mockList.get(0))
}

Documentation

  1. Installation
  2. Creating Mocks
  3. Stubbing
  4. Verifying Invocations
You can’t perform that action at this time.