<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Olly Legg</title>
 <link href="http://51degrees.net/atom.xml" rel="self"/>
 <link href="http://51degrees.net/"/>
 <updated>2010-10-06T18:39:16+01:00</updated>
 <id>http://51degrees.net/</id>
 <author>
   <name>Olly Legg</name>
   <email>olly@51degrees.net</email>
 </author>

 
 <entry>
   <title>Global After Blocks in RSpec; or How to Keep Timecop Happy</title>
   <link href="http://51degrees.net/2010/01/18/global-after-blocks-or-keeping-timcop-happy.html"/>
   <updated>2010-01-18T00:00:00+00:00</updated>
   <id>http://51degrees.net/2010/01/18/global-after-blocks-or-keeping-timcop-happy</id>
   <content type="html">&lt;p class=&quot;meta&quot;&gt;18 Jan 2010&lt;/p&gt;

&lt;p&gt;I recently ran into a problem with a test suite in a Rails application which had me stumped for a while. To sum up briefly a group of test suddenly started failing. What had happened was that &lt;a href=&quot;http://github.com/jtrupiano/timecop&quot;&gt;Timecop&lt;/a&gt; was being set globally and wasn't being reset. This caused problems when a couple of weeks later the tests were run and the times were different to what they were expecting. Although the final solution is very simplistic&lt;/p&gt;

&lt;p&gt;One way to fix the test suite would have been to use Timecop's block syntax, for example:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;should mark the sprint as in the past&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; 
  &lt;span class=&quot;no&quot;&gt;Timecop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;freeze&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;today&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sprint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;be_past&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;However I'm not a great fan of this syntax in my tests, I prefer my tests to be more procedural. It also prevents you from stubbing the time in a before block for a group of tests.&lt;/p&gt; 

&lt;p&gt;The solution I settled with was to add a &lt;a href=&quot;http://rspec.info/documentation/before_and_after.html&quot;&gt;global after block&lt;/a&gt; which resets &lt;a href=&quot;http://github.com/jtrupiano/timecop&quot;&gt;Timecop&lt;/a&gt; after each test. In &lt;code&gt;spec/spec_helper.rb&lt;/code&gt; add this simple global after block:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;no&quot;&gt;Spec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Runner&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;after&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:each&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Timecop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;return&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>What to do this New Year?</title>
   <link href="http://51degrees.net/2010/01/01/what-to-do-this-new-year.html"/>
   <updated>2010-01-01T00:00:00+00:00</updated>
   <id>http://51degrees.net/2010/01/01/what-to-do-this-new-year</id>
   <content type="html">&lt;p class=&quot;meta&quot;&gt;01 Jan 2010&lt;/p&gt;

&lt;div class=&quot;masthead&quot;&gt;
  &lt;a href=&quot;http://www.flickr.com/photos/tahir/2154248534/&quot;&gt;
    &lt;img src=&quot;/images/20100101-masthead.jpg&quot; width=&quot;586&quot; /&gt;
  &lt;/a&gt;
  &lt;p class=&quot;credit&quot;&gt;Photo by &lt;a href=&quot;http://www.flickr.com/people/tahir/&quot;&gt;T@H!R - طاھر&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;This is a very cliched, 1st of January, blog post &amp;mdash; however it does tie in, very nicely, to my first resolution. Here, for posterity, is a list of the four things I plan to achieve in 2010:&lt;/p&gt;

&lt;ul&gt;

  &lt;li&gt;&lt;strike&gt;Start blogging more often.&lt;/strike&gt; Start blogging. This blog was &lt;a href=&quot;/2009/03/25/rgb-helper.html&quot;&gt;started&lt;/a&gt; on the 25th March 2009 with the very best of intentions. It has lain dormant ever since. This year I plan to make good on last year's intentions and actually post some content.&lt;/li&gt;

  &lt;li&gt;I had heard about &lt;a href=&quot;http://codekata.pragprog.com/&quot;&gt;Code Katas&lt;/a&gt; a while back. Having completed my first one last year, after being inspired by &lt;a href=&quot;http://www.katacasts.com/&quot;&gt;Katacasts&lt;/a&gt;, I found it very enjoyable and quite useful. Over the coming year I am going to complete some different katas, complete some using different languages and different programming styles.&lt;/li&gt;

  &lt;li&gt;I've always wanted to be able to take decent photos. To this end I'm going to take more frequent photos this year. I recently saw the excellent &lt;a href=&quot;http://craigmod.com/journal/gf1-fieldtest/&quot;&gt;Panasonic GF1 review&lt;/a&gt; so might invest in one of those. Or I might just &lt;a href=&quot;http://thebestcamera.com/&quot;&gt;start by using my phone&lt;/a&gt;. I think taking part in &lt;a href=&quot;http://dailyshoot.com/&quot;&gt;The Daily Shoot&lt;/a&gt; would be a good start.&lt;/li&gt;

  &lt;li&gt;I'm also going to travel round the UK some more over the next year. I want to visit &lt;a href=&quot;http://wikitravel.org/en/Bath_%28England%29&quot;&gt;Bath&lt;/a&gt;, &lt;a href=&quot;http://wikitravel.org/en/Cambridge_%28England%29&quot;&gt;Cambridge&lt;/a&gt;, &lt;a href=&quot;http://wikitravel.org/en/Exeter&quot;&gt;Exeter&lt;/a&gt; and &lt;a href=&quot;http://wikitravel.org/en/Leeds&quot;&gt;Leeds&lt;/a&gt; for starters &amp;mdash; mainly because I have sofas to crash on there!&lt;/li&gt;

&lt;/ul&gt;




</content>
 </entry>
 
 <entry>
   <title>RGB helper method</title>
   <link href="http://51degrees.net/2009/03/25/rgb-helper.html"/>
   <updated>2009-03-25T00:00:00+00:00</updated>
   <id>http://51degrees.net/2009/03/25/rgb-helper</id>
   <content type="html">&lt;p class=&quot;meta&quot;&gt;25 Mar 2009&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/rgb-safari.png&quot; alt=&quot;Web Inspector in Safari&quot; title=&quot;Web Inspector in Safari&quot; class=&quot;right &quot;/&gt;I use Safari for my day to day development and while the &amp;#8216;Inspect Element&amp;#8217; command has been much improved since earlier versions &amp;#8211; I still can&amp;#8217;t find out the foreground or background colours in hexadecimal notation.&lt;/p&gt;
&lt;p&gt;The following ruby snippet converts from the format that Safari provides into hexadecimal. I find that its really useful to put in &lt;tt&gt;&lt;a href=&quot;http://github.com/olly/dotfiles/&quot;&gt;.irbrc&lt;/a&gt;&lt;/tt&gt; so that its always available for  quick conversions in &lt;span class=&quot;caps&quot;&gt;IRB&lt;/span&gt;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;colours&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;colours&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colour&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;colour&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rjust&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upcase&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;I&amp;#8217;m of the school of thought that every bit of code should be tested, mainly to preserve my sanity, so here are the specs for the following method.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;describe&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;#rgb&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;should convert rgb(0, 0, 0) to &amp;#39;#000000&amp;#39;&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;#000000&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;should convert rgb(190, 215, 205) to &amp;#39;#BED7CD&amp;#39;&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;190&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;215&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;205&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;#BED7CD&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;should convert rgb(255, 255, 255) to &amp;#39;#FFFFFF&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rgb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;should&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;#FFFFFF&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 
</feed>
