FoundationExtensionsSpec.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // FoundationExtensionsSpec.swift
  3. // ReactiveCocoa
  4. //
  5. // Created by Neil Pankey on 5/22/15.
  6. // Copyright (c) 2015 GitHub. All rights reserved.
  7. //
  8. import Result
  9. import Nimble
  10. import Quick
  11. import ReactiveCocoa
  12. class FoundationExtensionsSpec: QuickSpec {
  13. override func spec() {
  14. describe("NSNotificationCenter.rac_notifications") {
  15. let center = NSNotificationCenter.defaultCenter()
  16. it("should send notifications on the producer") {
  17. let producer = center.rac_notifications("rac_notifications_test")
  18. var notif: NSNotification? = nil
  19. let disposable = producer.startWithNext { notif = $0 }
  20. center.postNotificationName("some_other_notification", object: nil)
  21. expect(notif).to(beNil())
  22. center.postNotificationName("rac_notifications_test", object: nil)
  23. expect(notif?.name) == "rac_notifications_test"
  24. notif = nil
  25. disposable.dispose()
  26. center.postNotificationName("rac_notifications_test", object: nil)
  27. expect(notif).to(beNil())
  28. }
  29. it("should send Interrupted when the observed object is freed") {
  30. var observedObject: AnyObject? = NSObject()
  31. let producer = center.rac_notifications(object: observedObject)
  32. observedObject = nil
  33. var interrupted = false
  34. let disposable = producer.startWithInterrupted {
  35. interrupted = true
  36. }
  37. expect(interrupted) == true
  38. disposable.dispose()
  39. }
  40. }
  41. }
  42. }