Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polished sourcery templates given in #14 #17

Merged
merged 5 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .sourcery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
- ./Example/SwiftyMock/RoboKitten
templates:
- ./SwiftyMock/Templates
output:
path: ./Example/RoboKittenTests/Mocks/Generated
args:
testable: SwiftyMock_Example
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ SPEC CHECKSUMS:
ReactiveCocoa: 105ad96f6b8711f1ee7d165fc96587479298053b
ReactiveSwift: 5b26d2e988fe0eed2daf48c4054d1de74db50184
Result: d2d07204ce72856f1fd9130bbe42c35a7b0fea10
SwiftyMock: e0769d7dff9328adf0af2f977c98d861486393d5
SwiftyMock: 7ee122cdeb33302fff589ad3400085f464ccd292

PODFILE CHECKSUM: 2797c28d14fe41b5fd500d37769a81dfd8a59430
PODFILE CHECKSUM: 96e31c8bbe54905dd223cce795d28a49935d24a1

COCOAPODS: 1.5.3
58 changes: 58 additions & 0 deletions Example/RoboKittenTests/Mocks/Generated/Mock.generated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Generated using Sourcery 0.13.1 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

import Foundation
import SwiftyMock
@testable import SwiftyMock_Example

class FakeLazyRoboKitten: LazyRoboKitten {
let needsRestGetCall = FunctionVoidCall<Bool>()
let needsRestSetCall = FunctionCall<Bool, Void>()
var needsRest: Bool {
get { return stubCall(needsRestGetCall) }
set { stubCall(needsRestSetCall, argument: newValue) }
}

let batteryStatusCall = FunctionVoidCall<Int>()
func batteryStatus() -> Int {
return stubCall(batteryStatusCall)
}

let jumpCall = FunctionCall<(x: Int, y: Int), Void>()
func jump(x: Int, y: Int) {
return stubCall(jumpCall, argument: (x: x, y: y), defaultValue: ())
}

let canJumpAtCall = FunctionCall<(x: Int, y: Int), Bool>()
func canJumpAt(x: Int, y: Int) -> Bool {
return stubCall(canJumpAtCall, argument: (x: x, y: y))
}

let restCall = FunctionCall<(Bool) -> (), Void>()
func rest(_ completed: @escaping (Bool) -> ()) {
return stubCall(restCall, argument: completed, defaultValue: ())
}
}

class FakeRoboKitten: RoboKitten {

let batteryStatusCall = FunctionVoidCall<Int>()
func batteryStatus() -> Int {
return stubCall(batteryStatusCall)
}

let jumpCall = FunctionCall<(x: Int, y: Int), Void>()
func jump(x: Int, y: Int) {
return stubCall(jumpCall, argument: (x: x, y: y), defaultValue: ())
}

let canJumpAtCall = FunctionCall<(x: Int, y: Int), Bool>()
func canJumpAt(x: Int, y: Int) -> Bool {
return stubCall(canJumpAtCall, argument: (x: x, y: y))
}

let restCall = FunctionCall<(Bool) -> (), Void>()
func rest(_ completed: @escaping (Bool) -> ()) {
return stubCall(restCall, argument: completed, defaultValue: ())
}
}
33 changes: 0 additions & 33 deletions Example/RoboKittenTests/Mocks/RoboKittenMock.swift

This file was deleted.

