<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/templates/default/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    
    <link href="http://www.elancla.org/feeds/atom10.xml" rel="self" title="dejalatele's personal blog" type="application/atom+xml" />
    <link href="http://dejalatele.com/"                        rel="alternate"    title="dejalatele's personal blog" type="text/html" />
    <link href="http://dejalatele.com/rss.php?version=2.0"     rel="alternate"    title="dejalatele's personal blog" type="application/rss+xml" />
    <title type="html">dejalatele's personal blog</title>
    <subtitle type="html">My little place on the web...</subtitle>
    <icon>http://dejalatele.com/templates/bulletproof_fork/img/s9y_banner_small.png</icon>
    <id>http://dejalatele.com/</id>
    <updated>2012-02-13T20:07:44Z</updated>
    <generator uri="http://www.s9y.org/" version="1.5.5">Serendipity 1.5.5 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://dejalatele.com/archives/12-Throw-catch-in-Ruby.html" rel="alternate" title="Throw catch in Ruby" />
        <author>
            <name>Antonio Diaz Ruiz</name>
                    </author>
    
        <published>2012-02-12T10:37:16Z</published>
        <updated>2012-02-13T20:07:44Z</updated>
        <wfw:comment>http://dejalatele.com/wfwcomment.php?cid=12</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://dejalatele.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=12</wfw:commentRss>
    
            <category scheme="http://dejalatele.com/categories/4-Ruby" label="Ruby" term="Ruby" />
    
        <id>http://dejalatele.com/archives/12-guid.html</id>
        <title type="html">Throw catch in Ruby</title>
        <content type="xhtml" xml:base="http://dejalatele.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                A few days ago I got stuck on the <em>throw/catch</em> concept in Ruby.  The <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html">description on the Ruby documentation</a> was not clear for me and I spend many hours trying to figure out how it works.  If you are on one of those days and get also stuck on these concepts I'm going to try to show you how works through <a href="http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-catch">this example included on the Ruby documentation</a>:<br />
<br />
<div class="code"><br />
def routine(n)<br />
    puts n<br />
    throw :done if n<= 0<br />
    routine(n-1)<br />
end<br />
<br />
catch (:done) do<br />
    routine(3)<br />
end<br />
</div><br />
<br />
The above code prints out a sequence of numbers in reverse order, stopping the sequence when it reaches the zero.  The way it stops the sequence is by the use of the throw statement.  Catch defines a block that is labeled ("<em>done</em>" in the above example) and that is executed until a <em>throw</em> is encountered. Usually this <em>throw</em> statement is determined by a condition, in our example is <em>"if n<= 0"</em>.  Then, if the condition is not true it finishes the block where the thow is included, but if the condition is true it jumps out to the end of the of the active <em>catch</em>.  In our example it finishes the script.<br />
<br />
We can't have a <em>throw</em> statement with no catch <em>block</em>.  Let's try the following variant<br />
<br />
<div class="code"><br />
def routine(n)<br />
    puts n<br />
    throw :done if n<= 0<br />
    routine(n-1)<br />
