Latest 0.1.5
Homepage https://github.com/DarthStrom/Moxie
License MIT
Platforms osx 10.10, ios 8.1
Authors

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", whenCalledWith: [index])
    }
}

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", with: ["one"]))
    XCTAssertTrue(mockList.invoked(function: "clear"))

    // stubbing
    mockList.stub(function: "get", whenCalledWith: [0], return: "first")

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

    // nil because get(999) was not stubbed
    XCTAssertNil(mockList.get(999))
}

Documentation

  1. Installation
  2. Creating Mocks
  3. Stubbing
  4. Verifying Invocations

Latest podspec

{
    "name": "Moxie",
    "version": "0.1.5",
    "summary": "A mocking library for Swift.",
    "description": "Moxie makes creating mocks easier in Swift.",
    "homepage": "https://github.com/DarthStrom/Moxie",
    "license": "MIT",
    "authors": {
        "Jason Duffy": "[email protected]"
    },
    "social_media_url": "http://twitter.com/DarthStrom",
    "source": {
        "git": "https://github.com/DarthStrom/Moxie.git",
        "tag": "v0.1.5"
    },
    "source_files": "Sources/**/*.swift",
    "platforms": {
        "osx": "10.10",
        "ios": "8.1"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This