-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for the basic behaviors of the Result type.
- Loading branch information
1 parent
1f4586c
commit 43a0312
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Quick | ||
import Nimble | ||
|
||
@testable import Concurrency | ||
|
||
class ResultTests: QuickSpec { | ||
override func spec() { | ||
|
||
var subject: Result<Int>! | ||
let noBuenoError = NSError(domain: "No bueno", code: 666, userInfo: nil) | ||
|
||
describe("Result") { | ||
|
||
describe("onSuccess and onError syntactic sugar") { | ||
|
||
context("when the case is success") { | ||
var resultString = "" | ||
|
||
beforeEach { | ||
subject = .success(3) | ||
subject.onSuccess({ (value) in | ||
resultString = "Success: \(value)" | ||
}) | ||
subject.onError({ (_) in | ||
resultString = "Oopsie!" | ||
}) | ||
} | ||
|
||
it("should respond to the onSuccess block") { | ||
expect(resultString).to(equal("Success: 3")) | ||
} | ||
} | ||
|
||
context("when the case is error") { | ||
var resultString = "" | ||
|
||
beforeEach { | ||
subject = .error(noBuenoError) | ||
subject.onSuccess({ (value) in | ||
resultString = "Success: \(value)" | ||
}) | ||
subject.onError({ (_) in | ||
resultString = "Oopsie!" | ||
}) | ||
} | ||
|
||
it("should respond to the onError block") { | ||
expect(resultString).to(equal("Oopsie!")) | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|