RACChannelSpec.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // RACChannelSpec.m
  3. // ReactiveCocoa
  4. //
  5. // Created by Uri Baghin on 30/12/2012.
  6. // Copyright (c) 2012 GitHub, Inc. All rights reserved.
  7. //
  8. #import <Quick/Quick.h>
  9. #import <Nimble/Nimble.h>
  10. #import "RACChannelExamples.h"
  11. #import "NSObject+RACDeallocating.h"
  12. #import "RACChannel.h"
  13. #import "RACCompoundDisposable.h"
  14. #import "RACDisposable.h"
  15. #import "RACSignal.h"
  16. QuickSpecBegin(RACChannelSpec)
  17. qck_describe(@"RACChannel", ^{
  18. qck_itBehavesLike(RACChannelExamples, ^{
  19. return @{
  20. RACChannelExampleCreateBlock: [^{
  21. return [[RACChannel alloc] init];
  22. } copy]
  23. };
  24. });
  25. qck_describe(@"memory management", ^{
  26. qck_it(@"should dealloc when its subscribers are disposed", ^{
  27. RACDisposable *leadingDisposable = nil;
  28. RACDisposable *followingDisposable = nil;
  29. __block BOOL deallocated = NO;
  30. @autoreleasepool {
  31. RACChannel *channel __attribute__((objc_precise_lifetime)) = [[RACChannel alloc] init];
  32. [channel.rac_deallocDisposable addDisposable:[RACDisposable disposableWithBlock:^{
  33. deallocated = YES;
  34. }]];
  35. leadingDisposable = [channel.leadingTerminal subscribeCompleted:^{}];
  36. followingDisposable = [channel.followingTerminal subscribeCompleted:^{}];
  37. }
  38. [leadingDisposable dispose];
  39. [followingDisposable dispose];
  40. expect(@(deallocated)).toEventually(beTruthy());
  41. });
  42. qck_it(@"should dealloc when its subscriptions are disposed", ^{
  43. RACDisposable *leadingDisposable = nil;
  44. RACDisposable *followingDisposable = nil;
  45. __block BOOL deallocated = NO;
  46. @autoreleasepool {
  47. RACChannel *channel __attribute__((objc_precise_lifetime)) = [[RACChannel alloc] init];
  48. [channel.rac_deallocDisposable addDisposable:[RACDisposable disposableWithBlock:^{
  49. deallocated = YES;
  50. }]];
  51. leadingDisposable = [[RACSignal never] subscribe:channel.leadingTerminal];
  52. followingDisposable = [[RACSignal never] subscribe:channel.followingTerminal];
  53. }
  54. [leadingDisposable dispose];
  55. [followingDisposable dispose];
  56. expect(@(deallocated)).toEventually(beTruthy());
  57. });
  58. });
  59. });
  60. QuickSpecEnd