<?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>El blog de Carlos Ble</title>
	<atom:link href="http://www.carlosble.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.carlosble.com</link>
	<description>BrainStream.Write(Posts)</description>
	<lastBuildDate>Thu, 23 May 2013 13:15:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The best coding dojo ever</title>
		<link>http://www.carlosble.com/2013/05/the-best-coding-dojo-ever/</link>
		<comments>http://www.carlosble.com/2013/05/the-best-coding-dojo-ever/#comments</comments>
		<pubDate>Sat, 18 May 2013 00:52:06 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Clean code]]></category>
		<category><![CDATA[Retrospectivas]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1521</guid>
		<description><![CDATA[&#160; I've got goosebumps on my arms most of the day. And it doesn't happen very often. This is the most emotional coding dojo I've ever facilitated. It's been in Gran Canaria, at the Universidad de Las Palmas de Gran Canaria (EII ULPGC). The last day in college for some students, where many of them were [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><a href="https://pbs.twimg.com/media/BKelhi2CEAAVd0F.jpg:large" target="_blank"><br />
<img class="alignleft" style="margin: 5px;" title="coding dojo ULPGC" src="https://pbs.twimg.com/media/BKelhi2CEAAVd0F.jpg:large" alt="" width="344" height="278" /></a></p>
<p>I've got goosebumps on my arms most of the day. And it doesn't happen very often. This is the most emotional coding dojo I've ever facilitated. It's been in Gran Canaria, at the <strong>Universidad de Las Palmas de Gran Canaria (EII <a title="EII ULPGC" href="http://www.eii.ulpgc.es/" target="_blank">ULPGC</a>)</strong>.</p>
<p><strong>The last day in college</strong> for some students, where many of them were thinking of their uncertain near future. Asking for recommendations and expressing many doubts.</p>
<p>More than <strong>50 people</strong> coding together for more than 8 hours, in an incredible atmosphere.</p>
<p>&nbsp;</p>
<h3>How did we get here?</h3>
<p><span style="font-size: 13px; line-height: 19px;"><a href="http://www.carlosble.com/wp-content/uploads/2013-05-16-15.46.59.jpg" target="_blank"><img class="alignleft  wp-image-1522" style="margin: 5px;" title="coding dojo ULPGC" src="http://www.carlosble.com/wp-content/uploads/2013-05-16-15.46.59-300x225.jpg" alt="" width="300" height="225" /></a>There is only one book on TDD in Spanish so far. Published by my friends and me back in 2010, under the creative commons license. Creative commons is like a virus for this. One year ago a real master, <strong><a title="Jose Juan Hernandez" href="http://www.linkedin.com/pub/jose-juan-hernandez/10/b50/b80" target="_blank">Jose Juan Hernandez</a></strong> (@jjhernandez) decided the book was nice to teach his students how to write clean code. We didn't know each other. In fact I didn't know the book was being used at the University. Jose Juan has been <strong>coding since 1985</strong> and I do believe he is a software craftsman, now that I've seen him coding and teaching.<br />
A couple of months ago he contacted me  see if I could give a talk to his students, about TDD in <em>the real world</em>™ and the encounter was excellent. The coding dojo proposal came along right after that.</span></p>
<h3>Why has it been so good?</h3>
<div id="attachment_1527" class="wp-caption alignright" style="width: 310px"><a href="http://www.carlosble.com/wp-content/uploads/IMG_20130517_210041.jpg" target="_blank"><img class="wp-image-1527 " style="margin: 5px;" title="Guillermo Pascual &amp; Carlos Ble" src="http://www.carlosble.com/wp-content/uploads/IMG_20130517_210041-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">Guillermo and I</p></div>
<p><span style="font-size: 13px; line-height: 19px;">Several factors in here. Jose Juan has been teaching TDD, Refactoring, Patterns and Clean Code to his students t</span><span style="font-size: 13px; line-height: 19px;">he whole year. No only the practices but the values. This is the reason we believe he is a master, because his students have embraced and internalized his values and principles.</span></p>
<ol>
<li><span style="font-size: 13px; line-height: 19px;">So about 30% of the students were familiar with the techniques, and we asked them to </span><strong style="font-size: 13px; line-height: 19px;">pair up with those not exposed</strong><span style="font-size: 13px; line-height: 19px;"> to automated tests and example driven design before. And they explained everything to others with passion. </span></li>
<li><span style="font-size: 13px; line-height: 19px;">In a regular coding dojo the facilitator does not necessarily teach. Her goal is facilitating. In this case though, <strong>we've been teaching</strong> people, so it's been half of a training session. With direct feedback on their work, based on our experience.</span></li>
<li><span style="font-size: 13px; line-height: 19px;">We were <strong>3 guys</strong> facilitating: Guillermo Pascual (<a title="Guillermo Pascual" href="http://twitter.com/pasku1" target="_blank">@pasku1</a>), Jose Juan and me. And the sinergy it's been huge.</span></li>
<li><span style="font-size: 13px; line-height: 19px;">Everyone was absolutely <strong>willing to</strong> learn and share. Passionate people, warm and friendly.</span></li>
<li><span style="font-size: 13px; line-height: 19px;">It's been a total win-win event. We (facilitators) have felt very useful and appreciated, it's been<strong> fulfilling</strong>. Some people have discovered a new way of understanding their careers, and what "caring about code" means.</span></li>
<li><span style="font-size: 13px; line-height: 19px;">The retrospectives following every iteration were very participative, people were able to discuss among them.</span></li>
</ol>
<div><span style="font-size: 13px; line-height: 19px;"> </span></div>
<div></div>
<div id="attachment_1528" class="wp-caption alignleft" style="width: 157px"><a href="http://www.carlosble.com/wp-content/uploads/2013-05-16-20.20.55.jpg"><img class="wp-image-1528 " style="font-size: 13px; line-height: 19px; margin: 5px;" title="Jose Juan" src="http://www.carlosble.com/wp-content/uploads/2013-05-16-20.20.55-163x300.jpg" alt="" width="147" height="270" /></a><p class="wp-caption-text">Jose Juan</p></div>
<h3><span style="font-size: 1.17em; line-height: 19px;">What's next?</span></h3>
<ul>
<li style="text-align: left;">This is a milestone in the Canary Islands software development community, I can feel it. Something is changing...</li>
<li style="text-align: left;">Let's keep on practising together. The <a title="AgileCanarias community" href="https://groups.google.com/forum/#!forum/agile-canarias" target="_blank">AgileCanarias community</a> is growing and it's a good starting point  o meet new people and learn new stuff. The Tenerife group is kind of mature and stable now, let's do the same in Gran Canaria. And let's join the two groups for dojos and local conferences.</li>
<li style="text-align: left;">We have the <a title="AOS2013" href="http://aos2013.agile-spain.org/" target="_blank">Agile Open Space</a> this year in Tenerife. Join us, it's a great opportunity to discover more.</li>
<li style="text-align: left;">Now you know there are different ways of writing software. Keep on learning, it's a never ending path.</li>
<li style="text-align: left;">When is the next coding dojo, who will organize and facilitate it? <img src='http://www.carlosble.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ul>
<div>
<h3></h3>
<h3></h3>
<h3>I want to facilitate a dojo, what should I know?</h3>
<ul>
<li>Manage people's expectations. In general a coding dojo is not a training session. Be honest with participants and help beginners as much as you can. Otherwise they'll be scared, run away and take a wrong idea about what it is.</li>
<li>A dojo is a space for innovation, try different things all the time, you don't have to follow the manual on the go. Just use your imagination and empathy.</li>
<li>Ask someone experienced to facilitate it before doing it yourself, if possible.</li>
<li>There is an interesting new book on this by <a title="Emily Bache" href="http://twitter.com/emilybache" target="_blank">Emily Bache</a>: <a href="https://leanpub.com/codingdojohandbook">https://leanpub.com/codingdojohandbook</a> (haven't read it yet), foreword by <a title="Unclebob" href="http://twitter.com/unclebobmartin" target="_blank">Uncle Bob Martin</a>.</li>
<li>Check out this video by Emily Bache: <a title="Emily Bache on Coding dojos" href="http://www.youtube.com/watch?v=yao5XLJqogQ" target="_blank">http://www.youtube.com/watch?v=yao5XLJqogQ</a></li>
</ul>
</div>
<h3>Acknowledgments</h3>
<ul>
<li>Jose Juan and Guillermo Pascual.</li>
<li>All the participants, of course. Without them, there is nothing to do.</li>
<li><a title="Jorge Castellano" href="http://twitter.com/GoldenLion64" target="_blank">Jorge Castellano</a> for his pictures and video. <a title="Jorge Castellano" href="https://www.facebook.com/Jorgecastellanocastellano?fref=ts" target="_blank">Pictures will be uploaded soon here</a>. Jorge already uploaded some pictures to twitter. Just search for the hashtag <a title="dojoULPGC" href="https://twitter.com/search?q=dojoULPGC" target="_blank">#dojoULPGC</a></li>
<li><a title="Fran Santana" href="http://www.linkedin.com/pub/francisco-j-santana-p%C3%A9rez/27/502/120" target="_blank">Fran Santanta</a> for his support and organization. Fran brought journalists from local newspapers and TV, apart from the food and everything else.</li>
<li><a title="Mario Hernandez" href="http://www.linkedin.com/pub/mario-hern%C3%A1ndez/10/a96/7a9" target="_blank">Mario Hernandez Tejera</a> for his company, hospitality and sharing his interesting/wise thoughts.</li>
<li>All the colleagues who work with Jose Juan for his support and energy.</li>
<li><a title="Jm beas" href="http://twitter.com/jmbeas" target="_blank">JM Beas</a>, <a title="Xavi Gost" href="http://twitter.com/Xav1uzz" target="_blank">Xavi Gost</a> and other folks from Agile Spain, as they introduced me to coding dojos.</li>
</ul>
<p><a title="AgileCanarias thread" href="https://groups.google.com/forum/?fromgroups#!topic/agile-canarias/Mz4VAlpYI7s" target="_blank">This is the related thread in the AgileCanarias mailing list.</a></p>
<p><a href="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-ash3/941762_10200363067414073_227331065_n.jpg" target="blank"><img width="50%" height="50%" src="https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-ash3/941762_10200363067414073_227331065_n.jpg" alt="fotos de Jorge Castellano"></a><br />
<a href="https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-ash4/264493_10200363096494800_1031311650_n.jpg"><img src="https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-ash4/264493_10200363096494800_1031311650_n.jpg" alt="Guillermo Pascual y Carlos Ble" width="50%" height="50%"></a><br />
&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/05/the-best-coding-dojo-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming through VNC</title>
		<link>http://www.carlosble.com/2013/05/programming-through-vnc/</link>
		<comments>http://www.carlosble.com/2013/05/programming-through-vnc/#comments</comments>
		<pubDate>Wed, 01 May 2013 17:18:56 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1510</guid>
		<description><![CDATA[I connect to my desktop PC (which is very powerful) from my laptop (very old), when I feel like coding from the other room, the couch or the bed. Desktop is a Windows 7 machine, laptop is Ubuntu. I have installed TightVNC on the Windows machine and SSVNC (without any SSL) package on Ubuntu. Everything was fine [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_1511" class="wp-caption alignleft" style="width: 310px"><a href="http://www.carlosble.com/wp-content/uploads/vncconfig.jpg" target="_blank"><img class="size-medium wp-image-1511 " style="margin: 5px;" title="VNC config screenshot" src="http://www.carlosble.com/wp-content/uploads/vncconfig-300x230.jpg" alt="" width="300" height="230" /></a><p class="wp-caption-text">TightVNC settings</p></div>
<p>I connect to my desktop PC (which is very powerful) from my laptop (very old), when I feel like coding from the other room, the couch or the bed. Desktop is a Windows 7 machine, laptop is Ubuntu. I have installed <strong><a title="TightVNC" href="http://www.tightvnc.com/" target="_blank">TightVNC</a></strong> on the Windows machine and <a title="SSVNC" href="http://www.karlrunge.com/x11vnc/ssvnc.html" target="_blank">SSVNC</a> (without any SSL) package on Ubuntu. Everything was fine but still, the cursor was moving so slow through the source code.</p>
<p>The key is the <strong>"Screen pooling cycle"</strong> option on the TightVNC configuracion. It's default value is 1000 but changing it to 100, makes me feel like I am coding in my desktop PC.</p>
<p>This is obviously in my LAN, through the internet it's better to use Teamviewer or Chrome Remote Desktop. And if you can work only with a terminal, then SSH+ <a title="TMux" href="http://tmux.sourceforge.net/" target="_blank">Tmux</a> is the best choice.</p>
<p>Happy couch coding!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/05/programming-through-vnc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add the feature where you would like to find it</title>
		<link>http://www.carlosble.com/2013/04/add-the-feature-where-you-would-like-to-find-it/</link>
		<comments>http://www.carlosble.com/2013/04/add-the-feature-where-you-would-like-to-find-it/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 18:47:52 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Clean code]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1506</guid>
		<description><![CDATA[A new change or feature is about to be implemented. There are several places where it can fit in, and all of them seem to respect the Single Responsibility Principle. My tendency used to be adding the new feature where it was easier to place.  However now I consider other criterion. I ask myself this: [...]]]></description>
			<content:encoded><![CDATA[<p>A new change or feature is about to be implemented. There are several places where it can fit in, and all of them seem to respect the <a title="SRP" href="http://en.wikipedia.org/wiki/Single_responsibility_principle" target="_blank">Single Responsibility Principle</a>. My tendency used to be adding the new feature where it was easier to place.  However now I consider other criterion. I ask myself this: If I need to navigate through the code base a bunch of months later to read the feature implementation... where would I look at in the first place?</p>
<p><strong>Lesson: once you make sure your code is going to be SOLID, add the new feature in the place readers would expect to find it.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/04/add-the-feature-where-you-would-like-to-find-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What methods should Value Objects contain?</title>
		<link>http://www.carlosble.com/2013/04/what-methods-can-value-objects-contain/</link>
		<comments>http://www.carlosble.com/2013/04/what-methods-can-value-objects-contain/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 18:27:01 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Clean code]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1501</guid>
		<description><![CDATA[Value objects can contain methods. Otherwise they are just anemic models. Those methods prevent the feature envy code smell and ease refactoring. They manipulate object internals promoting cohesion and low coupling. But don't forget about the Open/Closed principle. If you add that method to the object, is the code still open to extension without modification? [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Value object" href="http://en.wikipedia.org/wiki/Value_object" target="_blank">Value objects</a> can contain methods. Otherwise they are just anemic models. Those methods prevent the feature envy code smell and ease refactoring. They manipulate object internals promoting cohesion and low coupling. But don't forget about the <a title="Open closed principle" href="http://en.wikipedia.org/wiki/Open/closed_principle" target="_blank">Open/Closed principle</a>. If you add that method to the object, is the code still open to extension without modification?</p>
<p>Imagine a value object encapsulating a collection. Now you need a method to sort the items in the collection. Should the "sort" method be part of the collection object? If is there a way to change the sorting algorithm without code modification, then the answer is yes. Otherwise the answer is no. Move the "sort" method to a specific class whose responsibility is sorting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/04/what-methods-can-value-objects-contain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What would you expect the code to do?</title>
		<link>http://www.carlosble.com/2013/04/what-would-you-expect-the-code-to-do/</link>
		<comments>http://www.carlosble.com/2013/04/what-would-you-expect-the-code-to-do/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 18:12:13 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Clean code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1497</guid>
		<description><![CDATA[Writing quality code is about satisfying the expectations of the reader. And the reader might be yourself a couple of months later. Let me tell you a mistake a made recently. I was test-driving a few classes and one collaborator was a stack. But I only needed the stack to give me the last two [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Writing quality code is about satisfying the expectations of the reader</strong>. And the reader might be yourself a couple of months later.</p>
<p>Let me tell you a mistake a made recently. I was test-driving a few classes and one collaborator was a stack. But I only needed the stack to give me the last two items pushed on top of it.  So I ended up with a function like this:</p>
<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> pop<span style="color: #66cc66;">&#40;</span>numberOfItems<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
   <span style="color: #009900; font-style: italic;">// ... some code dealing with border cases...</span>
   <span style="color: #009900; font-style: italic;">// and the happy path:</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #66cc66;">&#91;</span>items<span style="color: #66cc66;">&#91;</span>len <span style="color: #CC0000;">-1</span><span style="color: #66cc66;">&#93;</span>, items<span style="color: #66cc66;">&#91;</span>len <span style="color: #CC0000;">-2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>And everything went well. The stack was good enough for the object using it.<br />
After a few months I needed to use the stack again but I forgot about its internals. I was writing some tests for a new class also depending on a stack. As the stack was already tested, I stubbed out the "pop" method in the new test pretending it could give me the last 3 items on the stack. The unit tests passed and my new class was working fine with the stack. However, it didn't work into production. Lesson:<br />
<strong>Although TDD encourages you write only the smallest amount of code necessary to make the test pass, you should implement all the behavior a method is expected to have when someone reads its signature.</strong></p>
<p>In one way or another I was coupling the stack to the class using it. But <strong>APIs should always tell the truth</strong>. Classes and methods should do what their name say without the need to know how other artifacts consume them.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/04/what-would-you-expect-the-code-to-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Careful with JavaScript object literals</title>
		<link>http://www.carlosble.com/2013/04/careful-with-javascript-object-literals/</link>
		<comments>http://www.carlosble.com/2013/04/careful-with-javascript-object-literals/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 17:45:16 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1495</guid>
		<description><![CDATA[JavaScript object literals are very handy, they are just key-value pairs. Very convenient to implement dictionaries and also a very simple implementation of the Singleton pattern: var message = {sender: 'bob', body: 'hello'}; Duck typing is a technique I use very often as I test-drive my JavaScript code and object literals make it very easy. [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript object literals are very handy, they are just key-value pairs. Very convenient to implement dictionaries and also a very simple implementation of the Singleton pattern:</p>
<pre>var message = {sender: 'bob', body: 'hello'};</pre>
<p>Duck typing is a technique I use very often as I test-drive my JavaScript code and object literals make it very easy. But overusing them lead to several problems:</p>
<ul>
<li><a title="Feature Envy" href="http://c2.com/cgi/wiki?FeatureEnvySmell" target="_blank">Feature envy</a> code smell</li>
<li><a title="Anemic models" href="http://en.wikipedia.org/wiki/Anemic_domain_model" target="_blank">Anemic models</a></li>
<li>Refactoring difficulties</li>
</ul>
<p>I am no longer using object literals in my tests because when I need to add methods to those objects, I need to change too many tests. Also, exposing all those fields lead to feature envy rapidly, producing semantic coupling sooner or later. Although tests are written fast with object literals, I prefer to encapsulate the fields into business objects.</p>
<pre>&nbsp;
function Message(sender, body){
   this.sender = sender;
   this.body = body;
}
var message = new Message();
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/04/careful-with-javascript-object-literals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Push the &#8220;how&#8221; down: Cukeup! 2013</title>
		<link>http://www.carlosble.com/2013/04/push-the-how-down-cukeup-2013/</link>
		<comments>http://www.carlosble.com/2013/04/push-the-how-down-cukeup-2013/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 16:20:22 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1481</guid>
		<description><![CDATA[It's been my first time attending to an event at Skills Matter and it's been awesome Cukeup! is the annual conference about BDD and Cucumber. This was the third edition.  Let me share with you the ideas I listened yesterday. The ideas and sentences written in here are not necessarily what speakers said, this is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.carlosble.com/wp-content/uploads/2013-04-03-09.39.45.jpg" target="_blank"><img class="alignleft size-medium wp-image-1485" style="margin: 5px;" title="2013-04-03 09.39.45" src="http://www.carlosble.com/wp-content/uploads/2013-04-03-09.39.45-300x225.jpg" alt="" width="300" height="225" /></a>It's been my first time attending to an event at <a title="Skills Matter" href="http://skillsmatter.com/" target="_blank">Skills Matter</a> and it's been awesome <img src='http://www.carlosble.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p>Cukeup! is the annual conference about BDD and <a title="Cucumber" href="http://cukes.info/" target="_blank">Cucumber</a>. This was the third edition.  Let me share with you the ideas I listened yesterday. The ideas and sentences written in here are not necessarily what speakers said, this is just my understanding of them. You can now view the talks online from the <a title="Cukeup 2013 recorded sessions" href="http://skillsmatter.com/event/agile-testing/cukeup-2013" target="_blank">SkillsMatter site</a>.</p>
<p>- <strong>Keynote by <a title="Aslak" href="http://aslakhellesoy.com/" target="_blank">Aslak Hellesøy</a> - </strong>father of Cucumber and coauthor of the excellent <a title="The cucumber book" href="http://pragprog.com/book/hwcuc/the-cucumber-book" target="_blank">Cucumber book</a> (which I recommend) and <a title="Cucumber recipes" href="http://pragprog.com/book/dhwcr/cucumber-recipes" target="_blank">Cucumber Recipes</a> (brand new):<br />
<span style="font-size: 13px;">Aslak told us how the development of Cucumber is going and the new design ideas they are working on, together with a review of the many flavors Cucumber's got. I missed a reference to </span><a style="font-size: 13px;" title="SpecFlow" href="http://www.specflow.org" target="_blank">SpecFlow</a><span style="font-size: 13px;"> in the slides though, as it is one of the tools I use and I think </span><a style="font-size: 13px;" title="Gaspar" href="http://gasparnagy.com/" target="_blank">Gaspar Nagy</a><span style="font-size: 13px;"> is doing a great job (and he came to the conference by the way, which was nice). The thing I liked the most from this keynote was that he announced their new book recently published, </span><a style="font-size: 13px;" title="Cucumber recipes book" href="http://pragprog.com/book/dhwcr/cucumber-recipes" target="_blank">Cucumber Recipes</a><span style="font-size: 13px;">, which is now on top of my wishlist. And also the honest way he talked about the arc</span><span style="font-size: 13px;">hitecture redesign Cucumber needs and how are they approaching it. This is a good example of why architecture and design are so important.</span></p>
<p>- <strong>One-line step definitions with <a title="Matt Wynne" href="http://blog.mattwynne.net/" target="_blank">Matt Wynne</a></strong> - coauthor of the two books mentioned before:<br />
You can see the talk <a title="Matt on Vimeo, on-line step definitions" href="http://skillsmatter.com/podcast/agile-testing/why-your-step-definitions-should-be-one-liners-and-other-pro-tips" target="_blank">online here</a> (and so the others too). Having read his first book, the new ideas I got from this insightful talk was that the popular <strong>test pyramid can be "rotated"</strong>. Matt and <a title="Seb Rose on twitter" href="http://twitter.com/sebrose" target="_blank">Seb Rose</a> came across this idea together. Basically, you can use Cucumber to describe features without the need to access the application end to end, just exercising low level classes and methods from the step definitions. In those cases Seb decorates the features with tags indicating the level of abstraction they belong in (<em>@without_ui</em> for example). If you haven't read Matt's book, this talk is a good summary of some parts, it features some of the most important <strong>values and principles</strong>. Remarkable ideas:<br />
Push the "how" down because it changes often and because it will not bring people into BDD as the features written in the imperative way are hard to understand and boring, cluttered with irrelevant information. Sometimes <strong>imperative</strong> style is the result of ignorance but it can also spot<strong> lack of trust</strong> in the team.  And... don't nest steps (call another step from the step definition).</p>
<p>- <strong>Working in the Cucumber World with <a title="Andrew Premdas" href="http://pages.andrew.premdas.org/" target="_blank">Andrew Premdas</a>:</strong><br />
<span style="font-size: 13px;">Andrew's advise is to benefit from both, natural and programming languages when we write features and their step definitions. In order to do that, the "World" (fixtures used within step definitions) must be <strong>expressive, self-descriptive</strong>. </span><span style="font-size: 13px;">Although </span><strong style="font-size: 13px;">he discouraged us from using global variables</strong><span style="font-size: 13px;">, there are some exceptions, something useful when referring to oneself in the fixtures is to use the variable "I" (@I in Ruby). Enrique Comba also suggested using @narrator (@ comes from Ruby) as the variable used to refer to the person telling the story. Because "narrator" might be clearer than "I" when there are many steps. </span><span style="font-size: 13px;">Andrew said it was his first talk and he did very well in my opinion because clearly his primary concern was to communicate, so the message came out effectively.</span></p>
<p>- <strong>Don't you trust me? with <a title="Seb Rose" href="http://claysnow.co.uk/" target="_blank">Seb Rose</a>:</strong><br />
<span style="font-size: 13px;">Trust is easier to loose than to win. When developers tell testers that everything is fine but then it breaks, they are loosing points. Same when developers don't allow testers to navigate through the code base. Testers can work more effectively if they know a bit of programming and are able to check out the source code for inspection. When team members trust each other they clean up the road for others. Documenting high level architecture and components also helps.<br />
</span><span style="font-size: 13px;">Then he explained an experiment he is trying out: end to end tests are good to win trust so he starts by </span><span style="font-size: 13px;">exercising the application like that from the features. But after that, he </span><span style="font-size: 13px;">considers whether end to end is really the right way to go, because maybe exercising low level methods rather than several layers is cheaper, as long as there are already other end to end tests covering the path. Again, the rotated pyramid.</span></p>
<p>- <strong>The Impersonator Pattern with <a title="Enrique Comba" href="http://www.ecomba.org/" target="_blank">Enrique Comba</a></strong>:<br />
<span style="font-size: 13px;">Enrique got many of us thinking how to leverage the pattern right after his talk. He explained it on his blog time ago. A very nice secondary effect of this pattern, is that one can rapidly review the implementation of the impersonators and get a summary of <strong>what every persona in the project can do and what can't do</strong>. Useful documentation to have, specially when you have hundreds of features and thousands of steps. It was definitely a great talk, source of inspiration. </span><span style="font-size: 13px;">His craftsman spirit lead him to this pattern as the consequence of </span><span style="font-size: 13px;">following the "<strong>maximize code clarity</strong>" principle.</span></p>
<p><strong>- Hands-on Cucumber.js with <a title="Julien" href="https://twitter.com/jbpros" target="_blank">Julien Biezemans</a> and Matt Wynne:</strong><br />
Julien, the creator or Cucumber's JavaScript flavor was pairing up with Matt to test-drive a little game live, writing the code directly in the browser with particular web environment set up by him. I am already using Cucumber.js so nothing new about that but I didn't know about <a title="uitest.js" href="https://github.com/tigbro/uitest.js" target="_blank">uitest.js</a> which they were using during the session. I am actually doing something similar on my own with Jasmine to run the app within an iframe so is good to know that more people are doing that. Some other times I just run cucumber.js from the command line using zombie.js.</p>
<p><strong> - Cross-platform BDD for Mobile with <a title="Karl" href="http://blog.higher-order.net/" target="_blank">Karl Krukow</a>:</strong><br />
Karl showed <a title="Calabash" href="http://calaba.sh/" target="_blank">Calabash</a>, a very powerful framework for mobile testing. Really impressive to me. It fits perfectly with hexagonal architecture and helps to avoid duplication in the tests while testing native apps on different mobiles platforms. It's really worth having a look at Calabash. I'll definitely will do. Of course the integration with Cucumber is excellent.</p>
<p><strong>- Testing web apps with Cucumber.js with <a title="Paul Jensen" href="https://twitter.com/paulbjensen" target="_blank">Paul Jensen</a>:</strong><br />
Good speaker, nice technical stack and good ideas from the talk. He showed code from his successful app <a title="Dashku" href="https://dashku.com/" target="_blank">Dashku</a> and its tests. I must say that the way I write JavaScript apps is different specially because I test-drive them whereas he showed a prototype developed without tests, having them added afterwards. But still, some good points in the talk.</p>
<p>Now I'll watch all the sessions that I couldn't attend to (haven't found the way to split myself in two).<span style="font-size: 13px;"> </span></p>
<p>See you next year hopefully!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/04/push-the-how-down-cukeup-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit testing JavaScript with Promises and Jasmine</title>
		<link>http://www.carlosble.com/2013/03/unit-testing-javascript-with-promises-and-jasmine/</link>
		<comments>http://www.carlosble.com/2013/03/unit-testing-javascript-with-promises-and-jasmine/#comments</comments>
		<pubDate>Fri, 22 Mar 2013 19:05:34 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1470</guid>
		<description><![CDATA[Promises are a nice solution to write readable asynchronous code in JavaScript. If you understand Spanish, I highly recommend this great talk on Promises by Enrique Amodeo. But, is the code with promises easy to unit test? It's not very difficult, you have to take into account the calls are asynchronous even if the production [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Promises commonjs" href="http://wiki.commonjs.org/wiki/Promises/A" target="_blank">Promises</a> are a nice solution to write readable asynchronous code in JavaScript. If you understand Spanish, I highly recommend <a title="Enrique Amodeo hablando de Promesas" href="http://vimeo.com/60734992" target="_blank">this great talk</a> on Promises by <a title="Enrique Amodeo Blog" href="http://eamodeorubio.wordpress.com/" target="_blank">Enrique Amodeo</a>.</p>
<p>But, is the code with promises easy to unit test? It's not very difficult, you have to take into account the calls are asynchronous even if the production code executes instantly.</p>
<p>Here is some code I've written using <a title="when.js" href="https://github.com/cujojs/when" target="_blank">when.js library</a>:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> TicketSalesService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> self = <span style="color: #000066; font-weight: bold;">this</span>;
  <span style="color: #009900; font-style: italic;">// ... some other code over here...</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">buyTickets</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>quantity<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
     purchaseOrder.<span style="color: #006600;">quantity</span> = quantity;
     <span style="color: #009900; font-style: italic;">// THIS IS THE CODE WITH PROMISES:</span>
     <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">server</span>.<span style="color: #006600;">isUserRegistered</span><span style="color: #66cc66;">&#40;</span>user<span style="color: #66cc66;">&#41;</span>
       .<span style="color: #006600;">then</span><span style="color: #66cc66;">&#40;</span>tryToBuyTickets<span style="color: #66cc66;">&#41;</span>
       .<span style="color: #006600;">then</span><span style="color: #66cc66;">&#40;</span>informSubscribersAboutPurchaseResult<span style="color: #66cc66;">&#41;</span>
       .<span style="color: #006600;">otherwise</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>err<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
           helpers.<span style="color: #006600;">registerPromiseError</span><span style="color: #66cc66;">&#40;</span>self, err<span style="color: #66cc66;">&#41;</span>;
       <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>;
   <span style="color: #003366; font-weight: bold;">var</span> tryToBuyTickets = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>response<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
       <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!response.<span style="color: #006600;">registered</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          self.<span style="color: #006600;">onRegistrationRequired</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">// trigger event</span>
          <span style="color: #000066; font-weight: bold;">throw</span> helpers.<span style="color: #006600;">endOfPromiseChain</span>; <span style="color: #009900; font-style: italic;">// stop the chain</span>
       <span style="color: #66cc66;">&#125;</span>
       <span style="color: #000066; font-weight: bold;">return</span> self.<span style="color: #006600;">server</span>.<span style="color: #006600;">buyTickets</span><span style="color: #66cc66;">&#40;</span>purchaseOrder<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>;
   <span style="color: #003366; font-weight: bold;">var</span> informSubscribersAboutPurchaseResult = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>response<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>response.<span style="color: #006600;">success</span><span style="color: #66cc66;">&#41;</span>
            self.<span style="color: #006600;">onPurchaseSuccess</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">else</span>
            self.<span style="color: #006600;">onPurchaseFailure</span><span style="color: #66cc66;">&#40;</span>response.<span style="color: #006600;">message</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>;
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">onRegistrationRequired</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #009900; font-style: italic;">/* event */</span><span style="color: #66cc66;">&#125;</span>;
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">onPurchaseSuccess</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #009900; font-style: italic;">/* event */</span><span style="color: #66cc66;">&#125;</span>;
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">onPurchaseFailure</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #009900; font-style: italic;">/* event */</span><span style="color: #66cc66;">&#125;</span>;
  <span style="color: #009900; font-style: italic;">// ... some other code over here....</span>
<span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>In this code there is a helper namespace providing a function and a constant:</p>
<pre class="javascript">&nbsp;
helpers.<span style="color: #006600;">endOfPromiseChain</span>; <span style="color: #009900; font-style: italic;">// this is just a constant, a string.</span>
<span style="color: #009900; font-style: italic;">// And this is a function to ease testing:</span>
helpers.<span style="color: #006600;">registerPromiseError</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>target, err<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>err != helpers.<span style="color: #006600;">endOfPromiseChain</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
            target.<span style="color: #006600;">errorInPromise</span> = err.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>The "server" dependency in the TicketSalesService is just a jQuery ajax wrapper. There is a rule in TDD that says, <strong>"do not mock artifacts you don't own"</strong>. What I do is wrap up jQuery.ajax so that I can easily stub out the server response and also change jQuery for other library if I needed to.</p>
<pre class="javascript">&nbsp;
Service.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">isUserRegistered</span> = <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span>user<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> deferred = when.<span style="color: #006600;">defer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #009900; font-style: italic;">// wrapping jQuery aja:</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">requestData</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;theUrl/goes/over/here&quot;</span>,
	<span style="color: #66cc66;">&#123;</span> data: user <span style="color: #66cc66;">&#125;</span>,
	<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #009900; font-style: italic;">// jQuery.ajax success invokes this</span>
	  deferred.<span style="color: #006600;">resolve</span><span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #009900; font-style: italic;">// TODO. call deferred.reject(); on error</span>
    <span style="color: #000066; font-weight: bold;">return</span> deferred.<span style="color: #006600;">promise</span>;
<span style="color: #66cc66;">&#125;</span>;
&nbsp;</pre>
<p>What about the tests? I am using Jasmine as the testing framework. I test-drove the code above and these are the resulting tests:</p>
<pre class="javascript">&nbsp;
it<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;triggers event when server responds that the user is not registered&quot;</span>,
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    stubServerResponse<span style="color: #66cc66;">&#40;</span>salesService.<span style="color: #006600;">server</span>, <span style="color: #66cc66;">&#123;</span> registered: <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> promiseSpy = spyReturningPromise<span style="color: #66cc66;">&#40;</span>salesService,
                            <span style="color: #3366CC;">&quot;onRegistrationRequired&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    salesService.<span style="color: #006600;">buyTickets</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    assertAsyncExpects<span style="color: #66cc66;">&#40;</span>promiseSpy, salesService<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
it<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;tries to buy when server responds that the user is registered&quot;</span>,
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    stubServerResponse<span style="color: #66cc66;">&#40;</span>salesService.<span style="color: #006600;">server</span>, <span style="color: #66cc66;">&#123;</span> registered: <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> promiseSpy = spyReturningPromise<span style="color: #66cc66;">&#40;</span>salesService.<span style="color: #006600;">server</span>,
                                              <span style="color: #3366CC;">&quot;buyTickets&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    salesService.<span style="color: #006600;">buyTickets</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    assertAsyncExpects<span style="color: #66cc66;">&#40;</span>promiseSpy, salesService<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
it<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;triggers event when tickets are purchased&quot;</span>,
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
   stubServerResponse<span style="color: #66cc66;">&#40;</span>salesService.<span style="color: #006600;">server</span>,
                 <span style="color: #66cc66;">&#123;</span>success: <span style="color: #003366; font-weight: bold;">true</span>, registered: <span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #003366; font-weight: bold;">var</span> promiseSpy = spyReturningPromise<span style="color: #66cc66;">&#40;</span>salesService,
                               <span style="color: #3366CC;">&quot;onPurchaseSuccess&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
   salesService.<span style="color: #006600;">buyTickets</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
   assertAsyncExpects<span style="color: #66cc66;">&#40;</span>promiseSpy, salesService<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
it<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;triggers event when prescriptions could not be purchased&quot;</span>,
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    stubServerResponse<span style="color: #66cc66;">&#40;</span>salesService.<span style="color: #006600;">server</span>,
           <span style="color: #66cc66;">&#123;</span>success: <span style="color: #003366; font-weight: bold;">false</span>, registered: <span style="color: #003366; font-weight: bold;">true</span>, message: <span style="color: #3366CC;">'fatal'</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> promiseSpy = spyReturningPromise<span style="color: #66cc66;">&#40;</span>salesService,
                                <span style="color: #3366CC;">&quot;onPurchaseFailure&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    salesService.<span style="color: #006600;">buyTickets</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    assertAsyncExpects<span style="color: #66cc66;">&#40;</span>promiseSpy, salesService<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>My code is using DOM Level 0 event handling. You can read more about event driven design <a href="http://www.carlosble.com/2013/02/event-oriented-programming-with-javascript/" title="Event Oriented programming with JavaScript" target="_blank">in this former post</a>.<br />
The tests are very clean if you are familiar with Jasmine spies.<br />
The method "stubServerResponse" replaces the function "requestData" in my "server" object to simulate data coming from the server.<br />
The other helpers are here:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> assertAsyncExpects =
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>promiseSpy, target, additionalExpectation<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  waitsFor<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> promiseSpy.<span style="color: #006600;">called</span> ||
       target.<span style="color: #006600;">errorInPromise</span>; <span style="color: #66cc66;">&#125;</span>, <span style="color: #CC0000;">50</span>
  <span style="color: #66cc66;">&#41;</span>;
  runs<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #009900; font-style: italic;">// this tells me if there was any unhandled exception:</span>
      expect<span style="color: #66cc66;">&#40;</span>target.<span style="color: #006600;">errorInPromise</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">not</span>.<span style="color: #006600;">toBeDefined</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #009900; font-style: italic;">// this asks the spy if everything was as expected:</span>
      expect<span style="color: #66cc66;">&#40;</span>promiseSpy.<span style="color: #006600;">target</span><span style="color: #66cc66;">&#91;</span>promiseSpy.<span style="color: #006600;">methodName</span><span style="color: #66cc66;">&#93;</span>
           <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toHaveBeenCalled</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #009900; font-style: italic;">// optional expectations:</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>additionalExpectation<span style="color: #66cc66;">&#41;</span>
            additionalExpectation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> spyReturningPromise =
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>target, methodName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> spyObj = <span style="color: #66cc66;">&#123;</span>called: <span style="color: #003366; font-weight: bold;">false</span>,
                  target: target,
                  methodName: methodName<span style="color: #66cc66;">&#125;</span>;
    spyOn<span style="color: #66cc66;">&#40;</span>target, methodName<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">andCallFake</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        spyObj.<span style="color: #006600;">called</span> = <span style="color: #003366; font-weight: bold;">true</span>;
        <span style="color: #000066; font-weight: bold;">return</span> when.<span style="color: #006600;">defer</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">promise</span>;
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000066; font-weight: bold;">return</span> spyObj;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>These two are basically wrappers around Jasmine to remove noise from my tests. The funcionts "waitsFor", "runs" and "spyOn", belong to Jasmine. The first two deal with asynchronous execution whereas the third one creates a test double, a spy object.</p>
<h4>What are the tricky parts?</h4>
<p>When there is an exception inside the <em>"then"</em> or  <em>"otherwise"</em> functions, it is captured by the promise and the test doesn't know anything about it. So when the test fails, it might not be for an obvious reason, and I want my unit tests to tell me where the problem is very fast. So I create a property in the object containing the "then" methods, called "errorInPromise" that I can check later in my tests. I add the "otherwise" handler at the end of the "then" blocks to ensure any exception thrown within them is captured and can be read in the tests.  </p>
<p>What do you do to unit test your "promising code"?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/03/unit-testing-javascript-with-promises-and-jasmine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Segunda edición del PMA</title>
		<link>http://www.carlosble.com/2013/03/segunda-edicion-del-pma/</link>
		<comments>http://www.carlosble.com/2013/03/segunda-edicion-del-pma/#comments</comments>
		<pubDate>Sun, 17 Mar 2013 22:42:52 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1461</guid>
		<description><![CDATA[Acabo de regresar de impartir mi clase sobre Clean Code y TDD en el Postgrado de Métodos Ágiles de La Salle (#PMA), en Barcelona. Se trata de la segunda edición de este postgrado único en el mundo. La experiencia ha sido muy positiva e intensa al igual que lo fue el año pasado. Los participantes son [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_1462" class="wp-caption alignleft" style="width: 160px"><a href="http://www.carlosble.com/wp-content/uploads/pma2012.jpg" target="_blank"><img class=" wp-image-1462" style="margin: 5px;" title="Foto de grupo PMA 2012-2013" src="http://www.carlosble.com/wp-content/uploads/pma2012-150x150.jpg" alt="" width="150" height="150" /></a><p class="wp-caption-text">Foto de grupo</p></div>
<p>Acabo de regresar de impartir mi clase sobre Clean Code y TDD en el <a title="PMA La Salle" href="http://www.proyectosagiles.org/postgrado-metodos-agiles-segunda-edicion" target="_blank">Postgrado de Métodos Ágiles de La Salle</a> (#PMA), en Barcelona. Se trata de la segunda edición de este postgrado único en el mundo.</p>
<p>La<strong> experiencia ha sido muy positiva</strong> e intensa al igual que lo fue el año pasado. Los participantes son profesionales del sector con un interés enorme en el postgrado así que funciona de maravilla.</p>
<div id="attachment_1463" class="wp-caption alignright" style="width: 160px"><a href="http://www.carlosble.com/wp-content/uploads/pma2012_2.jpg" target="_blank"><img class=" wp-image-1463" style="margin: 5px;" title="PMA2012" src="http://www.carlosble.com/wp-content/uploads/pma2012_2-150x150.jpg" alt="" width="150" height="150" /></a><p class="wp-caption-text">Nuestro primer test en verde</p></div>
<p>Si viviese en Barcelona o en algún punto cercano, sin duda me inscribiría como alumno para la siguiente edición del postgrado por la increible <strong>selección de profesores con que cuenta</strong>. El temario toca absolutamente todos los puntos clave de las metodologías ágiles, desde las personas hasta el código.</p>
<p>Este año había varios gestores de proyecto y tambien DevOps entre los asistentes. Llevaban muchos años sin programar y a pesar de ello han puesto muchas ganas para aprender en este módulo en que hablamos sobre todo de código. <strong>De cómo escribir código para las personas</strong>, no para las máquinas. Poder hablar del cuidado con el que hay que programar, a personas que están en la gestión de proyectos, es motivador para mi porque pueden valorar mejor el trabajo que hace el equipo de desarrollo (y también las chapuzas que pueden llegar a hacer). Para mí es una oportunidad de dar a conocer <strong>lo importante que es la carrera técnica</strong> y la forma de programar y de mantener el código. En nuestro país los roles de desarrollador y tester están peor valorados que los roles no-técnicos, al menos en cuanto a salarios, por lo que los buenos programadores acaban por desaparecer al "promocionar" a puestos de gestión.</p>
<p>El postgrado proporciona una<strong> visión integral</strong> muy importante para impulsar el cambio hacia la calidad que necesitamos en estos momentos.</p>
<p>A continuación listo la bibliografía y demás recursos que comenté en clase:</p>
<ul>
<li>Libro: <a title="Diseño Agil con TDD" href="http://dirigidoPorTests.com/el-libro" target="_blank">Diseño Agil con TDD</a> (el único en español)</li>
<li>Libro: <a title="Bridging the communication gap by Gojko Adzic" href="http://www.acceptancetesting.info/the-book/" target="_blank">Bridging the communication gap</a> (introduccion a specificaton by example)</li>
<li>Libro: <a title="Specification By Example by Gojko Adzic" href="http://specificationbyexample.com/" target="_blank">Specification by example</a> (clave para BDD)</li>
<li>Libro: <a title="Clean Code" href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" target="_blank">Clean Code</a> (imprescindible)</li>
<li>Libro: <a title="Effective Unit Testing by Lasse Koskela" href="http://manning.com/koskela2/" target="_blank">Effective Unit Testing</a> (sobre cómo escribir buenos unit tests)</li>
<li>Libro: <a title="Test Driven by Lasse Koskela" href="http://manning.com/koskela" target="_blank">Test Driven</a> (uno de los mejores en ingles)</li>
<li>Videos: Clean Coders. <a title="Clean Coders, E1, subtitulado" href="http://www.carlosble.com/2012/06/clean-coders-e1-subtitulado/" target="_blank">El episodio 1, tiene subtitulos en español</a></li>
</ul>
<p>Ha sido un placer, volveremos a vernos en el futuro <img src='http://www.carlosble.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Gracias a <a title="Cesar Villar en twitter" href="http://twitter.com/cmvillar" target="_blank">César Villar</a> y <a title="Oriol" href="http://about.me/orioldelbarrio" target="_blank">Oriol del Barrio</a> por las fotos.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/03/segunda-edicion-del-pma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Charla sobre agilidad, testing y TDD en la ULPG</title>
		<link>http://www.carlosble.com/2013/03/charla-sobre-agilidad-testing-y-tdd-en-la-ulpg/</link>
		<comments>http://www.carlosble.com/2013/03/charla-sobre-agilidad-testing-y-tdd-en-la-ulpg/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 10:56:11 +0000</pubDate>
		<dc:creator>Carlos Ble</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://www.carlosble.com/?p=1457</guid>
		<description><![CDATA[Gracias a Jose Juan Hernández, profesor de ingeniería del software de la Escuela de Informática de la Universidad de Las Palmas de Gran Canaria, ayer 12 de marzo pudimos grabar la primera video conferencia con su clase. Hablamos de métodos ágiles, de testing y de TDD. Tuve algunos problemas técnicos y no se si la [...]]]></description>
			<content:encoded><![CDATA[<p>Gracias a <a href="http://www.dis.ulpgc.es/profesorado/ficha.asp?id=28" title="Jose Juan Hernández" target="_blank">Jose Juan Hernández</a>, profesor de ingeniería del software de la Escuela de Informática de la Universidad de Las Palmas de Gran Canaria, ayer 12 de marzo pudimos grabar la primera video conferencia con su clase. Hablamos de métodos ágiles, de testing y de TDD.</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/PAcdHxR-gTY?feature=player_detailpage" frameborder="0" allowfullscreen></iframe></p>
<p>Tuve algunos problemas técnicos y no se si la parte de preguntas se grabó también. Pero seguramente no será la ultima colaboración porque ha sido muy enriquecedora para mí.</p>
<p>Muchas gracias a Jose Juan por hacerlo posible y a sus alumnos por el gran interes mostrado durante la sesión.<br />
Esta es la primera noticia que tengo de que <a href="http://www.dirigidoPorTests.com/el-libro" title="El libro de TDD" target="_blank">nuestro libro de TDD</a> se esté usando como material docente en la Universidad. Es una gran noticia y me anima a publicar una nueva version mejorada.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.carlosble.com/2013/03/charla-sobre-agilidad-testing-y-tdd-en-la-ulpg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
