<?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/"
	>

<channel>
	<title>Dr Nic &#187; Objective-C</title>
	<atom:link href="http://drnicwilliams.com/category/osx/objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Sat, 12 Nov 2011 01:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Unit Testing iPhone apps with Ruby: rbiphonetest</title>
		<link>http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/</link>
		<comments>http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 19:26:02 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Iphone]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=287</guid>
		<description><![CDATA[Everything to love about Ruby: the concise, powerful language; the sexy testing frameworks; and finally, the people. Everything to love about Objective-C: hmmm; well&#8230;; and finally, its the only high-level language you can use to write iPhone apps. On iPhone 2.0, to arrive on the 11th of July, you cannot run RubyCocoa. But you can [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/06/01/validate-and-save-your-ruby-in-textmate-with-secret-rubinus-superpowers/' rel='bookmark' title='Permanent Link: Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers'>Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers</a> <small>In some TextMate bundles, if you save a file it...</small></li><li><a href='http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/' rel='bookmark' title='Permanent Link: Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;'>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</a> <small> Got a simple app you want to build? Allocate...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20080703-mqpqqhdk4e49x3yhhb8t2g9rjg.jpg" alt="rbiphonetest logo" style="float: right" /></p>
<p>Everything to love about <strong>Ruby</strong>: the concise, powerful language; the sexy testing frameworks; and finally, the people.</p>
<p>Everything to love about <strong>Objective-C</strong>: hmmm; well&#8230;; and finally, its the only high-level language you can use to write iPhone apps.</p>
<p>On iPhone 2.0, to arrive on the 11th of July, you cannot run RubyCocoa. But you can run it on your Mac, so let&#8217;s use it to unit test your Objective-C classes. This tutorial shows you how to get started using a new project <a href="http://github.com/drnic/rbiphonetest/">rbiphonetest</a> [<a href="http://github.com/drnic/rbiphonetest">GitHub</a> | <a href="http://drnic.lighthouseapp.com/projects/13763-rbiphonetest">Lighthouse</a> | <a href="http://groups.google.com/group/rbiphonetest">Google Group</a>]</p>
<p>If you followed some of my <a href="http://summize.com/search?q=iphoneruby">recent tweets</a>, this project was previously called &#8220;iphoneruby&#8221;. And alas, the screencast also calls it &#8220;iphoneruby&#8221; but that was a crap name. People thought it was a way to run Ruby on the iphone. I can&#8217;t do that yet. So, a far better name is &#8216;rbiphonetest&#8217;. [track on <a href="http://summize.com/search?q=rbiphonetest">summize</a>]</p>
<p>Even if you&#8217;ve never touched Objective-C, Cocoa, the iPhone SDK, nor RubyCocoa I recommend watching the video anyway. It should give you hope that if you make the transition to iPhone development you don&#8217;t have to go alone without Ruby: your trusty swiss army knife of language/libraries/tools.</p>
<p>The screencast is also available in <a href="http://drnicwilliams.com/wp-content/uploads/2008/06/rbiphonetest-introduction.mov">high-def video</a> (55Mb QuickTime)</p>
<p><object width="550" height="393"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=1262916&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=01AAEA&amp;fullscreen=1" /><embed src="http://www.vimeo.com/moogaloop.swf?clip_id=1262916&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=01AAEA&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="393"></embed></object><br /><a href="http://www.vimeo.com/1262916?pg=embed&amp;sec=1262916">Unit Testing iPhone apps using Ruby</a> from <a href="http://www.vimeo.com/user289979?pg=embed&amp;sec=1262916">Dr Nic</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1262916">Vimeo</a>.</p>
<h2 id="installation_and_usage">Installation and Usage</h2>
<p>To summarize the video, but change &#8216;iphoneruby&#8217; to &#8216;rbiphonetest&#8217;, you install the framework via RubyGems:</p>
<pre>sudo gem install rbiphonetest</pre>
<p>Then change to your project&#8217;s folder and install the test framework:</p>
<pre>rbiphonetest .</pre>
<p>Finally, for each generic, non-UIKit-framework-using class you want to test:</p>
<pre>script/generate model WidgetModel</pre>
<p>Then write your tests in <code>test/test_widget_model.rb</code></p>
<h2 id="supported_cocoa_iphone_frameworks">Supported Cocoa &amp; iPhone frameworks</h2>
<p>The mysterious, magical premise upon which rbiphonetest depends is possibly erroneous: that your Objective-C class can be compiled and tested against your OS X/Intel frameworks, and if your tests pass you assume you can then compile and include your class with the the iPhone/ARM frameworks.</p>
<p>I&#8217;m willing to go with this assumption until its proven dangerously flawed by some angry 20-year veteran of NextStep/Cocoa/iPhone. But really, how different could NSString be on the iPhone versus your Mac?</p>
<p>Fortunately there is one way to check for significant differences between your available Mac-based frameworks, such as Cocoa, and the iPhone-based frameworks, such as UIKit. We need to compare the framework names, header files and method signatures.</p>
<p>So for example, you cannot currently unit test any class that depends on/includes the UIKit framework. <em>Why?</em> It doesn&#8217;t exist on your Mac, so the Mac/Intel compiler cannot link it in. We&#8217;re compiling and running our tests with RubyCocoa, which itself is built against the Mac/Intel frameworks, not the iPhone frameworks. Hell, <a href="http://chopine.be/lrz/">Laurent</a> doesn&#8217;t even own an iPhone <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  [Laurent is the Apple-employee maintainer of <a href="http://rubycocoa.sourceforge.net/HomePage">RubyCocoa</a> and the newer <a href="http://trac.macosforge.org/projects/ruby/wiki/MacRuby">MacRuby</a>]</p>
<p>Similarly, its no use including/linking the Cocoa framework into your Objective-C class. <em>Why?</em> It doesn&#8217;t exist on the iPhone. It has its own UI frameworks, collectively called &#8216;UIKit&#8217;.</p>
<p>So for the moment we cannot test UI-related, iPhone-API-specific code. But we can test generic Objective-C. That&#8217;s better than a kick in the teeth. Surely. I mean, in the teeth&#8230; that&#8217;d friggin&#8217; hurt.</p>
<p>&#8220;Fair enough Dr Nic, so which frameworks <em>can</em> my code use and yet still unit test it with your oh-so-special test library thingy?&#8221; Keep your pants on, I&#8217;m getting there. [<a href="#keep-your-pants-on">ref</a>]</p>
<p>To the best of my ability, I&#8217;ve compared the two sets of frameworks and listed the available Frameworks that are available on both the iPhone and your Mac. There are about a dozen. The most important is called &#8216;Foundation&#8217;. It holds gold nuggets like &#8216;NSString&#8217;. </p>
<p>The list of <a href="http://github.com/drnic/rbiphonetest/wikis/platform-differences">platform differences</a> is on the wiki as a reference.</p>
<p>Note, this list doesn&#8217;t guarantee that any two framework classes &#8211; the iPhone and matching Mac framework &#8211; will behave the same. This list is compiled by finding the set of Frameworks with the same name on both platforms, e.g. Foundation.</p>
<p>Then it compares the set of public header files (Foundation.framework/Headers/*.h files) This comparison is by method signature. It pulls all lines from each header that start with + or &#8211; (+ is a class method and &#8211; is an instance method in Objective-C) and compares the two lists. If there is a single difference in the method signatures of the header files in the two platforms it is marked on the wiki page. You&#8217;ll need to look at the two header files yourself to see the differences. Some header files are ugly. C-based anything starts ugly and goes down from there, I think.</p>
<h2 id="python_testing_of_iphone_objective_c">Python testing of iPhone Objective-C?</h2>
<p>In the Python world there is PyObjC, a bridge-based twin to RubyCocoa. If you are a Python developer you could easily port this project to use PyObjC I would think. Ping me if you are attempting this and need any help.</p>
<h2 id="summary">Summary</h2>
<p>I think this project can give Ruby developers a happy place to work from as they write their Objective-C/iPhone code. You still need to wire up your UI views and controller classes manually, but if you push all the &#8220;oooh that code really needs some tests&#8221; classes away from the UI-dependent frameworks then you can hook it up to rbiphonetest and write your tests in Ruby.</p>
<p>Currently the generator creates test/unit test stubs. I personally then add the Shoulda gem into my test_helper.rb for my apps. If an rspec and/or test/spec developer can help with adding support to the generators I&#8217;m certain the large rspec user-base would be happy campers.</p>
<p>Similarly, someone might like to investigate using MacRuby to run the tests instead of RubyCocoa. Fast tests vs slow tests. You choose.</p>
<h3>What the?</h3>
<p>Sometimes I re-read what I&#8217;ve written and notice things that don&#8217;t seem to make sense, but are in my vocabulary nonetheless. Yep, the things you learn living in Australia.</p>
<p><strong id="keep-your-pants-on">&#8220;Keep your pants on&#8221;</strong> &#8211; this seems to imply that until I mentioned otherwise you were about to take your pants off. Hardly relevant at any stage during this article, we&#8217;d both agree. Most code-based blog articles are &#8220;pants on&#8221;. This phrase means &#8220;don&#8217;t get upset&#8221;. You can try to figure out how you go from &#8220;don&#8217;t get upset&#8221; to &#8220;keep your pants on&#8221;. I have no idea.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/06/01/validate-and-save-your-ruby-in-textmate-with-secret-rubinus-superpowers/' rel='bookmark' title='Permanent Link: Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers'>Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers</a> <small>In some TextMate bundles, if you save a file it...</small></li><li><a href='http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/' rel='bookmark' title='Permanent Link: Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;'>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</a> <small> Got a simple app you want to build? Allocate...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
<enclosure url="http://drnicwilliams.com/wp-content/uploads/2008/06/rbiphonetest-introduction.mov" length="60255710" type="video/quicktime" />
		</item>
	</channel>
</rss>

