Last active
August 29, 2015 14:14
-
-
Save Gurpartap/b67968bd88c6e75287cc to your computer and use it in GitHub Desktop.
Quick bug? Update: Not anymore.
This file contains hidden or 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
import Quick | |
import Nimble | |
class LibrarySpec: QuickSpec { | |
override func spec() { | |
describe("library") { | |
var library: Library! | |
beforeEach { | |
library = Library() | |
} | |
context("when initialized") { | |
it("has no playlists") { | |
expect(library.hasPlaylists()).to(beFalse()) | |
} | |
} | |
context("when populated with valid playlists") { | |
// where can i use library initialized by beforeEach? | |
// a) library.addPlaylist(Playlist()) | |
// but library is nil here. beforeEach was not called? | |
// fatal error: unexpectedly found nil while unwrapping an Optional value | |
// Fix: Wrap it in beforeEach. | |
beforeEach { | |
library.addPlaylist(Playlist()) | |
} | |
it("has playlists") { | |
// b) library.addPlaylist(Playlist()) | |
// works... | |
expect(library.hasPlaylists()).to(beTrue()) | |
} | |
it("has only 1 playlist") { | |
// b) library.addPlaylist(Playlist()) | |
// works... | |
expect(library.size()).to(equal(1)) | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
struct Library { | |
var playlists = Array<Playlist>() | |
mutating func addPlaylist(playlist: Playlist) { | |
playlists.append(playlist) | |
} | |
func size() -> Int { | |
return playlists.count | |
} | |
func hasPlaylists() -> Bool { | |
return size() > 0 | |
} | |
} | |
struct Playlist { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment