Latest 0.2
Homepage https://github.com/jwilkey/Spurious
License MIT
Platforms ios 8.0, requires ARC
Authors

Version
License
Platform

Why so spurious? Because sometimes the real thing is just too risky.

databaseSaver.save()        // real records, yikes!
requestMaker.makeRequest()  // pound that server!
rainMaker.makeRain()        // goodness no!

Spurious makes it easier to stub and fake object dependencies when testing.

Usage

Given

class FakeRainMaker: RainMaker, SpuriousTestable {
    func makeRain() -> String {
        // will register any calls with Spurious, identified by String "makeRain()"
        return callSpurious() 
    }

    func rainfallTotals(cityName: String, month: Int) -> Int {
        // will register any calls with Spurious, identified by String "rainfallTotals(_:month:)"
        return callSpurious([cityName, month])
    }
}

When

rainMaker = FakeRainMaker()
subject.rainMaker = rainMaker
rainMaker.stub("makeRain()", yield: "Chocolate rain")

Fantastic. And then (using Quick matchers):

let rain = subject.precipitation()
expect(rainMaker.wasCalled("makeRain()")).to(beTruthy())
expect(rain) == "Chocolate rain"

Using Swift 2 ability to provide default implementations for protocols, an instance of a particular class or protocol can be declared as also implementing protocol SpuriousTestable, and will automatically gain the ability to register stubs and verify function calls through an instance of Spurious.

More…

rainMaker.stub("rainfallTotals(_:month:)", yield: 5555)
let totalInches = subject.getLocalRainLastJanuary()

expect(rainMaker.wasCalled("rainfallTotals(_:month:)", <-"UserCity", <-1)) == true
// can also be written as:
expect(rainMaker.wasCalled("rainfallTotals(_:month:)", with("UserCity"), and(1))) == true

expect(totalInches) == 5555

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Swift 2.0

Installation

Spurious is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Spurious"

Author

Justin Wilkey

License

Spurious is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Spurious",
    "version": "0.2",
    "summary": "A testing tool that eases pure Swift stubbing, faking & verifying",
    "description": "Easily create Swift test object fakes and mocks that can be stubbed, and that can verify function calls. Allows for easy testing of interface with dependencies without the overhead of creating extensive or duplicate fake class implementations.",
    "homepage": "https://github.com/jwilkey/Spurious",
    "license": "MIT",
    "authors": {
        "Justin Wilkey": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jwilkey/Spurious.git",
        "tag": "0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "Spurious": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This