title: Pointer to block pointer
body: <p>I have a method using promises (PMKPromise), that I'd like to unit test using the library Kiwi.</p>
  
  <p>My method looks like this:</p>
  
  <pre><code>- (void)fetchData {
  [PMKPromise new:^(PMKPromiseFulfiller fulfill, PMKPromiseRejecter reject) {
      // make the request
  }].then(^(NSDictionary *data){
      // code that I'd like to test
  });
  }
  </code></pre>
  
  <p>I want to capture and execute the promise completion block (called "then"), and I managed to do it this way (with a mocked promise):</p>
  
  <pre><code>// capture the promise completion block
  __block void (^capturedBlock)(NSDictionary *);
  
  [thePromise stub:@selector(then) withBlock:^id(NSArray *params) {
      return ^(id block){
          capturedBlock = block;
          return nil;
      };
  }];
  
  [myObj fetchData];
  
  // execute the block
  capturedBlock(@{});
  </code></pre>
  
  <p>What I'd like to do now is to hide this ugly code in a category that I could easily use in the future when unit testing promises.</p>
  
  <p>I'd like to pass a block "double pointer" as a method argument. </p>
  
  <p>This could be the implementation:</p>
  
  <pre><code>@interface NSObject (PMKPromiseTest)
  
  - (void)captureThenBlock:(void (^ *)(NSDictionary *))capturedBlock;
  
  @end
  
  @implementation NSObject (PMKPromiseTest)
  
  - (void)captureThenBlock:(void (^ *)(NSDictionary *))capturedBlock {
  
      [self stub:@selector(then) withBlock:^id(NSArray *params) {
          return ^(id block){
              *capturedBlock = block;
              return nil;
          };
      }];
  }
  
  @end
  </code></pre>
  
  <p>And this is how I would use it:</p>
  
  <pre><code>// capture the promise completion block:
  void (^capturedBlock)(NSDictionary *);
  [thePromise captureThenBlock:&amp;capturedBlock];
  
  [myObj fetchData];
  
  // execute it
  capturedBlock(@{});  // Exception! captureBlock is nil
  </code></pre>
  
  <p>Unfortunately this code does not work. When stepping in, the block is indeed captured. But once out, at the moment of executing the captured block, it is nil.</p>