Giter VIP home page Giter VIP logo

spurious's Introduction

Spurious

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.

spurious's People

Contributors

jwilkey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.