end<br />
<br />
routine(3)<br />
</div><br />
<br />
If you execute the code above you should see the following error<br />
<div class="code"><br />
`throw': uncaught throw :done (ArgumentError)<br />
</div><br />
because there is no active catch block, the <em>throw</em> was called but in the call stack there was not <em>catch</em> block labeled with a tag which matches the throw's tag (<em>done</em> in our example).<br />
<br />
We can include more than one <em>throw</em> statement, here is an example<br />
<br />
<div class="code"><br />
def routine(n)<br />
    puts n<br />
    throw :done unless n>2<br />
    throw :done if n>12<br />
    routine(n+1)<br />
end<br />
<br />
catch (:done) do<br />
    routine(3)<br />
end<br />
</div><br />
<br />
Finally, I recommend you to check this <a href="http://www.rorexperts.com/rescue-raise-vs-catch-throw-in-ruby-t2162.html">link</a> and this <a href="http://www.jacopretorius.net/2012/01/catch-and-throw-in-ruby.html">link</a> what were usefull for help me to understand this topic. 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://dejalatele.com/archives/7-Launching-the-iPhone-simulator-using-Apache-Ant.html" rel="alternate" title="Launching the iPhone simulator using Apache Ant" />
        <author>
            <name>Antonio Diaz Ruiz</name>
                    </author>
    
        <published>2012-01-29T20:01:00Z</published>
        <updated>2012-02-03T20:48:43Z</updated>
        <wfw:comment>http://dejalatele.com/wfwcomment.php?cid=7</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://dejalatele.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    
            <category scheme="http://dejalatele.com/categories/1-iOS" label="iOS" term="iOS" />
    
        <id>http://dejalatele.com/archives/7-guid.html</id>
        <title type="html">Launching the iPhone simulator using Apache Ant</title>
        <content type="xhtml" xml:base="http://dejalatele.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                Here's the XML of an <a href="http://ant.apache.org/">Apache Ant</a> buildfile that allows the execution of an iPhone application on the iPhone simulator.<br />
<br />
<div class="code"><br />
&lt;project name="my-iPhone-project"&gt;<br />
&lt;property name="xcodebuild" value="path_to_xcodebuilder_execuitable"/&gt;<br />
&lt;property name="sdk" value="5.1"/&gt;<br />
&lt;property name="build_path" value="/myhomepath/my_builds_folder"/&gt;<br />
&lt;property name="application_path" value="${build_path}/Applications/my_iOS_application.app/my_application" /&gt;<br />
&lt;property name="simulator_path" value="/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator" /&gt;<br />
<br />
&lt;target name="run" depends="install, simulator"/&gt;<br />
&lt;target name="build" depends="clean, make"/&gt;<br />
<br />
&lt;target name="clean"&gt;<br />
&lt;delete dir="build" failonerror="false"/&gt;<br />
&lt;xcodebuild target="my_application_target"&gt;<br />
&lt;arg value="clean"/&gt;<br />
&lt;/xcodebuild&gt;<br />
&lt;/target&gt;<br />
<br />
&lt;target name="make"&gt;<br />
&lt;xcodebuild target="my_application_target"&gt;<br />
&lt;arg value="build"/&gt;<br />
&lt;/xcodebuild&gt;<br />
&lt;/target&gt;<br />
<br />
&lt;target name="install" depends="build"&gt;<br />
&lt;xcodebuild target="my_application_target"&gt;<br />
&lt;arg value="install"/&gt;<br />
&lt;/xcodebuild&gt;<br />
&lt;/target&gt;<br />
<br />
&lt;target name="simulator"&gt;<br />
&lt;iphone_simulator/&gt;<br />
&lt;/target&gt;<br />
<br />
&lt;macrodef name="xcodebuild"&gt;<br />
&lt;attribute name="dir" default="/myhomepath/my_application_source_code_folder"/&gt;<br />
&lt;attribute name="builddir" default="${build_path}"/&gt;<br />
&lt;attribute name="failonerror" default="true"/&gt;<br />
&lt;attribute name="target"/&gt;<br />
&lt;attribute name="sdk" default="${sdk}"/&gt;<br />
&lt;attribute name="configuration" default="${configuration}"/&gt;<br />
&lt;element name="args" optional="true" implicit="true" /&gt;<br />
&lt;sequential&gt;<br />
&lt;exec executable="${xcodebuild}" dir="@{dir}" failonerror="@{failonerror}"  failifexecutionfails="@{failonerror}"&gt;<br />
&lt;arg value="-target"/&gt;<br />
&lt;arg value="@{target}"/&gt;<br />
&lt;arg value="-sdk"/&gt;<br />
&lt;arg value="@{sdk}"/&gt;<br />
&lt;arg value="-configuration"/&gt;<br />
&lt;arg value="@{configuration}"/&gt;<br />
&lt;arg value="SYMROOT=@{builddir}"/&gt;<br />
&lt;arg value="DSTROOT=@{builddir}"/&gt;<br />
&lt;args/&gt;<br />
&lt;/exec&gt;<br />
&lt;/sequential&gt;<br />
&lt;/macrodef&gt;<br />
<br />
&lt;macrodef name="iphone_simulator"&gt;<br />
&lt;attribute name="applicationpath" default="${application_path}"/&gt;<br />
&lt;sequential&gt;<br />
&lt;exec executable="${simulator_path}" spawn="true"&gt;<br />
&lt;arg value="-SimulateApplication"/&gt;<br />
&lt;arg value="@{applicationpath}"/&gt;<br />
&lt;arg value="&amp;"/&gt;<br />
&lt;/exec&gt;<br />
&lt;/sequential&gt;<br />
&lt;/macrodef&gt;<br />
&lt;/project&gt;<br />
<br />
</div><br />
<br />
What you should see when you save this build file and run Ant is <em>xcodebuilder</em> will start to clean, build and install our application, and when <em>xcodebuilder</em> will finish the iPhone simulater will start automatically to run our application.<br />
<br />
Some key points here are the following:<br />
- The xcodebuild property is the path to the xcodebuilder executable.<br />
- The sdk property should be the iOS version you want to run your application.<br />
- The build_path property is the path where <em>xcodebuilder</em> will build and install the application.  It could be any path.  Notice that this property is passed into the macro responsible of the <em>xcodebuilder</em> execution.<br />
- The application_path property is the path of the application inside the build path.  It should be similar to the example above because <em>xcodebuilder</em> installs the applications on folder called  <em>Applications</em>.<br />
- The simulator_path property is the path of the simulator executable.<br />
- You should specify the target of the application by the attribute <em>target</em> in all the <em>xcodebuilder</em> calls.  <strong>Don't confuse</strong> the application target with the Ant targets.<br />
- The macro <em>xcodebuild</em> contains the necessary code to call the <em>xcodebuilder</em> executable.  Pay attention to the first attribute <em>dir</em>, it is the path to the source code of your application.  Your can use the same attributes and arguments as in the example, but it is advisable to check man page of <em>xcodebuilder</em> for a better understanding of the meaning of each available arguments.  Be careful with the order of the arguments inside the <em>sequential</em> Ant container because it executes the nested tasks in sequence, so if you wrongly modify the order of the arguments, <em>xcodebuild</em> will not run.<br />
- Finally the <em>iphone_simulator</em> macro will run the simulator starting your application.  The last argument (the ampersand) is passed with the only purpose of execute the simulator in background.<br />
<br />
This build file can be used in various ways but the most useful could be the launch of automated tests.  
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://dejalatele.com/archives/3-Avoiding-crashes.html" rel="alternate" title="Avoiding crashes" />
        <author>
            <name>Antonio Diaz Ruiz</name>
                    </author>
    
        <published>2012-01-13T18:41:29Z</published>
        <updated>1970-01-01T00:00:00Z</updated>
        <wfw:comment>http://dejalatele.com/wfwcomment.php?cid=3</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://dejalatele.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=3</wfw:commentRss>
    
            <category scheme="http://dejalatele.com/categories/1-iOS" label="iOS" term="iOS" />
    
        <id>http://dejalatele.com/archives/3-guid.html</id>
        <title type="html">Avoiding crashes</title>
        <content type="xhtml" xml:base="http://dejalatele.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                When we doing test automation for iPhone or iPad using the <a href="http://code.google.com/p/uispec/">UISpec</a> framework we have to pay attention to the existence or not of the UI elements we interact with.  If we try to touch a button, fill in a text field or perform any kind of interaction with an element and the element doesn't exist the Test application will crash and will stop the execution of the rest of specs.  So, we have to check the existence of the element before try to interact with them.  We can avoid the crash setting expectations before interact with the element.  <br />
Let's imagine a screen with two buttons and we want to touch the second one, the UIquery code of the button is<br />
<br />
<div class="code"><br />
[[[app button] index:1] touch];<br />
</div><br />
<br />
If this code is not correct or the button is no present on the screen the application which run the tests will crash, but if we set the expectation before the interaction <br />
<br />
<div class="code"><br />
[expectThat([app button] index:1]) should:be(YES)];<br />
[[[app button] index:1] touch];<br />
</div><br />
<br />
as the expectation will not be satisfied the execution of this spec will finish at this point but it won't finish the execution of the whole test application.  It will continue with the next spec.<br />
<br />
A more elaborated implementation could be<br />
<br />
<div class="code"><br />
    BOOL existElement;<br />
<br />
    @try {<br />
        existElement = [[[[app button] index:1] should] exist];<br />
    }<br />
    @catch (NSException *exception) {<br />
        NSLog(@"EXCEPTION CAUSED BY: %@", [NSThread callStackSymbols]);<br />
    }<br />
    @finally {<br />
        [expectThat(existElement) should:be(YES)];<br />
    }<br />
</div> 
            </div>
        </content>
        
    </entry>

</feed>
