Created
January 8, 2020 15:36
-
-
Save turekj/a21612c0f21877967ce06a6341e8f015 to your computer and use it in GitHub Desktop.
Supplementary behaviour code for https://jakubturek.com/bottom-up-unit-testing/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YearsBetweenDatesBehavior: | |
Behavior<YearsBetweenDatesBehavior.Context> { | |
struct Context { | |
let sut: (Calendar) -> (Date, Date) -> Int? | |
let from: String | |
let to: String | |
let calendar: Calendar.Identifier | |
let expected: Int | |
} | |
override class func spec(_ aContext: @escaping | |
() -> YearsBetweenDatesBehavior.Context) { | |
let calendar = aContext().calendar | |
let from = aContext().from | |
let to = aContext().to | |
let expected = aContext().expected | |
describe("years between") { | |
context("with calendar \(calendar)") { | |
var sut: ((Date, Date) -> Int?)! | |
beforeEach { | |
sut = aContext().sut(Calendar(identifier: calendar)) | |
} | |
afterEach { | |
sut = nil | |
} | |
context("from \(from) to \(to)") { | |
var yearsBetween: Int? | |
beforeEach { | |
yearsBetween = sut(from.date, to.date) | |
} | |
afterEach { | |
yearsBetween = nil | |
} | |
it("should return \(expected) years") { | |
expect(yearsBetween).toNot(beNil()) | |
expect(yearsBetween) == expected | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment