<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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" version="2.0">

<channel>
	<title>The Lucid</title>
	
	<link>http://thelucid.com</link>
	<description>Lightweight ramblings</description>
	<pubDate>Sat, 07 Feb 2009 20:39:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/thelucid" type="application/rss+xml" /><item>
		<title>LucidGrid - a bookmarklet for working with grid based layouts</title>
		<link>http://thelucid.com/2009/02/07/lucidgrid-a-bookmarklet-for-working-with-grid-based-layouts/</link>
		<comments>http://thelucid.com/2009/02/07/lucidgrid-a-bookmarklet-for-working-with-grid-based-layouts/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 20:10:50 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=508</guid>
		<description><![CDATA[I&#8217;m pleased to give you LucidGrid, a super useful bookmarklet for working with grid based layouts&#8230;

I have been working on a few grid based layouts of late and consistently find myself sitting with a calculator tapping out the various dimensions. I was surprised to find that there weren&#8217;t any simple bookmarklets for this so I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pleased to give you LucidGrid, a super useful <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a> for working with grid based layouts&#8230;</p>

<p>I have been working on a few grid based layouts of late and consistently find myself sitting with a calculator tapping out the various dimensions. I was surprised to find that there weren&#8217;t any simple bookmarklets for this so I wrote one.</p>

<p>LucidGrid allows you to supply a width, the number of columns you need and the gutter size and then overlays a grid on the current page. You may disable the grid by clicking the bookmarklet again or by clicking exit. If you choose to apply the grid, the preference dialog will minimise to the top right of the window.</p>

<p>Grid changes happen in realtime so it is easy to play with different settings.</p>

<p><img src="http://thelucid.com/files/lucid-grid-example-300x198.gif" alt="" width="300" height="198" /></p>

<p>Simply drag the link below to your bookmarks bar in your browser or click it to try it out first:</p>

<p><a href="javascript:(function(){void(theBody=document.getElementsByTagName('body')[0]);void(wrapper=document.getElementById('_lucid_wrapper'));if(wrapper!=null){void(theBody.removeChild(wrapper));}else{void(bodyFontSize=parseFloat((theBody.currentStyle||(window.getComputedStyle&amp;&amp;getComputedStyle(theBody,null))||theBody.style).fontSize));void(wrapper=document.createElement('div'));void(wrapper.id='_lucid_wrapper');void(wrapper.style.position='absolute');void(wrapper.style.top='0');void(wrapper.style.right=0);void(wrapper.style.bottom=0);void(wrapper.style.left=0);void(wrapper.style.background='rgba(0,0,0,0.5)');void(wrapper.style.zIndex='1097');void(modal=document.createElement('div'));void(modal.id='_lucid_grid_modal');void(modal.style.position='absolute');void(modal.style.width='384px');void(modal.style.left='50%');void(modal.style.top='40px');void(modal.style.marginLeft='-200px');void(modal.style.paddingTop='8px');void(modal.style.paddingRight='8px');void(modal.style.paddingBottom='8px');void(modal.style.paddingLeft='8px');void(modal.style.background='rgba(0,0,0,.45)');void(modal.style.zIndex='1099');void(fontStyle='font-family:%20Verdana,%20Arial,%20sans-serif;%20font-size:%2012px;%20font-weight:%20normal;');void(dtStyle=fontStyle+'float:left;%20clear:%20both;%20width:%20140px;%20margin:%200;%20padding:%206px%205px;%20text-align:%20right;');void(ddStyle=fontStyle+'float:right;%20width:%20200px;%20margin:%200;%20padding:%204px%205px;%20text-align:%20left;');void(labelStyle=fontStyle+'color:%20#333;');void(inputStyle=fontStyle+'width:%20100px;%20background:%20%23fff;%20margin:%200;%20padding:%202px;%20border:%201px%20solid%20%23c3c3c3;%20border-top-color:%20%237c7c7c;%20border-bottom-color:%20%23ddd;');void(annotationStyle=fontStyle+'color:%20rgba(255,255,255,.9);%20font-size:%209px;%20padding:%201px%206px;%20background:%20rgba(0,0,0,.6);%20border:%201px%20solid%20rgba(255,255,255,.9);%20-moz-border-radius:%201px;%20-webkit-border-radius:%201px;');void(modal.innerHTML='%3Cform%20style=%22float:left;%20margin:%200;%20padding:%200;%20width:%20384px;%20background:%20rgba(255,255,255,.85);%20border-bottom:%201px%20solid%20%23bbb;%22%3E'+'%3Ch1%20style=%22'+fontStyle+'font-weight:%20bold;%20background:%20%23bbb;%20border-top:%201px%20solid%20%23eee;%20border-bottom:%201px%20solid%20%23999;%20color:%20%23fff;%20margin:%200;%20padding:%2010px%2012px;%22%3ELucidGrid%20%3Cspan%20style=%22'+fontStyle+'color:%20%23333;%20font-size:%2010px;%20position:%20absolute;%20right:%2022px;%20top:%2020px;%22%3Eby%20%3Ca%20href=%22http://thelucid.com%22%20style=%22'+fontStyle+'color:%20%23369;%20font-size:%2010px;%22%3Ethelucid.com%3C/a%3E%20(v0.9)%3C/span%3E%3C/h1%3E'+'%3Cdl%20style=%22'+fontStyle+'float:left;%20width:%20360px;%20margin:%200;%20padding:%2012px;%20list-style:%20none;%20border-top:%201px%20solid%20%23fff;%22%3E'+'%3Cdt%20style=%22'+dtStyle+'%22%3E%3Clabel%20for=%22_lucid_grid_columns%22%20style=%22'+labelStyle+'%22%3EColumns:%3C/label%3E%3C/dt%3E'+'%3Cdd%20style=%22'+ddStyle+'%22%3E%3Cinput%20id=%22_lucid_grid_columns%22%20type=%22text%22%20value=%2212%22%20style=%22'+inputStyle+'%22%20maxlength=%222%22%20/%3E%3C/dd%3E'+'%3Cdt%20style=%22'+dtStyle+'%22%3E%3Clabel%20for=%22_lucid_grid_width%22%20style=%22'+labelStyle+'%22%3EWidth:%3C/label%3E%3C/dt%3E'+'%3Cdd%20style=%22'+ddStyle+'%22%3E%3Cinput%20id=%22_lucid_grid_width%22%20type=%22text%22%20value=%22960%22%20style=%22'+inputStyle+'%22%20maxlength=%224%22%20/%3E%20px%3C/dd%3E'+'%3Cdt%20style=%22'+dtStyle+'%22%3E%3Clabel%20for=%22_lucid_grid_gutter%22%20style=%22'+labelStyle+'%22%3EGutter:%3C/label%3E%3C/dt%3E'+'%3Cdd%20style=%22'+ddStyle+'%22%3E%3Cinput%20id=%22_lucid_grid_gutter%22%20type=%22text%22%20value=%2210%22%20style=%22'+inputStyle+'%22%20maxlength=%222%22%20/%3E%20px%3C/dd%3E'+'%3Cdt%20style=%22'+dtStyle+'%22%3E%3Clabel%20for=%22_lucid_grid_annotate%22%20style=%22'+labelStyle+'%22%3EAnnotate:%3C/label%3E%3C/dt%3E'+'%3Cdd%20style=%22'+ddStyle+'%22%3E%3Cinput%20id=%22_lucid_grid_annotate%22%20type=%22checkbox%22%20value=%220%22%20style=%22'+fontStyle+'%22%20/%3E%3C/dd%3E'+'%3C/dl%3E'+'%3Cp%20style=%22'+fontStyle+'text-align:%20center;%20font-size:%2011px;%20padding-bottom:%204px;%22%3E%3Cinput%20type=%22submit%22%20value=%22Apply%22%20id=%22_lucid_grid_apply%22%20style=%22'+fontStyle+'padding:%203px%206px;%20background:%20%23f5f5f5;%20border:%201px%20solid%20%23999;%20border-left-color:%20%23fff;%20border-top-color:%20%23fff;%22%20/%3E%20or%20%3Ca%20href=%22%23%22%20id=%22_lucid_grid_exit%22%20style=%22'+fontStyle+'color:%20%23369;%22%3Eexit%3C/a%3E%3C/p%3E'+'%3C/form%3E');void(grid=document.createElement('div'));void(grid.id='_lucid_grid');void(grid.style.position='relative');void(grid.style.marginLeft='auto');void(grid.style.marginRight='auto');void(grid.style.height='100%');void(grid.style.zIndex='1098');void(trigger=document.createElement('div'));void(trigger.innerHTML='%3Ca%20href=%22%23%22%20id=%22_lucid_grid_trigger%22%20style=%22'+fontStyle+'display:%20block;%20color:%20rgba(255,255,255,.9);%20font-size:%2011px;%20text-decoration:%20none;%20font-weight:%20normal;%20padding:%203px%2012px;%20background:%20rgba(0,0,0,.7);%20border:%202px%20solid%20rgba(255,255,255,.9);%20-moz-border-radius:%201px;%20-webkit-border-radius:%201px;%20-webkit-box-shadow:%200px%201px%202px%20rgba(0,0,0,0.6);%22%3ELucidGrid%3C/a%3E');void(trigger.style.position='absolute');void(trigger.style.right='12px');void(trigger.style.top='10px');void(trigger.style.display='none');void(trigger.style.zIndex='1099');void(wrapper.appendChild(grid));void(wrapper.appendChild(trigger));void(wrapper.appendChild(modal));void(theBody.appendChild(wrapper));void(columnInput=document.getElementById('_lucid_grid_columns'));void(widthInput=document.getElementById('_lucid_grid_width'));void(gutterInput=document.getElementById('_lucid_grid_gutter'));void(annotateInput=document.getElementById('_lucid_grid_annotate'));void(applyInput=document.getElementById('_lucid_grid_apply'));void(triggerLink=document.getElementById('_lucid_grid_trigger'));void(exitLink=document.getElementById('_lucid_grid_exit'));updateGrid=function(){while(grid.hasChildNodes()){void(grid.removeChild(grid.firstChild));};void(columns=columnInput.value);void(width=widthInput.value);void(gutter=gutterInput.value);void(annotate=annotateInput.checked);void(fullColumnWidth=width/columns);void(actualColumnWidth=fullColumnWidth-(gutter*2));void(columnWidth=parseInt(actualColumnWidth));void(widthEms=(width/bodyFontSize).toFixed(3));void(columnWidthEms=(columnWidth/bodyFontSize).toFixed(3));void(gutterEms=(gutter/bodyFontSize).toFixed(3));void(grid.style.width=(widthEms+'em'));for(i=0;i%3Ccolumns;i++){void(column=document.createElement('div'));void(column.style.width=(columnWidthEms+'em'));void(column.style.marginLeft=(gutterEms+'em'));void(column.style.marginRight=(gutterEms+'em'));void(column.style.height='100%');void(column.style.cssFloat='left');void(column.style.background='rgba(255,0,0,.4)');if(annotate){void(exampleWidth=(fullColumnWidth*(i+1))-(gutter*2));void(example=document.createElement('div'));void(example.innerHTML='%3Cdiv%20style=%22'+fontStyle+'text-align:%20center;%20padding:%2010px;%20border:%201px%20solid%20rgba(255,255,255,.8);%20background:%20rgba(0,0,0,.2);%20overflow:%20hidden;%22%3E%3Cspan%20style=%22'+annotationStyle+'%22%3E'+(((exampleWidth%1)==0)?exampleWidth:exampleWidth.toFixed(3))+'%3C/span%3E%3C/div%3E');void(exampleWidthEms=(exampleWidth/bodyFontSize).toFixed(3));void(example.style.position='absolute');void(example.style.width=(exampleWidthEms+'em'));if(i%3C(columns/2)){void(top=((50/bodyFontSize)*(i+1)));void(example.style.left=(gutterEms+'em'));}else{void(top=(((50/bodyFontSize)*columns)-(50/bodyFontSize)*(i+1)));void(example.style.right=(gutterEms+'em'));};void(example.style.top=((100/bodyFontSize)+top).toFixed(3)+'em');void(grid.appendChild(example));};void(grid.appendChild(column));};};void(columnInput.onkeyup=updateGrid);void(widthInput.onkeyup=updateGrid);void(gutterInput.onkeyup=updateGrid);void(annotateInput.onchange=updateGrid);void(applyInput.onclick=function(){modal.style.display='none';trigger.style.display='block';wrapper.style.background='rgba(0,0,0,0)';return%20false;});void(triggerLink.onclick=function(){modal.style.display='block';trigger.style.display='none';wrapper.style.background='rgba(0,0,0,0.5)';return%20false;});void(exitLink.onclick=function(){theBody.removeChild(wrapper);return%20false;});void(updateGrid());}})();">LucidGrid</a></p>

<p>Enjoy&#8230; (currently tested with Safari 3.2.1 and Firefox 3.0.5).</p>

<p>p.s. I will be adding cookie support soon so that the grid remains with the same settings between page views.</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2009/02/07/lucidgrid-a-bookmarklet-for-working-with-grid-based-layouts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unit testing by simplifying the problem: memoization</title>
		<link>http://thelucid.com/2008/12/18/unit-testing-by-simplifying-the-problem-memoization/</link>
		<comments>http://thelucid.com/2008/12/18/unit-testing-by-simplifying-the-problem-memoization/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 13:16:01 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[test]]></category>

		<category><![CDATA[testing]]></category>

		<category><![CDATA[unit]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=500</guid>
		<description><![CDATA[I see unit testing as a way to test each possible snippet of functionality and route the code in question can take. With Ruby being such a dynamic language and allowing shortcuts to common problems, sometimes it can seem somewhat of a mystery, how to test these snippets of functionality.

Using Memoization as an example:


class MyClass
 [...]]]></description>
			<content:encoded><![CDATA[<p>I see unit testing as a way to test each possible snippet of functionality and route the code in question can take. With Ruby being such a dynamic language and allowing shortcuts to common problems, sometimes it can seem somewhat of a mystery, how to test these snippets of functionality.</p>

<p>Using Memoization as an example:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> MyClass
  <span style="color:#9966CC; font-weight:bold;">def</span> lazy_initialized_value
    <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span> ||= Expensive.<span style="color:#9900CC;">request</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>There are actually 3 separate snippets of functionality that need testing here, however it is not immediately obvious from the example. Lets be slightly more verbose about what is actually happening:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> MyClass
  <span style="color:#9966CC; font-weight:bold;">def</span> lazy_initialized_value
    <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span> = Expensive.<span style="color:#9900CC;">request</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span>
    <span style="color:#0066ff; font-weight:bold;">@lazy_initialized_value</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>Now it is much easier to see the 3 steps the code should take:</p>


<ul>
<li>Store result of expensive request in instance variable</li>
<li>Leave instance variable alone when it is already set</li>
<li>Return the value of the instance variable</li>
</ul>



<p>Now we have this information, our tests become (using Mocha to mock external methods):</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Expensive; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#6666ff; font-weight:bold;">Tests::MyClass</span>
  <span style="color:#008000; font-style:italic;"># lazy_initialized_value</span>
  <span style="color:#008000; font-style:italic;"># ----------------------</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> LazyInitializedValueTest &lt; <span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_respond
      assert_respond_to MyClass.<span style="color:#9900CC;">new</span>, <span style="color:#ff3333; font-weight:bold;">:lazy_initialized_value</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_store_result_of_expensive_request_in_instance_variable
      instance = MyClass.<span style="color:#9900CC;">new</span>
      Expensive.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:request</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">with</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">returns</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'expensive value'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      instance.<span style="color:#9900CC;">lazy_initialized_value</span>
      assert_equal <span style="color:#996600;">'expensive value'</span>, instance.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'@lazy_initialized_value'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_return_value_of_instance_varable
      instance = MyClass.<span style="color:#9900CC;">new</span>
      instance.<span style="color:#9900CC;">instance_variable_set</span> <span style="color:#996600;">'@lazy_initialized_value'</span>, <span style="color:#996600;">'the value'</span>
      Expensive.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:request</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      assert_equal <span style="color:#996600;">'the value'</span>, instance.<span style="color:#9900CC;">lazy_initialized_value</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> test_should_maintain_existing_instance_variable_value_when_already_set
      instance = MyClass.<span style="color:#9900CC;">new</span>
      instance.<span style="color:#9900CC;">instance_variable_set</span> <span style="color:#996600;">'@lazy_initialized_value'</span>, <span style="color:#996600;">'existing value'</span>
      Expensive.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:request</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      instance.<span style="color:#9900CC;">lazy_initialized_value</span>
      assert_equal <span style="color:#996600;">'existing value'</span>, instance.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'@lazy_initialized_value'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>Now we have these tests in place, we can go back and refractor the code &#8217;til our heart&#8217;s content using all the tricks in the book but by simplifying the problem in the first place, it gives us a solid test suite and the confidence to make changes without breaking functionality.</p>

<p>If you were solving this problem test-first then you wouldn&#8217;t (but more likely, shouldn&#8217;t) have written the first example until re-factoring stage anyway, however when these shortcuts become engrained in your brain, it&#8217;s all too easy to forget what they are <em>actually</em> doing.</p>

<p>So there we go, simplify the initial implementation, get a solid test suite in order, <em>then</em> re-factor.</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/12/18/unit-testing-by-simplifying-the-problem-memoization/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Stubbing case statements with Mocha</title>
		<link>http://thelucid.com/2008/12/04/stubbing-case-statements-with-mocha/</link>
		<comments>http://thelucid.com/2008/12/04/stubbing-case-statements-with-mocha/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 23:04:22 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[mocha]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[testing]]></category>

		<category><![CDATA[unit]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=498</guid>
		<description><![CDATA[I was happily mocking away with Mocha, then I passed a stub to a case statement at which point I was a little flummoxed.

The Ruby documentation clearly states that the &#8216;when&#8217; in a &#8216;case&#8217; statement uses the &#8216;===&#8217; method for comparing the subject so I couldn&#8217;t work out why something like the following wasn&#8217;t working:


# [...]]]></description>
			<content:encoded><![CDATA[<p>I was happily mocking away with <a href="http://mocha.rubyforge.org/">Mocha</a>, then I passed a stub to a case statement at which point I was a little flummoxed.</p>

<p>The Ruby documentation clearly states that the &#8216;when&#8217; in a &#8216;case&#8217; statement uses the &#8216;===&#8217; method for comparing the subject so I couldn&#8217;t work out why something like the following wasn&#8217;t working:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># Code</span>
<span style="color:#9966CC; font-weight:bold;">class</span> A; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> foo<span style="color:#006600; font-weight:bold;">&#40;</span>instance<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">case</span> instance
    <span style="color:#9966CC; font-weight:bold;">when</span> A : <span style="color:#996600;">'an A instance'</span>
    <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#996600;">'not an A instance'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Test</span>
a = stub_everything
a.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span>:===<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">with</span><span style="color:#006600; font-weight:bold;">&#40;</span>A<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">returns</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
assert_equal <span style="color:#996600;">'an A instance'</span>, foo<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>So I had a little play around in irb and found the following:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> A; <span style="color:#9966CC; font-weight:bold;">end</span>
a = A.<span style="color:#9900CC;">new</span>
a === A <span style="color:#008000; font-style:italic;">#=&gt; false</span>
A === a <span style="color:#008000; font-style:italic;">#=&gt; true</span></pre></div></div>




<p>This revealed that I was actually stubbing the wrong side of the operator, I changed this to the following and voila!</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># Code</span>
<span style="color:#9966CC; font-weight:bold;">class</span> A; <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> foo<span style="color:#006600; font-weight:bold;">&#40;</span>instance<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">case</span> instance
    <span style="color:#9966CC; font-weight:bold;">when</span> A : <span style="color:#996600;">'an A instance'</span>
    <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#996600;">'not an A instance'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Test</span>
a = stub_everything
A.<span style="color:#9900CC;">stubs</span><span style="color:#006600; font-weight:bold;">&#40;</span>:===<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">with</span><span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">returns</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
assert_equal <span style="color:#996600;">'an A instance'</span>, foo<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>




<p>Looks obvious now but certainly wasn&#8217;t at the time!</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/12/04/stubbing-case-statements-with-mocha/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Git - setting up a remote repository and doing an initial ‘push’</title>
		<link>http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/</link>
		<comments>http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 10:06:28 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=495</guid>
		<description><![CDATA[There is loads of documentation and posts on Git out there so this is more of a note to self as I keep forgetting the steps to setting up a remote repository and doing an initial &#8216;push&#8217;.

So, firstly setup the remote repository:




ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
git-update-server-info # If planning to serve via HTTP
exit




On local [...]]]></description>
			<content:encoded><![CDATA[<p>There is loads of documentation and posts on Git out there so this is more of a note to self as I keep forgetting the steps to setting up a remote repository and doing an initial &#8216;push&#8217;.</p>

<p>So, firstly setup the remote repository:</p>



<pre>
ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
git-update-server-info # If planning to serve via HTTP
exit
</pre>



<p>On local machine:</p>



<pre>
cd my_project
git init
git add *
git commit -m &quot;My initial commit message&quot;
git remote add origin git@example.com:my_project.git
git push origin master
</pre>



<p>Done!</p>

<p>Team members can now clone and track the remote repository using the following:</p>



<pre>
git clone git@example.com:my_project.git
cd my_project
git-track origin
</pre>



<p>Note: the &#8216;git-track&#8217; command is a bash function we use to save manually editing the .git/config file (add the following to your ~/.bash_profile file <a href="http://darkliquid.co.uk/2008/11/05/git-tracking/" rel="external">as outlined by darkliquid</a>):</p>



<pre>
function parse_git_branch {
  git branch --no-color 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function git-track {
  CURRENT_BRANCH=$(parse_git_branch)
  git-config branch.$CURRENT_BRANCH.remote $1
  git-config branch.$CURRENT_BRANCH.merge refs/heads/$CURRENT_BRANCH
}
</pre>



<h4>Bonus</h4>

<p>To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile:</p>



<pre>
function parse_git_branch_and_add_brackets {
  git branch --no-color 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
PS1=&quot;\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ &quot;
</pre>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Testing private class methods in Ruby</title>
		<link>http://thelucid.com/2008/12/01/testing-private-class-methods-in-ruby/</link>
		<comments>http://thelucid.com/2008/12/01/testing-private-class-methods-in-ruby/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 23:52:37 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=493</guid>
		<description><![CDATA[I generally make a point of not unit testing private methods however in some circumstance I find it necessary to do so. One example of this is when a class method is to be documented in the API of a library, only for use when declaring a descendent class (the Rails validates_* macros could be [...]]]></description>
			<content:encoded><![CDATA[<p>I generally make a point of not unit testing private methods however in some circumstance I find it necessary to do so. One example of this is when a class method is to be documented in the <span class="caps">API </span>of a library, only for use when declaring a descendent class (the Rails validates_* macros could be private for example).</p>

<p>Testing of private instance methods has already been <a href="http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html">documented by Jay Fields</a>, however testing private class methods requires a little more work:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> publicize_private_class_methods
    saved_instance_methods = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">class</span> &lt;&lt; <span style="color:#0000FF; font-weight:bold;">self</span>; private_instance_methods.<span style="color:#9900CC;">sort</span>; <span style="color:#9966CC; font-weight:bold;">end</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    saved_instance_methods.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |method| public_class_method method <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">yield</span> <span style="color:#0000FF; font-weight:bold;">self</span>
  <span style="color:#9966CC; font-weight:bold;">ensure</span>
    saved_instance_methods.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |method| private_class_method method <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>This allows you to do the following:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Foo
  <span style="color:#9966CC; font-weight:bold;">class</span> &lt;&lt; <span style="color:#0000FF; font-weight:bold;">self</span>
    private
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> foo
      <span style="color:#996600;">'bar'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Foo.<span style="color:#9900CC;">publicize_private_class_methods</span> <span style="color:#9966CC; font-weight:bold;">do</span> |klass|
  assert_equal <span style="color:#996600;">'bar'</span>, klass.<span style="color:#9900CC;">foo</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>The same would work for protected methods by changing all instances of the word &#8216;private&#8217; with &#8216;protected&#8217;.</p>

<p>All this could probably be merged into the original method by Jay, however I will leave that as an exercise for the reader.</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/12/01/testing-private-class-methods-in-ruby/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Storing .js files and .css files in ‘js’ and ‘css’ directories in Rails 2.2</title>
		<link>http://thelucid.com/2008/11/29/storing-js-files-and-css-files-in-js-and-css-directories-in-rails-22/</link>
		<comments>http://thelucid.com/2008/11/29/storing-js-files-and-css-files-in-js-and-css-directories-in-rails-22/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 12:26:03 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=487</guid>
		<description><![CDATA[In the years I have been working with Rails I have generally been happy to follow the conventions that it enforces. There is one that just doesn&#8217;t sit right with me and that is the decision to store .css files in a &#8217;stylesheets&#8217; directory and .js files in a &#8216;javascripts&#8217; directory as I prefer &#8216;css&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>In the years I have been working with Rails I have generally been happy to follow the conventions that it enforces. There is one that just doesn&#8217;t sit right with me and that is the decision to store .css files in a &#8217;stylesheets&#8217; directory and .js files in a &#8216;javascripts&#8217; directory as I prefer &#8216;css&#8217; and &#8216;js&#8217; directories (call me old fashioned).</p>

<p>Achieving this in Rails 2.2 involves changing a couple of constants. I may submit a patch with a config hook for this as it feels a little dirty changing the constants directly. Add the following lines to your environment.rb file.</p>


<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::AssetTagHelper::StylesheetAsset::DIRECTORY</span> = <span style="color:#996600;">'css'</span>.<span style="color:#9900CC;">freeze</span>
<span style="color:#6666ff; font-weight:bold;">ActionView::Helpers::AssetTagHelper::JavaScriptAsset::DIRECTORY</span> = <span style="color:#996600;">'js'</span>.<span style="color:#9900CC;">freeze</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/11/29/storing-js-files-and-css-files-in-js-and-css-directories-in-rails-22/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Yet another Git convert</title>
		<link>http://thelucid.com/2008/11/26/yet-another-git-convert/</link>
		<comments>http://thelucid.com/2008/11/26/yet-another-git-convert/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 09:09:52 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=485</guid>
		<description><![CDATA[So, after switching from Subversion to Git approximately a month ago, how has it been?

Well, what can I say, all the hype is deserved. Git makes things like branching, merging and tagging something that I no longer have to think about.

At first I wasn&#8217;t completely sold on the idea of keeping multiple copies of entire [...]]]></description>
			<content:encoded><![CDATA[<p>So, after switching from Subversion to Git approximately a month ago, how has it been?</p>

<p>Well, what can I say, all the hype is deserved. Git makes things like branching, merging and tagging something that I no longer have to think about.</p>

<p>At first I wasn&#8217;t completely sold on the idea of keeping multiple copies of entire repositories on multiple machines as I keep my Photoshop originals etc. all in the repositories and feared it would take forever for the initial checkout (clone in Git). I have actually found completely the opposite in that by having the entire repository on my development machine (whether it be my office or laptop machine), the time that I save switching branches i.e. not having to checkout another branch remotely etc. far outweighs the initial &#8220;pull&#8221; time which is in fact extremely fast.</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/11/26/yet-another-git-convert/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hiding system files such as /usr and /bin on OSX Leopard</title>
		<link>http://thelucid.com/2008/11/11/hiding-system-files-such-as-usr-and-bin-on-osx-leopard/</link>
		<comments>http://thelucid.com/2008/11/11/hiding-system-files-such-as-usr-and-bin-on-osx-leopard/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 10:49:49 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://thelucid.com/?p=471</guid>
		<description><![CDATA[This is a very boring post considering it&#8217;s the first in over a year but hey, I have to start somewhere.

Since upgrading to Leopard, even on clean installs, it decides to show system files such as /usr /bin /etc etc. To re-hide these files use the following:

  sudo /Developer/Tools/SetFile -a V /bin

The -a means [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very boring post considering it&#8217;s the first in over a year but hey, I have to start somewhere.</p>

<p>Since upgrading to Leopard, even on clean installs, it decides to show system files such as /usr /bin /etc etc. To re-hide these files use the following:</p>

<p>  sudo /Developer/Tools/SetFile -a V /bin</p>

<p>The -a means &#8220;set attributes&#8221; and the V means make in(V)isible (obviously!?). You will need developer tools installed from the Leopard disc for this to work.</p>

<h3>Why so long since the last post?</h3>

<p>The reason for not posting in such a long time is that I was running on a broken Typo install for ages with no time to fix it. I have now moved to Wordpress as it has grown up a little since I last used it. I will be porting the Lucid theme and adding features at some point, in the meantime the Typo version is still available as a download.</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2008/11/11/hiding-system-files-such-as-usr-and-bin-on-osx-leopard/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Proprietary CSS rules - Are we returning to 1995?</title>
		<link>http://thelucid.com/2007/10/30/proprietary-css-rules-are-we-returning-to-1995/</link>
		<comments>http://thelucid.com/2007/10/30/proprietary-css-rules-are-we-returning-to-1995/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 13:44:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Mac / OS X]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">88bcddf7-b862-47f8-8788-3a0abd4c8ab7</guid>
		<description><![CDATA[Call me a cynic, but posts like this one on the Surfin&#8217; Safari blog worry me a little. Let me explain&#8230;

I don&#8217;t know if anyone remembers back to the days of Netscape 4 and Explorer 3.5? - It was a time of table based layouts and browser sniffing. Each browser had it&#8217;s own &#8220;feature&#8221; set [...]]]></description>
			<content:encoded><![CDATA[<p>Call me a cynic, but <a href="http://webkit.org/blog/130/css-transforms">posts like this one on the Surfin&#8217; Safari blog</a> worry me a little. Let me explain&#8230;</p>

<p>I don&#8217;t know if anyone remembers back to the days of Netscape 4 and Explorer 3.5? - It was a time of table based layouts and browser sniffing. Each browser had it&#8217;s own &#8220;feature&#8221; set and this resulted in hacks galore, for example Netscape had &#8220;Layers&#8221; but Explorer didn&#8217;t, Explorer had feature X but Netscape didn&#8217;t.</p>

<p>Along came <a href="http://www.w3c.org">Web Standards</a> and the likes of <a href="http://www.zeldman.com">Jeffrey Zeldman</a> fighting for a standards based approach to web development. Over a decade on, it looks like were finally getting there as <em>even</em> Microsoft <em>slowly</em> start to get things right with <span class="caps">IE7.</span></p>

<p>As cool as the <a href="http://webkit.org/blog/130/css-transforms"><span class="caps">CSS</span> Transform</a> stuff looks, I can&#8217;t help but thing we&#8217;re stepping right back into 1995.</p>

<p>What does everyone else think?</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2007/10/30/proprietary-css-rules-are-we-returning-to-1995/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails: Using Autotest with UnitRecord</title>
		<link>http://thelucid.com/2007/09/05/rails-using-autotest-with-unitrecord/</link>
		<comments>http://thelucid.com/2007/09/05/rails-using-autotest-with-unitrecord/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 00:17:00 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[autotest]]></category>

		<category><![CDATA[test]]></category>

		<category><![CDATA[unit_record]]></category>

		<guid isPermaLink="false">d3754554-5787-434b-8741-474c805c4a4e</guid>
		<description><![CDATA[Myself and a colleague have just managed to waste away a good couple of hours trying to figure out Autotests strange &#8217;style&#8217; mechanism to add the ability to test in the way Jay Fields explains using UnitRecord.

You can grab our plugin to enable UnitRecord when using Autotest below:

http://svn.soniciq.com/public/rails/plugins/iq_autotest

By default, running autotest in the Rails directory [...]]]></description>
			<content:encoded><![CDATA[<p>Myself and a colleague have just managed to waste away a good couple of hours trying to figure out Autotests strange &#8217;style&#8217; mechanism to add the ability to <a href="http://blog.jayfields.com/2007/09/rails-how-we-test.html">test in the way Jay Fields explains</a> using <a href="http://unit-test-ar.rubyforge.org/">UnitRecord</a>.</p>

<p>You can grab our plugin to enable <a href="http://unit-test-ar.rubyforge.org/">UnitRecord</a> when using <a href="http://rubyforge.org/projects/zentest">Autotest</a> below:</p>

<p><a href="http://svn.soniciq.com/public/rails/plugins/iq_autotest">http://svn.soniciq.com/public/rails/plugins/iq_autotest</a></p>

<p>By default, running <code>autotest</code> in the Rails directory will run the unit tests. To run the functional tests, do: <code>AUTOTEST='functional' autotest</code></p>

<p>I hope this saves some people some time!!</p>]]></content:encoded>
			<wfw:commentRss>http://thelucid.com/2007/09/05/rails-using-autotest-with-unitrecord/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
