Skip to content

Instantly share code, notes, and snippets.

@laiso
Created January 13, 2017 05:04
Show Gist options
  • Save laiso/3169c66a58143bb15846f797b2b65c94 to your computer and use it in GitHub Desktop.
Save laiso/3169c66a58143bb15846f797b2b65c94 to your computer and use it in GitHub Desktop.
こんなかんじ・・? #CodePiece
extension Charge {
static var stubObjects: [Charge] {
let JSON = json(from: "Fixtures/charges.json")
return try! decodeArray(JSON, rootKeyPath: "data")
}
}
struct MockWebAPI: HomeAPIProtocol {
func getCharges() -> Observable<[Charge]> {
return Observable.from(Charge.stubObjects)
}
}
class HomeViewModelSpec: QuickSpec {
override func spec() {
describe("HomeViewModel") {
var viewModel: HomeViewModel!
beforeEach {
let api = MockWebAPI()
viewModel = HomeViewModel(with: api)
}
describe("#charges") {
context("initial value") {
var charges: [Charge]!
beforeEach {
charges = viewModel.charges.value
}
it("should be equal stubing") {
let stub = Charge.stubObjects
expect(charges).to(equal(stub))
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment