Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is how you do this in Kiwi:</p> <p>First, you must dependency inject <code>NetworkClass</code> to <code>TestedClass</code> (if it's not clear how, please add a comment and I'll explain; this can be done as a property for simplicity. This is so that you can operate on a mock object for the <code>NetworkClass</code>)</p> <p>Then your spec, create the mock for the network class and create your class that you want to unit test:</p> <pre><code>SPEC_BEGIN(TestSpec) describe(@"describe goes here", ^{ it(@"should test block", ^{ NetworkClass *mockNetworkClass = [NetworkClass mock]; KWCaptureSpy *spy = [mockNetworkClass captureArgument:@selector(networkMethod:) atIndex:0]; TestedClass testClass = [TestedClass alloc] init]; testClass.networkClass = mockNetworkClass; [testClass testMethod]; NetworkClassCallback blockToRun = spy.argument; blockToRun(nil); // add expectations here }); }); SPEC_END </code></pre> <p>To explain what's going on here:</p> <p>You are creating <code>TestedClass</code> and calling <code>testMethod</code>. However, before that, we are creating something called <code>Spy</code> - its job is to capture the block in the first parameter when <code>networkMethod:</code> is called. Now, it's time to actually execute the block itself.</p> <p>It's easy to be confused here so I'll emphasize this: the order of calls is important; you first declare the spy, then call the tested method, and only then you're actually calling and executing the block!</p> <p>This will give you the ability to check what you want as you're the one executing the block.</p> <p>Hope it helps for other, as it took me quite sometime to understand this flow.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload