Skip to content

Instantly share code, notes, and snippets.

View victorpanitz's full-sized avatar
📱

Victor Panitz Magalhães victorpanitz

📱
  • iFood
  • Porto Alegre
View GitHub Profile
func test_Validation_Case_1() {
XCTContext.runActivity(named: "Given valueA is false, valueB is true and valueC is false") { _ in
let a = false
let b = true
let c = false
XCTContext.runActivity(named:"When validation is called") { _ in
sut.validation(valueA: a, valueB: b, valueC: c)
XCTContext.runActivity(named:"Then should call setup method passing a, b and c."){ _ in
func given<A>(_ description: String, block: (XCTActivity) throws -> A) rethrows -> A {
return try XCTContext.runActivity(named: "Given " + description, block: block)
}
func when<A>(_ description: String, block: (XCTActivity) throws -> A) rethrows -> A {
return try XCTContext.runActivity(named: "When " + description, block: block)
}
func then<A>(_ description: String, block: (XCTActivity) throws -> A) rethrows -> A {
return try XCTContext.runActivity(named: "Then " + description, block: block)
func test_Validation_Case_1() {
given("valueA is false, valueB is true and valueC is false") { _ in
let a = false
let b = true
let c = false
when("validation is called") { _ in
sut.validation(valueA: a, valueB: b, valueC: c)
then("should call setup method passing a, b and c."){ _ in
func given<A>(_ description: String, block: () throws -> A) rethrows -> A {
return try XCTContext.runActivity(named: "Given " + description, block: { _ in try block() })
}
func when<A>(_ description: String, block: () throws -> A) rethrows -> A {
return try XCTContext.runActivity(named: "When " + description, block: { _ in try block() })
}
func then<A>(_ description: String, block: () throws -> A) rethrows -> A {
return try XCTContext.runActivity(named: "Then " + description, block: { _ in try block() })
func test_Validation_Case_1() {
given("valueA is false, valueB is true and valueC is false") {
let a = false
let b = true
let c = false
when("validation is called") {
sut.validation(valueA: a, valueB: b, valueC: c)
then("should call setup method passing a, b and c."){
import os.log
func given<A>(_ description: String, block: () throws -> A) rethrows -> A {
os_log("1º Given %{public}@", description)
return try XCTContext.runActivity(named: "Given " + description, block: { _ in try block() })
}
func when<A>(_ description: String, block: () throws -> A) rethrows -> A {
os_log("2º When %{public}@", description)
return try XCTContext.runActivity(named: "When " + description, block: { _ in try block() })
func cancelAllTasks() {
session.getAllTasks { tasks in
tasks.forEach { $0.cancel() }
}
}
func test_cancellAllTasks_givenExistsActiveTasks_shouldCancellAllOfThem() {
let sut = Network( parameters ... )
sut.session.dataTask(with: URL(fileURLWithPath: "lorem/ipsum")).resume()
sut.session.dataTask(with: URL(fileURLWithPath: "foo/bar")).resume()
...
}
func test_cancellAllTasks_givenExistsActiveTasks_shouldCancellAllOfThem() {
...
let getTasksExpectation = XCTestExpectation(description: "getTasksExpectation")
var activeTasksCount: Int?
sut.session.getAllTasks { tasks in
activeTasksCount = tasks.count
func test_cancellAllTasks_givenExistsActiveTasks_shouldCancellAllOfThem() {
...
let cancelTasksExpectation = XCTestExpectation(description: "cancelTasksExpectation")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
sut.session.getAllTasks { tasks in
activeTasksCount = tasks.count
cancelTasksExpectation.fulfill()