<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Can't see nothing but the source code &#187; iPhone TDD</title>
	<atom:link href="http://codeforfun.wordpress.com/tag/iphone-tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeforfun.wordpress.com</link>
	<description>Java development with an iPhone touch pad for the Atari 2600 from an urban hip-hop perspective</description>
	<lastBuildDate>Thu, 10 Dec 2009 01:13:25 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='codeforfun.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/8d21f8fd8dcc021adcd46592bfbddcda?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Can't see nothing but the source code &#187; iPhone TDD</title>
		<link>http://codeforfun.wordpress.com</link>
	</image>
			<item>
		<title>You must fail before you can succeed!</title>
		<link>http://codeforfun.wordpress.com/2009/12/01/you-must-fail-before-you-can-succeed/</link>
		<comments>http://codeforfun.wordpress.com/2009/12/01/you-must-fail-before-you-can-succeed/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 01:28:44 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[Objective C unit tests]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1087</guid>
		<description><![CDATA[If you try to fail and you succeed, which have you actually done? Are you a success? Or a failure? Is it good to be a failure? Is it better to be successful at failure? Let&#8217;s add detail to the question. By the way, I&#8217;m Cliff. You&#8217;re here because you tried to fail and you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1087&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you try to fail and you succeed, which have you actually done? Are you a success? Or a failure? Is it good to be a failure? Is it better to be successful at failure? Let&#8217;s add detail to the question. By the way, I&#8217;m Cliff. You&#8217;re here because you tried to fail and you succeeded. Today&#8217;s topic is something I&#8217;ve visited before. It&#8217;s a new thing I&#8217;m trying with unit tests. Actually it&#8217;s an old thing to many but I&#8217;m trying it for the first time in both C++ and ObjC so it feels sorta new-ish.</p>
<p><strong>How do you unit test?</strong><br />
Let&#8217;s start with how you unit test. What are your steps? What are the recommended steps? In order to be successful at TDD you must appreciate the entirety of the practice. It goes, &#8220;Red, Green, Refactor&#8221;. Red comes before Green, just like with traffic lights. What I&#8217;m saying is that you have to begin with a failing test. The first test is important. The first failure should describe what work you have to do. In my case, I&#8217;m swimming in un-ventured waters (C++/ObjC++ testing) so there&#8217;s some learning that needs to be re-enforced. Here&#8217;s how I&#8217;ve been starting my tests recently:</p>
<pre class="brush: plain;">
//
//  MyCoolNewObjectTest.m
//  Created by cliftoncraig07 on 12/1/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import &lt;SenTestingKit/SenTestingKit.h&gt;
#include &quot;MyCoolNewObject.h&quot;

@interface MyCoolNewObjectTest : SenTestCase
{
  MyCoolNewObject *coolObject;
}
@end

@implementation MyCoolNewObjectTest

-(void) setUp
{}

@end
</pre>
<p>The test shell is completely empty except for references to the &#8220;thing&#8221; I&#8217;m about to create. I get my first failure which is a compile error stating that this thing does not exist. &#8220;No such file error&#8230;&#8221; around the include. Here I have an opportunity to review my design as minimalist as it is. I ask, &#8220;Does the error make sense? Is it expected? Do I like the name of this cool new thing I&#8217;m creating? Is it specific to the task I&#8217;m assigned to?&#8221; Always review each error with these question. After creating the files for the new &#8220;thing&#8221; I then follow up with:</p>
<pre class="brush: plain;">
//
//  MyCoolNewObjectTest.m
//  Created by cliftoncraig07 on 12/1/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import &lt;SenTestingKit/SenTestingKit.h&gt;
#include &quot;MyCoolNewObject.h&quot;

@interface MyCoolNewObjectTest : SenTestCase
{
  MyCoolNewObject *coolObject;
}
@end

@implementation MyCoolNewObjectTest

-(void) setUp
{ STFail(@&quot;You must fail before you can succeed!&quot;); }

@end
</pre>
<p>Also important, while I train myself on the new testing framework, because I need to catch myself misnaming the &#8220;setup&#8221; method which should have a capital &#8220;U&#8221;. It also lets me know that my test is actually running as part of the suite. Far too often, in Xcode, I&#8217;ll have the wrong target active and begin writing the wrong code because I was getting false positives from tests that were never run. Here&#8217;s where it gets interesting. The STFail in the above example does not fail! Now we face our original question, if you try to fail, as we have above, and you succeed like our test suite will do here, which have you actually done? The first time I hit the unexpected success I got nervous and read all around the SenTesting framework and OCUnit. Eventually I settled on the conclusion that because there were no tests to run the setUp was being optimized away as unnecessary. What the above example is pointing out is that such a test case can never fail since there are no tests. That leads us to our final step&#8230;</p>
<pre class="brush: plain;">
//
//  MyCoolNewObjectTest.m
//  Created by cliftoncraig07 on 12/1/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import &lt;SenTestingKit/SenTestingKit.h&gt;
#include &quot;MyCoolNewObject.h&quot;

@interface MyCoolNewObjectTest : SenTestCase
{
  MyCoolNewObject *coolObject;
}
@end

@implementation MyCoolNewObjectTest

-(void) setUp
{ STFail(@&quot;You must fail before you can succeed!&quot;); }

-(void) testSomething
{}

@end
</pre>
<p>&#8230;and here we get our familiar red bar! Our test case is complete and we now understand a little more about OCUnit. That&#8217;s it for today. Go on. Nothing else to see here. I know what you&#8217;re thinking. &#8220;We haven&#8217;t written or learned anything new!&#8221; Sure we have! We&#8217;ve written and validated our first test case in ObjC++. (I&#8217;m using OCUnit w/ C++ extensions to exercise or test drive C++ code.) The little amount we went over here is persistent through all the testing you will do from then on. It starts from the basic mechanics. Make sure every line of code is proceeded by some test (or compiler) failure. If you&#8217;ve done more than 2-3 things and haven&#8217;t run a build to generate a failure then you&#8217;re completely off track.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1087/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1087/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1087/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1087&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/12/01/you-must-fail-before-you-can-succeed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Hard to test things</title>
		<link>http://codeforfun.wordpress.com/2009/10/28/hard-to-test-things/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/28/hard-to-test-things/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 23:21:03 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1059</guid>
		<description><![CDATA[So I&#8217;d been thinking. Because I&#8217;m back into iPhone development and getting warmed up not only to ObjC issues and errors but also C++ oddities, I&#8217;m wondering how do you write tests for some of the more difficult things to capture? For instance, I&#8217;ve figured out how to capture some of the manual reference counting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1059&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So I&#8217;d been thinking. Because I&#8217;m back into iPhone development and getting warmed up not only to ObjC issues and errors but also C++ oddities, I&#8217;m wondering how do you write tests for some of the more difficult things to capture? For instance, I&#8217;ve figured out how to capture some of the manual reference counting that&#8217;s required by CocoaTouch. (I assert that objects passed into other objects are properly retained and properly released when the object itself is released.) Still I can&#8217;t capture the more involved memory management problems. How do you assert an autorelease? What about dynamic memory allocation with pointers? I ended up with a single method that dynamically allocates for a pointer via malloc. I then changed it to use new with array notation. </p>
<p>void MySpecialObject::writeRequestToStream(CFStringRef aRequest, CFWriteStreamRef requestStream)<br />
{<br />
  if(CFWriteStreamGetStatus(requestStream) == kCFStreamStatusNotOpen) CFWriteStreamOpen(requestStream);<br />
  UInt8* convertedString =(UInt8*)convertToCString(aRequest);<br />
  CFWriteStreamWrite(requestStream, convertedString, CFStringGetLength(aRequest));<br />
  free(convertedString);<br />
}</p>
<p>It&#8217;s used in one spot so far and I&#8217;ve manually added the free without a prior failing test. I felt dirty. Assuming there were no call to free, how would you write a failing test for the code above? Is this just one of those things where you have to be extra careful? Maybe I should investigate the use of Velocity style code macros/templates that expand after keying special abbreviation similar to what we have in IntelliJ. I can imagine something like &#8220;cstr&#8221; expanding to:</p>
<p>char *myCStr = new char[size];<br />
// use myCStr here<br />
free(myCStr);</p>
<p>With the ability to tab through highlighting the variable name, declared size and commented insert code section. Any bright ideas?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1059/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1059&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/28/hard-to-test-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>AssertRunsInAnotherThread ?</title>
		<link>http://codeforfun.wordpress.com/2009/10/13/assertrunsinanotherthread/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/13/assertrunsinanotherthread/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 01:55:39 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Objective C unit tests]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1038</guid>
		<description><![CDATA[**Update**
I&#8217;ve updated my example below after realizing I left out some important pieces&#8230;
**Update**
How do you assert that something runs in a different thread? Or more generically, how do you assert that something runs asynchronously? I need to do this in ObjC but also in Java. The scenario is as follows. I have a WhatzItz object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1038&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>**Update**</strong><br />
I&#8217;ve updated my example below after realizing I left out some important pieces&#8230;<br />
<strong>**Update**</strong></p>
<p>How do you assert that something runs in a different thread? Or more generically, how do you assert that something runs asynchronously? I need to do this in ObjC but also in Java. The scenario is as follows. I have a WhatzItz object instance stored in myWhatzItz. I tell myWhatzItz to doDisThing. I need to specify that myWhatzItz will doDisThing asynchronously. Experience tells the story that multi-threaded unit tests are dumb, complicated and wrong. So asking myWhatzItz to doDisThing then waiting or polling for completion of doDisThing is not what we want to do here. (It may be what you want to do but it&#8217;s not what I want. Since we&#8217;re on the same team and since I&#8217;m doing the writing you have to want what I want not what you want. I <em>want</em> you to want my wants&#8230; forget your wants&#8230; your wants are dumb anyhow!)</p>
<p>So how do we design myWhatzItz to doDisThing and doDisThing right? I&#8217;m going to suggest an interface&#8230; err prototcol. That is an abstraction for what we want to design. In unit testing we stay focused on one thing. All distractions are tossed behind abstractions. So after asking myWhatzItz to doDisThing I need to assert that it uses asynchronous behavior. That brings us a step back. I have to design a dependency on asynchronous behavior first. Right now you&#8217;re probably wondering how asynchronous behavior works. Right now I&#8217;m &#8217;bout to slap you like Bruce Lee slapped that boy in Enter the Dragon. (Or was that Return of the Dragon? Maybe it was the game of death? Bonus points to the 1st person that gets the movie correct with a link to the clip on YouTube!) &#8220;Don&#8217;t focus on the finger or you&#8217;ll miss the beauty in the sky above!&#8221;, says Bruce. We <em>don&#8217;t care</em> about how asynchronous behavior works, as its irrelevant to our design. We only care that our work is done asynchronously! So we&#8217;ll code this test in ObjectiveC:</p>
<pre class="brush: cpp;">
#import
@protocol MyAsynchronousBehavior
-(void) performAsynchronously:(SEL) aSelctor onTarget:(id)aTarget withObject:(id)anObject;
@end

@interface MyWhatzItzTest : SenTestCase &lt;MyAsynchronousBehavior&gt;
{
  MyWhatzItz *myWhatzItz;
  SEL selectorPerformed;
  id targetForSelector;
  id parameterForSelector;
  int performAsynchronouslyInvocationCount;
}
@end

@implementation MyWhatzItzTest

-(void) setUp
{
   myWhatzItz = [[MyWhatzItz alloc] init];
   //The test uses the self-shunt pattern to listen for MyAsynchronousBehavior interaction.
   id theAsynchronousBehavior = self;
   myWhatzItz.asynchronousBehavior = theAsynchronousBehavior;
}

-(void) testMyWhatzItzWillAsynchronouslyDoDisThingWhenAskedToDoDatThing
{
  STAssertEquals(performAsynchronouslyInvocationCount, 0, @&quot;Assuming that we haven't been asked to performAsynchronously&quot;);
  [myWhatzItz doDatThing];
  STAssertEquals(performAsynchronouslyInvocationCount, 1, @&quot;We SHOULD HAVE been asked to performAsynchronously&quot;);
  STAssertEquals(selectorPerformed, @selector(doDisThing:), @&quot;Should have asked to doDisThing using asynchronous behavior.&quot;);
  STAssertEquals(targetForSelector, myWhatzItz, @&quot;Should use myWhatzItz for asynchronous execution.&quot;);
}
@end
#pragma mark MyAsynchronousBehavior protocol methods
-(void) performAsynchronously:(SEL) aSelctor onTarget:(id)aTarget withObject:(id)anObject
{
  performAsynchronouslyInvocationCount++; selectorPerformed = aSelctor; targetForSelector = aTarget; parameterForSelector = anObject;
}
</pre>
<p>Supplying the asynchronous behavior becomes a construction/intialization concern, which could be extracted into a wiring framework like Interface Builder (or if you do Java, Springframework). The nice thing is that we can alternate our asynchronous behavior without touching the rest of the project. We can do something quick/dirty like detachThread&#8230; and later get more elegant with RunLoops. Today&#8217;s tip comes to you (me) completely by accident. I&#8217;ve been trying to test drive things in Java and ObjC for several years now and I&#8217;ve never got this part quite right. Feel free to share your opinions/experiences with threads and tests.</p>
<p><strong>**Update**</strong><br />
The above example demonstrates a few important unit testing concepts. first it uses the self-shunt pattern to allow the test to become a mock and listen for interactions between the tested object and its collaborator(s). Second, it demonstrates the importance of using tests to carve out the pieces that should NOT be under test. In this situation it&#8217;s multi-tasking, however in other scenarios it could be anything from a DBMS to a network call. I could have illustrated an example where I spin up a Thread pool of some sort from within the test started work, paused the main thread and waited for a response. That&#8217;s what I&#8217;ve done in the past and it becomes extremely complicated and brittle. In stead, I use the elegance of abstraction to make the test 100% predictable, 200% more simplistic, and 300% more maintainable. Where do I get those statistics? The short answer is they&#8217;re sequential. (The long story begins yesterday when my 5yr old spontaneously decided to count from 1 to infinity in the middle of our shopping trip. You see, she only recently learned her numbers up to 100 and after getting to 199 we all realized the child&#8217;s computational limits as she continued with one hundred one hundred then followed up with one hundred one hundred one, one hundred one hundred two&#8230;)<br />
<strong>**Update**</strong></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1038/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1038&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/13/assertrunsinanotherthread/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>RSpec 4 iPhone BDD?</title>
		<link>http://codeforfun.wordpress.com/2009/06/28/rspec-4-iphone-bdd/</link>
		<comments>http://codeforfun.wordpress.com/2009/06/28/rspec-4-iphone-bdd/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 02:01:41 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[iphone unit testing]]></category>
		<category><![CDATA[RSpec iPhone]]></category>
		<category><![CDATA[Ruby iPhone Testing]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=899</guid>
		<description><![CDATA[Is anybody doing this yet? I made an effort to use RSpec for iPhone development almost a year ago but got stumped on Ruby mock objects that didn&#8217;t seem to to play nice with CocoaTouch objects. I got a lot closer than my blog post would lead you to believe but stopped due to deadlines, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=899&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Is anybody doing this yet? <a href="http://codeforfun.wordpress.com/2008/11/10/rspec-for-iphone-development/">I made an effort</a> to use RSpec for iPhone development almost a year ago but got stumped on Ruby mock objects that didn&#8217;t seem to to play nice with CocoaTouch objects. I got a lot closer than my blog post would lead you to believe but stopped due to deadlines, and my lack of experience with both Ruby and ObjC. Tonight I dug up the old project and tried to remember where I left off&#8230;</p>
<p>&#8230;Aahh it&#8217;s al coming back to me now! I had wrapped the MockObject support in Ruby to ensure it received parameters from CocoaTouch. For some silly reason parameters passed directly from CocoaTouch objects are dropped/ignored by whatever mock framework Ruby is using with RSpec. Forgive me for not knowing more about the internals but I don&#8217;t do Ruby and this was from last November. Here&#8217;s an example of the RSpec I modified to allow parameters to pass cleanly. It also has the buddings of a dynamic message dispatch thingy I couldn&#8217;t get working because it makes no sense to hard code every anticipated method invocation. If one of you Ruby guys could jump in and patch this up or if somebody could point me to an already viable alternative that&#8217;d be so swell&#8230;</p>
<pre class="brush: cpp;">

require File.dirname(__FILE__) + '/test_helper'

require &quot;BowlingController.bundle&quot;
OSX::ns_import :BowlingController
OSX::ns_import :BowlingProtocol
require 'delegate'

include OSX

class ObjCMock
  attr_accessor :delegate
  def roll(num)
    @delegate.roll(num)
  end

  # def method_missing(m, *args)
  #   puts &quot;Forwarding message&quot;
  #   @delegate.send(m, args)
  # end

  def initialize(theMock)
    @delegate = theMock
  end
end

describe BowlingController do
  before(:each) do
    @controller = BowlingController.new
    @bowling = mock('BowlingProtocol')
    @bowling.stub!(:roll)
    @controller.bowling = ObjCMock.new(@bowling)
    @text_field = mock('Pins')
    @text_field.stub!(:intValue).and_return(10)
    @controller.pins = @text_field
  end

  it &quot;should roll a ball&quot; do
    @controller.roll
  end

  it &quot;should roll a ball and get the value from the pins outlet&quot; do
    @text_field.should_receive(:intValue).and_return(0)
    @controller.roll
  end

  it &quot;should be an OSX::NSObject&quot; do
    @controller.is_a?(OSX::NSObject).should == true
  end

  it &quot;should have an outlet to a bowling object&quot; do
    @controller.bowling = @bowling
  end

  it &quot;should send the pin value to the bowling object&quot; do
    #This line wraps the mock with the class defined above
    @controller.bowling = ObjCMock.new(@bowling)
    #The following line will cause failure calling directly into the mock
#    @controller.bowling = @bowling
    @bowling.should_receive(:roll).with(10)

    @controller.roll
  end

  it &quot;should have an outlet to the score&quot; do
    @score = mock('Score')
    @controller.score = @score
  end

end
</pre>
<pre class="brush: cpp;">
//
//  BowlingController.h
//  BowlingController
//
//  Created by FIXME on 2008-11-10.
//  Copyright 2008 FIXME. All rights reserved.
//

#import &quot;BowlingController.h&quot;
#import &quot;BowlingProtocol.h&quot;

@implementation BowlingController
@synthesize pins;
@synthesize bowling;
@synthesize score;

-(void) roll{
	int val = (int) [self.pins intValue];
	printf(&quot;Value is: %i&quot;, val);
	[self.bowling roll:val];
}

@end

// This initialization function gets called when we import the Ruby module.
// It doesn't need to do anything because the RubyCocoa bridge will do
// all the initialization work.
// The rbiphonetest test framework automatically generates bundles for
// each objective-c class containing the following line. These
// can be used by your tests.
void Init_BowlingController() { }
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/899/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=899&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/06/28/rspec-4-iphone-bdd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>TDD for iPhone development</title>
		<link>http://codeforfun.wordpress.com/2009/01/09/tdd-for-iphone-development/</link>
		<comments>http://codeforfun.wordpress.com/2009/01/09/tdd-for-iphone-development/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 19:47:19 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=737</guid>
		<description><![CDATA[I&#8217;m getting more familiar with the tools and technology surrounding iPhone development but I still face challenges daily. Hi, my name&#8217;s Cliff. You&#8217;re here because a random Yahoo/Google search or cross-link from another site pulled you in by your chin hairs. (In the case of women reading you&#8217;re here because you&#8217;re trying to figure out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=737&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m getting more familiar with the tools and technology surrounding iPhone development but I still face challenges daily. Hi, my name&#8217;s <a href="http://codeforfun.wordpress.com/about/">Cliff</a>. You&#8217;re here because a random Yahoo/Google search or cross-link from another site pulled you in by your chin hairs. (In the case of women reading you&#8217;re here because you&#8217;re trying to figure out where you husband/significant other spends all of his spare time.) Bear with me as I try to make sense of the tedium involved in <a href="http://www.macworld.com/article/132003/xcode.html">XCode</a> unit testing.</p>
<p><strong>Not yer Daddy&#8217;s cup o&#8217; Java!</strong><br />
For score and several years of Java development has seasoned me similar to a rotisserie side of pork spinning slowly over an open hearth. As a flavored piece of pig, I&#8217;ve come to expect certain things&#8230; from my IDE&#8230; from advertised test tools&#8230; from any form of modern development. For one, I don&#8217;t expect a ton of over head associated with adding a new test. Consequently, copying the Google tools for mac files into each project that wants to be agile is becoming painful. I&#8217;ve also come to expect&#8230; no demand a certain ability to easily decouple. Running things in isolation is key to true unit tests, not requiring the stars to line up is crucial. I&#8217;ve also grown used to the CLASSPATH. For those that only deal in XCode, Ruby, or Cocoa the CLASSPATH is the bane of all Java development allowing one to easily gain and/or dismally lose runtime visibility of entire libraries of supporting logic. Today I&#8217;m having trouble getting Objective-C class implementations to be visible without individually adding them. While that&#8217;s not too bad I found a classpathy work-around while playing with another open source project a while ago. This other project was setup with individual modules which made me very happy since it smells of modular reuse. It&#8217;s main module contained all of the supporting logic and could be embedded or reused in any client application. Writing tests that exercised anything from the project became a simple matter of adding that main module as a dependency of the test target.</p>
<p><strong>My Dilemma</strong><br />
Because I started a project sans knowledge of how to properly decouple I have a bunch of classes tied to the default application build target in XCode. I tried to add this target&#8217;s output as a dependency of my test target as I did with the other project. Since the output is an executable application I believe it&#8217;s causing things not to work as expected. If you have any idea of a work-around that doesn&#8217;t involve adding each file loaded by the test to be manually added to both the application and the the test target then speak up.</p>
<p><strong>Retribution *Ahem* Reimbursement</strong><br />
I&#8217;ve asked people to do my work for me plenty times before and I&#8217;m not ashamed to do it again. As your reward for being a faithful reader of my blog and committing occasional insight to my struggles you can expect silent but honorable mention as I speak to others on behalf of your contribution. Followup posts on this site to highlight your involvement in any way will be edited, reworded, and/or deleted prior to clearing moderation. (In all reality, I sincerely appreciate all comments and feedback. I don&#8217;t actually steal credit unless you request that I do and at the end of the day we&#8217;re all working towards a common goal&#8230; Don&#8217;t take nothing you read here seriously&#8230; it&#8217;s just jokes!)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/737/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/737/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/737/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/737/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/737/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/737/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/737/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/737/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/737/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/737/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=737&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/01/09/tdd-for-iphone-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
	</channel>
</rss>