Bankside 0.3.0

Bankside 0.3.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2015
SPMSupports SPM

Maintained by Bjarne Mogstad.



Bankside 0.3.0

  • By
  • Bjarne Mogstad

Bankside

Bankside is a fixture generation tool. It’s useful for defining fixtures for tests. Inspired by factory_girl and Rosie.js

Usage

Bankside provides an easy API for defining default attributes and options that allows you to change how you generate the data.

Defining a factory

struct Account {
  let id: Int
  let name: String
  init(payload: [String: Any]) {
    self.id = payload["id"] as! Int
    self.name = payload["name"] as! String
  }
} 
import Bankside

let AccountFactory = Factory({ Account(payload: $0) })
  .sequence("id")
  .attr("name", "Walter White")

Using a factory

let walter = AccountFactory.build()
let gustavo = AccountFactory.build(attributes: [
  "name": "Gustavo Fridge"
])

Extentions

To keep your fixtures DRY it’s useful to extend the Factory class and add common or complex default attributes. Remember to return self to keep the API chainable.

extension Factory {

  func timestamp() -> Self {
    func date(options: [String: Any]) {
      return NSDate()
    }
    self.attr("created_at", closure: date)
    self.attr("updated_at", closure: date)
    return self
  }

}

In use:

let AccountFactory = Factory({ Account(payload: $0) })
  .sequence("id")
  .attr("name", "Walter White")
  .timestamps()

Limitations

We don’t try to detect circular dependencies, you will just get a stack overflow if it happens.

Install

Requirements:

  • Bankside will be compatible with the lastest public release of Swift. Older releases will be available, but bug fixes won’t be issued.
  • A data structure that accepts a reflected data structure to populate its models.