52 changes: 26 additions & 26 deletions Example/RoboKittenTests/RoboKittenControllerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class RoboKittenControllerSpec: QuickSpec {
override func spec() {
describe("RoboKittenController") {
var sut: RoboKittenController!
var kittenMock: RoboKittenMock!
var kittenMock: FakeRoboKitten!
beforeEach {
kittenMock = RoboKittenMock()
kittenMock = FakeRoboKitten()
sut = RoboKittenController(kitten: kittenMock)
}

Expand Down Expand Up @@ -47,36 +47,36 @@ class RoboKittenControllerSpec: QuickSpec {

describe("when asked to jump somewhere") {
beforeEach {
kittenMock.canJump.returns(false)
kittenMock.canJumpAtCall.returns(false)
}
it("should ask kitten if it's available to jump there") {
sut.jumpAt(x: 10, y: 20)
expect(kittenMock.canJump.called).to(beTruthy())
expect(kittenMock.canJumpAtCall.called).to(beTruthy())
}

it("should ask kitten if it's available to jump there with the same coords") {
sut.jumpAt(x: 10, y: 20)
expect(kittenMock.canJump.capturedArgument?.x).to(equal(10))
expect(kittenMock.canJump.capturedArgument?.y).to(equal(20))
expect(kittenMock.canJumpAtCall.capturedArgument?.x).to(equal(10))
expect(kittenMock.canJumpAtCall.capturedArgument?.y).to(equal(20))
}

context("and kitten can jump there") {
beforeEach {
kittenMock.canJump.returns(true)
kittenMock.canJumpAtCall.returns(true)
}
it("should actually ask kitten to jump") {
sut.jumpAt(x: 15, y: 30)
expect(kittenMock.jump.called).to(beTruthy())
expect(kittenMock.jump.capturedArgument?.x).to(equal(15))
expect(kittenMock.jump.capturedArgument?.y).to(equal(30))
expect(kittenMock.jumpCall.called).to(beTruthy())
expect(kittenMock.jumpCall.capturedArgument?.x).to(equal(15))
expect(kittenMock.jumpCall.capturedArgument?.y).to(equal(30))
}

it("should actually ask kitten to jump only once per call") {
sut.jumpAt(x: 18, y: 23)
expect(kittenMock.jump.callsCount).to(equal(1))
expect(kittenMock.jumpCall.callsCount).to(equal(1))

sut.jumpAt(x: 80, y: 15)
expect(kittenMock.jump.callsCount).to(equal(2))
expect(kittenMock.jumpCall.callsCount).to(equal(2))
}

it("return success result") {
Expand All @@ -86,12 +86,12 @@ class RoboKittenControllerSpec: QuickSpec {

context("and kitten cannot jump there") {
beforeEach {
kittenMock.canJump.returns(false)
kittenMock.canJumpAtCall.returns(false)
}

it("should shouldn't ask kitten to jump") {
sut.jumpAt(x: 15, y: 30)
expect(kittenMock.jump.called).to(beFalsy())
expect(kittenMock.jumpCall.called).to(beFalsy())
}
it("shouldreturn failure result") {
expect(sut.jumpAt(x: 10, y: 20)).to(equal(Result.failure))
Expand All @@ -103,7 +103,7 @@ class RoboKittenControllerSpec: QuickSpec {
describe("when asked to perform multiple jumps") {
context("and kitten can perform all of them") {
beforeEach {
kittenMock.canJump.returns(true)
kittenMock.canJumpAtCall.returns(true)
}
it("should return success result") {
expect(sut.jump(inSequence: [(x: 10, y: 20), (x: 12, y: 20)])).to(equal(Result.success))
Expand All @@ -112,21 +112,21 @@ class RoboKittenControllerSpec: QuickSpec {
it("should call jump on each passed parameter in the correct order") {
let sequence = [(x: 15, y: 21), (x: 23, y: 21)]
sut.jump(inSequence: sequence)
expect(kittenMock.jump.callsCount).to(equal(2))
expect(kittenMock.jump.capturedArguments[0].x).to(equal(15))
expect(kittenMock.jump.capturedArguments[0].y).to(equal(21))
expect(kittenMock.jumpCall.callsCount).to(equal(2))
expect(kittenMock.jumpCall.capturedArguments[0].x).to(equal(15))
expect(kittenMock.jumpCall.capturedArguments[0].y).to(equal(21))

expect(kittenMock.jump.capturedArguments[1].x).to(equal(23))
expect(kittenMock.jump.capturedArguments[1].y).to(equal(21))
expect(kittenMock.jumpCall.capturedArguments[1].x).to(equal(23))
expect(kittenMock.jumpCall.capturedArguments[1].y).to(equal(21))
}
}

context("And kitten can not jump at some coordinates") {
beforeEach {
kittenMock.canJump
kittenMock.canJumpAtCall
.on { $0.x < 0 }.returns(false)
.on { $0.y < 0 }.returns(false)
.returns(true) // in all other cases
.returns(true) // in all other cases

}
context("and there are some coordinates where kitten cannot jump at in passed in sequence") {
Expand All @@ -139,7 +139,7 @@ class RoboKittenControllerSpec: QuickSpec {
it("should not ask kitten to jump at all") {
sut.jump(inSequence: [(x: -10, y: 20), (x: 12, y: 20)])

expect(kittenMock.jump.called).to(beFalsy())
expect(kittenMock.jumpCall.called).to(beFalsy())
}
}

Expand All @@ -155,12 +155,12 @@ class RoboKittenControllerSpec: QuickSpec {

it("should ask kitten to rest") {
sut.rest { _ in }
expect(kittenMock.rest.called).to(beTruthy())
expect(kittenMock.restCall.called).to(beTruthy())
}

context("and kitten rests successfully") {
beforeEach {
kittenMock.rest.performs { completion in
kittenMock.restCall.performs { completion in
completion(true)
}
}
Expand All @@ -175,7 +175,7 @@ class RoboKittenControllerSpec: QuickSpec {

context("and kitten fails to rest") {
beforeEach {
kittenMock.rest.performs { completion in
kittenMock.restCall.performs { completion in
completion(false)
}
}
Expand Down
16 changes: 12 additions & 4 deletions Example/SwiftyMock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
A7D119AA1D500828F6B64159 /* Pods_RoboKittenTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A380849D11951D85498E493C /* Pods_RoboKittenTests.framework */; };
D21AF4631FC62DF600C0DC5F /* SwiftyMockReactiveCallsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21AF4611FC62CFF00C0DC5F /* SwiftyMockReactiveCallsSpec.swift */; };
D21AF4661FC638F200C0DC5F /* ReactiveMatchers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21AF4641FC6324400C0DC5F /* ReactiveMatchers.swift */; };
D2AEE57F20F9559000FF7DC8 /* Mock.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2AEE57E20F9559000FF7DC8 /* Mock.generated.swift */; };
E434BE281D4AAE86000E7125 /* SwiftyMockCallsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = E434BE271D4AAE86000E7125 /* SwiftyMockCallsSpec.swift */; };
E481D6901D4DDE61000E73AE /* RoboKittenControllerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = E481D68F1D4DDE61000E73AE /* RoboKittenControllerSpec.swift */; };
EEDBE358155D115C15126670 /* RoboKitten.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDBEBCC4DF10B0C24246892 /* RoboKitten.swift */; };
EEDBE98564CE5D2A54750BFD /* RoboKittenV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDBE0C70C380389995EB816 /* RoboKittenV1.swift */; };
EEDBEAB8D9887C15ED1D0632 /* RoboKittenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDBE8EC7249C454D04FB152 /* RoboKittenController.swift */; };
EEDBED3915A12D3BF5C227B3 /* RoboKittenMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDBEDBDEDE79BAF07F7038A /* RoboKittenMock.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -62,6 +62,7 @@
BE3E75F38E5B31874FC7F8C4 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
D21AF4611FC62CFF00C0DC5F /* SwiftyMockReactiveCallsSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftyMockReactiveCallsSpec.swift; sourceTree = "<group>"; };
D21AF4641FC6324400C0DC5F /* ReactiveMatchers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactiveMatchers.swift; sourceTree = "<group>"; };
D2AEE57E20F9559000FF7DC8 /* Mock.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Mock.generated.swift; sourceTree = "<group>"; };
E434BE271D4AAE86000E7125 /* SwiftyMockCallsSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyMockCallsSpec.swift; sourceTree = "<group>"; };
E481D6831D4DDDBE000E73AE /* RoboKittenTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RoboKittenTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E481D6871D4DDDBE000E73AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -70,7 +71,6 @@
EEDBE0C70C380389995EB816 /* RoboKittenV1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoboKittenV1.swift; sourceTree = "<group>"; };
EEDBE8EC7249C454D04FB152 /* RoboKittenController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoboKittenController.swift; sourceTree = "<group>"; };
EEDBEBCC4DF10B0C24246892 /* RoboKitten.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoboKitten.swift; sourceTree = "<group>"; };
EEDBEDBDEDE79BAF07F7038A /* RoboKittenMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoboKittenMock.swift; sourceTree = "<group>"; };
F2E0186E90C589DC306B4DE9 /* Pods_SwiftyMock_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftyMock_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F8922BE058C4D4604D03C886 /* Pods-SwiftyMock_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftyMock_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftyMock_Tests/Pods-SwiftyMock_Tests.release.xcconfig"; sourceTree = "<group>"; };
FC5C9C80564A568114ED28E1 /* Pods-SwiftyMock_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftyMock_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftyMock_Example/Pods-SwiftyMock_Example.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -187,6 +187,14 @@
name = Frameworks;
sourceTree = "<group>";
};
D2AEE57D20F9559000FF7DC8 /* Generated */ = {
isa = PBXGroup;
children = (
D2AEE57E20F9559000FF7DC8 /* Mock.generated.swift */,
);
path = Generated;
sourceTree = "<group>";
};
D5147DA4ACDB782F513D0F5D /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -223,7 +231,7 @@
EEDBE0EC744C4D09DA6A1963 /* Mocks */ = {
isa = PBXGroup;
children = (
EEDBEDBDEDE79BAF07F7038A /* RoboKittenMock.swift */,
D2AEE57D20F9559000FF7DC8 /* Generated */,
);
path = Mocks;
sourceTree = "<group>";
Expand Down Expand Up @@ -544,8 +552,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D2AEE57F20F9559000FF7DC8 /* Mock.generated.swift in Sources */,
E481D6901D4DDE61000E73AE /* RoboKittenControllerSpec.swift in Sources */,
EEDBED3915A12D3BF5C227B3 /* RoboKittenMock.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 7 additions & 1 deletion Example/SwiftyMock/RoboKitten/RoboKitten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

import Foundation

// sourcery: Mock
protocol RoboKitten {
@discardableResult func batteryStatus() -> Int
func jump(x: Int, y: Int)
@discardableResult func canJumpAt(x: Int, y: Int) -> Bool
func rest(_ completed: @escaping (Bool) -> () )
func rest(_ completed: @escaping (Bool) -> ())
}

// sourcery: Mock
protocol LazyRoboKitten: RoboKitten {
var needsRest: Bool { get set }
}
Loading