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_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 cancelAllTasks() {
session.getAllTasks { tasks in
tasks.forEach { $0.cancel() }
}
}
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 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."){
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") { _ 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: (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() {
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
extension XCTContext {
/// Create and run a new activity with provided name and block.
public class func runActivity<Result>(named name: String, block: (XCTActivity) throws -> Result) rethrows -> Result
}
class TableOfContentsSpec: QuickSpec {
override func spec() {
describe("the 'Documentation' directory") {
it("has everything you need to get started") {
let sections = Directory("Documentation").sections
expect(sections).to(contain("Organized Tests with Quick Examples and Example Groups"))
expect(sections).to(contain("Installing Quick"))
}
context("if it doesn't have what you're looking for") {