<?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>emson... &#187; ruby</title>
	<atom:link href="http://blog.emson.co.uk/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.emson.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 24 Jun 2010 08:27:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>What is the Difference Between a Proc and a Lambda in Ruby?</title>
		<link>http://blog.emson.co.uk/2010/05/what-is-the-difference-between-a-proc-and-a-lambda-in-ruby/</link>
		<comments>http://blog.emson.co.uk/2010/05/what-is-the-difference-between-a-proc-and-a-lambda-in-ruby/#comments</comments>
		<pubDate>Tue, 11 May 2010 11:43:12 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/?p=104</guid>
		<description><![CDATA[The concepts of a Proc and a lambda in Ruby are subtly different and this post aims to try and explain the differences.

Procs and Lambdas

Firstly why do we need Procs and lambdas? In order to answer this you need to understand what a block is in Ruby.

Understanding what a block is?

A block is simply a [...]]]></description>
			<content:encoded><![CDATA[<p>The concepts of a <strong>Proc</strong> and a <strong>lambda</strong> in Ruby are subtly different and this post aims to try and explain the differences.</p>

<h2>Procs and Lambdas</h2>

<p>Firstly why do we need Procs and lambdas? In order to answer this you need to understand what a <strong>block</strong> is in Ruby.</p>

<h3>Understanding what a block is?</h3>

<p>A <strong>block</strong> is simply a piece of code, which is usually attached to a method, Proc or lambda. It is important to note that this block of code is NOT an object (yet&#8230;), it is code that is defined either within braces {} or within a <code>do end</code> container.</p>

<p>The code in a <strong>block</strong> is just logic that hasn&#8217;t been wrapped into an object yet. When this <strong>block</strong> is passed to a method and that method has a <strong>yield</strong> statement then Ruby will wrap that <strong>block</strong> into a special type of object. That type of object is a <strong>Proc</strong> object. Once the <strong>block</strong> becomes a <strong>Proc</strong> Ruby can use it and the <strong>block</strong> code &#8216;comes alive&#8217;.</p>

<p>Therefore we need a <strong>Proc</strong> object in order to handle <strong>blocks</strong>. The next question is how does a <strong>lambda</strong> fit in.</p>

<p>A <strong>lambda</strong> is a type of <strong>Proc</strong> object, it is almost completely identical to a Proc apart from two differences. This little code snippet shows that a <strong>Proc</strong> and a <strong>lambda</strong> are derived from the same superclass, <strong>Proc</strong>.</p>

<pre><code>  def what_are_lambdas_and_procs
    puts "--- #{__method__} ---"
    lam = lambda { puts 'lam variable assigned a lambda' }
    lam.call
    puts "lam is a class of: #{lam.class.name}"
    puts "lam method count: #{lam.methods.size}"
    puts
    prc = Proc.new { puts 'prc variable assigned a Proc' }
    prc.call
    puts "prc is a class of: #{prc.class.name}"
    puts "prc method count: #{prc.methods.size}"
    ""
  end
</code></pre>

<p>This will output:</p>

<pre><code>  --- what_are_lambdas_and_procs ---
  lam variable assigned a lambda
  lam is a class of: Proc
  lam method count: 55

  prc variable assigned a Proc
  prc is a class of: Proc
  prc method count: 55
</code></pre>

<h2>So what are the subtle differences between Proc and lambda?</h2>

<p>As mentioned there are two differences, and these differences are :</p>

<ol>
<li>in how a Proc/lambda assigns arguments, and</li>
<li>in what happens, when a Proc/lambda calls return within a caller method.</li>
</ol>

<h3>Proc, lambda argument assignment</h3>

<p>When a <strong>lambda</strong> is called with more or less than the required number of arguments Ruby will throw an ArgumentError.</p>

<p>However when a <strong>Proc</strong> is called with more arguments, no error is thrown and the extra values are simply thrown away.  When it is called with less arguments these parameters are simply assigned a value of <strong>nil</strong>.</p>

<p>These two code snippets demonstrate this:</p>

<pre><code>  def lambda_args
    puts "--- #{__method__} ---"
    lam = lambda { |a, b| puts "lambda with 2 arguments a:#{a}, b:#{b}" }
    lam.call( "first", "second")
    puts "lambda called with three arguments..."
    begin
      lam.call("first", "second", "third")
    rescue
      puts "   ArgumentError: wrong number of arguments (3 for 2)"
    end
    puts "lambda called with no arguments..."
    begin
      lam.call()
    rescue
      puts "   ArgumentError: wrong number of arguments (0 for 2)"
    end
  end

  def proc_args
    puts "--- #{__method__} ---"
    prc = Proc.new { |a, b| puts "Proc with 2 arguments a:#{(a.nil?) ? "nil" : a }, b:#{(b.nil?) ? "nil" : b }" }
    prc.call( "first", "second")
    puts "Proc called with three arguments..."
    prc.call("first", "second", "third")
    puts "Proc called with no arguments..."
    prc.call()
  end
</code></pre>

<p>This will output:</p>

<pre><code>  --- lambda_args ---
  lambda with 2 arguments a:first, b:second
  lambda called with three arguments...
     ArgumentError: wrong number of arguments (3 for 2)
  lambda called with no arguments...
     ArgumentError: wrong number of arguments (0 for 2)

  --- proc_args ---
  Proc with 2 arguments a:first, b:second
  Proc called with three arguments...
  Proc with 2 arguments a:first, b:second
  Proc called with no arguments...
  Proc with 2 arguments a:nil, b:nil
</code></pre>

<h3>Proc and lambda return behaviour</h3>

<p>When a <strong>lambda</strong> returns a value and this <strong>lambda</strong> is called within a method then method will simply continue it&#8217;s execution until it itself returns a value.</p>

<p>However when a <strong>Proc</strong> returns a value and this <strong>Proc</strong> is called within a method this containing method will be exited WITHOUT any further execution. This is slightly surprising behaviour, and consequently a <strong>Proc</strong> should be handled with care.</p>

<p>These two code snippets demonstrate this behaviour:</p>

<pre><code>  def lam_return
    puts "--- #{__method__} ---"
    puts "simple function that calls a lambda and then returns it's own string."
    my_lam = lambda { return 'Lambda has returned' }
    my_lam.call 
    return 'lam_return method string returned'
  end

  def proc_return
    puts "--- #{__method__} ---"
    puts "simple function that calls a Proc, \nBUT instead of returning it's own string returns the Proc's string."
    my_proc = Proc.new { return 'Proc string returned' }
    my_proc.call # this function returns and finishes here
    return 'proc_return method string returned' # the return is never called
  end
</code></pre>

<p>This will output the following:</p>

<pre><code>  --- lam_return ---
  simple function that calls a lambda and then returns it's own string.
  lam_return method string returned

  --- proc_return ---
  simple function that calls a Proc, 
  BUT instead of returning it's own string returns the Proc's string.
  Proc string returned
</code></pre>

<h4>Proc return work around</h4>

<p>There is however a very simple work around to avoid a Proc from returning out of it&#8217;s caller method. Simply removed the return statement, because Ruby always returns the last line this last line will be returned automatically.</p>

<pre><code>  def proc_return_work_around
    puts "--- #{__method__} ---"
    puts "simple function that calls a Proc, \nhowever the method string still returns."
    my_proc = Proc.new { 'Proc string returned' }
    my_proc.call # this function returns and finishes here
    return "#{__method__} method string returned" # the return is never called
  end
</code></pre>

<p>This will output:</p>

<pre><code>  --- proc_return_work_around ---
  simple function that calls a Proc, 
  however the method string still returns.
  proc_return_work_around method string returned
</code></pre>

<h2>Conclusion</h2>

<p>As you have seen there are only two small differences between a <strong>Proc</strong> and a <strong>lambda</strong> but these differences have quite surprising behaviours.  Therefore following the Ruby principle of <em>&#8220;&#8230;least surprise&#8221;</em>, it is best practice to use <strong>lambdas</strong> over <strong>Procs</strong> unless you absolutely need the <strong>Proc</strong> behaviour.</p>

<p>For more information please see this article: <a href="http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls">http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2010/05/what-is-the-difference-between-a-proc-and-a-lambda-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Sinatra Partials The Rails Way</title>
		<link>http://blog.emson.co.uk/2009/09/create-sinatra-partials-the-rails-way/</link>
		<comments>http://blog.emson.co.uk/2009/09/create-sinatra-partials-the-rails-way/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 08:09:57 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/?p=71</guid>
		<description><![CDATA[This is just a quick post. I&#8217;ve been playing around with the Sinatra micro web framework, and have to say that it is excellent. It really is the perfect tool for rapidly creating small and useful Ruby micro-sites.

Being small and lightweight it doesn&#8217;t have many of the features of larger frameworks like Ruby on Rails. [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick post. I&#8217;ve been playing around with the <a href="http://www.sinatrarb.com/">Sinatra micro web framework</a>, and have to say that it is excellent. It really is the perfect tool for rapidly creating small and useful <a href="http://www.ruby-lang.org/en/">Ruby</a> micro-sites.</p>

<p>Being small and lightweight it doesn&#8217;t have many of the features of larger frameworks like <a href="http://rubyonrails.org/">Ruby on Rails</a>. One of the features I&#8217;ve begun to need is the handling of Rails like partials.</p>

<p>Notably I need to pass both local variables and collections to the partial code and have the partials rendered accordingly.
I started implementing my own version, and then came across a nice little <a href="http://github.com/">Github</a> project: <a href="http://github.com/sbfaulkner/sinatra-helpers">Sinatra-Helpers by sbfaulkner</a>.</p>

<p>Anyway here is the code he uses for Sinatra partials:</p>

<pre><code>def haml_partial(name, options = {})
  item_name = name.to_sym
  counter_name = "#{name}_counter".to_sym
  if collection = options.delete(:collection)
    collection.enum_for(:each_with_index).collect do |item,index|
      haml_partial name, options.merge(:locals =&gt; {item_name =&gt; item, counter_name =&gt; index+1})
    end.join
  elsif object = options.delete(:object)
    haml_partial name, options.merge(:locals =&gt; {item_name =&gt; object, counter_name =&gt; nil})
  else
    haml "_#{name}".to_sym, options.merge(:layout =&gt; false)
  end
end
</code></pre>

<p>You can use his project or if you just need this feature just pop this code into your Sinatra helpers file  <strong>application_helper.rb</strong>:</p>

<pre><code>helpers do

  def partial(name, options = {})
    item_name = name.to_sym
    counter_name = "#{name}_counter".to_sym
    if collection = options.delete(:collection)
      collection.enum_for(:each_with_index).collect do |item, index|
        partial(name, options.merge(:locals =&gt; { item_name =&gt; item, counter_name =&gt; index + 1 }))
      end.join

    elsif object = options.delete(:object)
      partial name, options.merge(:locals =&gt; {item_name =&gt; object, counter_name =&gt; nil})
    else
      haml "_#{name}".to_sym, options.merge(:layout =&gt; false)
    end
  end
end
</code></pre>

<p>Now you can call the partial from a your page e.g. <strong>index.haml</strong></p>

<pre><code>= partial("mypartial", :locals =&gt; {:var1 =&gt; "value 1", :var2 =&gt; "value 2 and so on"})
</code></pre>

<p>Create a partial in the same directory as the calling page. Note that this code doesn&#8217;t like filenames truncated with a &#8216;-&#8217;, so avoid this if possible. Also like in Rails your partials should start with an underscore. e.g.  <strong>_mypartial.haml</strong></p>

<p>To access the variable from this partial simply call the local variable name in your code:</p>

<pre><code>%h2 
  This is var1:
  = var1

%p 
  And this is var2:
  = var2
</code></pre>

<p>Handling collections, again, is similar to the way Rails handles partial collections. From your page call the partial with a collection such as:</p>

<pre><code>= partial("listitem", :collection =&gt; ["item 1", "item 2 and so on"])
</code></pre>

<p>Now in the <strong>_listitem.haml</strong> partial code simply provide the partial name as a variable or the partialname with _counter for the increment number e.g.</p>

<pre><code>%li
  = listitem
  is the 
  = listitem_counter
  in this array
</code></pre>

<p>Anyway all pretty basic stuff but I hope it helps the casual Sinatra surfer.</p>

<p>Goodluck.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2009/09/create-sinatra-partials-the-rails-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SproutCore and Web Applications</title>
		<link>http://blog.emson.co.uk/2008/08/sproutcore-and-web-applications/</link>
		<comments>http://blog.emson.co.uk/2008/08/sproutcore-and-web-applications/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 10:00:56 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sproutcore javascript ruby]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/?p=15</guid>
		<description><![CDATA[It&#8217;s been a wee while since my last article, which has largely been due to my summer holiday.
Anyway I&#8217;ve been reading up and experimenting with the SproutCore JavaScript framework.

Its excellent but I wanted to explain why companies and developers should consider using it.  So I&#8217;ve written an article on my business partner&#8217;s web site [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a wee while since my last article, which has largely been due to my summer holiday.
Anyway I&#8217;ve been reading up and experimenting with the <a href="http://www.sproutcore.com">SproutCore</a> JavaScript framework.</p>

<p>Its excellent but I wanted to explain why companies and developers should consider using it.  So I&#8217;ve written an article on my business partner&#8217;s web site <a href="http://rapidappsgroup.com/content/desktop-web-applications-using-sproutcore/">http://rapidappsgroup.com/content/desktop-web-applications-using-sproutcore/</a>. <br/></p>

<p>Please check it out as it tries to answer a lot of the general questions about web applications and JavaScript frameworks.</p>

<p>BE&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/08/sproutcore-and-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Almost Fix for Creating RubyGems on Windows</title>
		<link>http://blog.emson.co.uk/2008/06/an-almost-fix-for-creating-rubygems-on-windows/</link>
		<comments>http://blog.emson.co.uk/2008/06/an-almost-fix-for-creating-rubygems-on-windows/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 14:20:25 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[gems]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/2008/06/an-almost-fix-for-creating-rubygems-on-windows/</guid>
		<description><![CDATA[Introduction

I wrote this article originally so that I could write command-line apps using Ruby, as I got further and further down the line I realised that what I really wanted to do was create a command-line app using RubyGems.  I use both Windows and an Apple Mac and I quickly found myself having problems [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>I wrote this article originally so that I could write command-line apps using Ruby, as I got further and further down the line I realised that what I really wanted to do was create a command-line app using RubyGems.  I use both Windows and an Apple Mac and I quickly found myself having problems trying to create RubyGems on Windows.</p>

<p>In this article I try to explain my thought process and the problems I encountered.  Unfortunately I had to employ a manual process when trying to package up my project into a <em>tar</em> file, as there isn&#8217;t a simple way to do this in Windows (let me know if you have a solution), however everything else seems to work.</p>

<h2>What&#8217;s a RubyGem?</h2>

<p>One of the joys of Ruby is the <a href="http://www.rubygems.org/">RubyGems</a> packaging system. 
It is essentially a tool written in Ruby, for packaging up source code for deployment.</p>

<p>The RubyGems site describes it as follows:</p>

<blockquote>
  <p>RubyGems is the premier ruby packaging system. It provides:</p>
  
  <ul>
  <li>A standard format for destributing Ruby programs and libraries.</li>
  <li>An easy to use tool for managing the installation of gem packages.</li>
  <li>A gem server utility for serving gems from any machine where RubyGems is installed.</li>
  </ul>
</blockquote>

<h2>Why should I create a RubyGem?</h2>

<p>Maybe a better question should be <em>when</em> should I package my code up into a RubyGem.  Obviously there are no hard and fast rules but if you are going to share your code libraries with others or even with other applications of yours, you should think about using a gem.</p>

<p>Now you might think that you don&#8217;t want to make all your code public on <a href="http://rubyforge.org/">RubyForge</a>, and there are very good reason not to publish every gem, so you don&#8217;t have to.
RubyGems comes with its own <em>local</em> gem server so you can create your own gem library and share it amoung your other Ruby applications.</p>

<p>This is really quite useful, you get the power of RubyGems without the commitment and maintenance work of making your code OpenSource.  Plus at any point in time you can then make it OpenSource, and live off the joy of the Ruby community <img src='http://blog.emson.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>

<p>The reason I wrote this article is because I wanted to create a simple command-line application using Ruby. I went through a number of steps before realising that the best way was to use RubyGems.</p>

<p>I started by creating my own command-line structure and then found this great article by <a href="http://blog.infinitered.com/entries/show/5">Todd Werth</a>.  He has a single Ruby file that you just replace various sections and viola you have a very simple command-line app.  But it wasn&#8217;t quite what I wanted.  I didn&#8217;t want to have to type:</p>

<pre><code>./my_super_app 'some params'
</code></pre>

<p>I wanted to type:</p>

<pre><code>my_super_app 'some params'
</code></pre>

<p>I also wanted the structure of the application to follow a standard structure and I didn&#8217;t want to put &#8216;.&#8217; into my path, for security reasons.
<a href="http://drnicwilliams.com/">Dr Nic</a> came to the rescue with a couple of excellent articles describing how to <a href="http://drnicwilliams.com/2006/10/11/generating-new-gems/">create gems using <strong>newgem</strong></a> and specifically <a href="http://drnicwilliams.com/2006/10/18/create-and-deploy-command-line-apps-with-rubygems/">command-line apps as gems</a>.</p>

<h2>Installing newgem on Windows</h2>

<p>To install <strong>newgem</strong> on Windows use the RubyGems install method.</p>

<pre><code>gem install newgem
</code></pre>

<p>This will install the gem and its dependencies.  However one of its dependencies is the <a href="http://seattlerb.rubyforge.org/hoe/">Hoe gem</a>, and there is a slight issue using it on Windows.</p>

<h3>What is hoe?</h3>

<p>Hoe is a compliment to <strong>rake</strong>, it was created by <a href="http://zenspider.com/">Ryan Davis</a> and provides <strong>rake</strong> tasks for testing, packaging, and releasing RubyGems.  <a href="http://nubyonrails.com/articles/tutorial-publishing-rubygems-with-hoe">Geoffrey Grosenbach has a nice tutorial for using hoe</a> and also describes how to create a project structure using the <strong>sow</strong> task.</p>

<p>Hoe uses a <strong>.hoerc</strong> file for configuration, and this file should reside in the user&#8217;s home directory, something like:</p>

<pre><code>C:\Documents and Settings\MyUserName
</code></pre>

<p>An example <strong>.hoerc</strong> file should look like the one below.  Please note that this is a <a href="http://en.wikipedia.org/wiki/YAML">YAML</a> file and if you copy it from here remember to follow the indentation convention:</p>

<pre><code>---
publish_on_announce: false
exclude: !ruby/regexp/tmp$|CVS|\.svn|_darcs|\.git|log$|local/.*\.rb$|Makefile|.*\.o$|.*\.bundle$|.*\.so$|.*\.dll$/ 
str: ""
"@taguri": tag:ruby.yaml.org,2002:regexp/tmp$|CVS|\.svn|_darcs|\.git|log$|local/.*\.rb$|Makefile|.*\.o$|.*\.bundle$|.*\.so$|.*\.dll$/
blogs:
- user: user
  url: url
  extra_headers:
    mt_convert_breaks: markdown
  blog_id: blog_id
  password: password
</code></pre>

<p>On Unix systems there is a shortcut to the user&#8217;s home directory which is &#8216;~&#8217; and on Windows this isn&#8217;t a shortcut.  Windows however does have an environment variable <strong>HOMEPATH</strong> which will point to the user&#8217;s home directory.  The problem is that the Hoe gem code uses &#8216;~&#8217; in its <strong>hoe.rb</strong> file and this causes problems for Windows users.</p>

<h3>Patching the hoe.rb file</h3>

<p>OK, be brave, lets tweak the hoe.rb file so that it will work on the Windows platform.
The Hoe gem <strong>hoe.rb</strong> file can be found in the following directory (assuming you installed Ruby to the standard location):</p>

<pre><code>C:\ruby\lib\ruby\gems\1.8\gems\hoe-1.6.0\lib
</code></pre>

<p>To make it work for Windows PCs you will need to modify this file with the following changes.</p>

<p>Locate the <strong>define_tasks</strong> method:</p>

<pre><code>def define_tasks # :nodoc:
  def with_config # :nodoc:
    rc = File.expand_path("~/.hoerc")
    exists = File.exist? rc
    config = exists ? YAML.load_file(rc) : {}
    yield(config, rc)
  end
</code></pre>

<p>And add a new method above it such as this, and modify the line <strong>rc = File.expand_path(&#8220;~/.hoerc&#8221;)</strong> as below:</p>

<pre><code>def get_home_dir
  home_file_path = "~/"
  home_file_path = "#{ENV['HOMEPATH']}\\" if WINDOZE
  home_file_path
end

def define_tasks # :nodoc:
 def with_config # :nodoc:
   rc = File.expand_path(get_home_dir + '.hoerc')
   exists = File.exist? rc
   config = exists ? YAML.load_file(rc) : {}
   yield(config, rc)
 end
</code></pre>

<p>Finally you will need to locate and change the <strong>task :config_hoe</strong> so that it reads:</p>

<pre><code>"signing_key_file" =&gt; "#{get_home_dir}.gem/gem-private_key.pem",
"signing_cert_file" =&gt; "#{get_home_dir}.gem/gem-public_cert.pem",
</code></pre>

<p>If all has gone correctly save this file and you are now ready to create a RubyGem.</p>

<h2>Creating a basic RubyGem</h2>

<p>Using the <strong>newgem</strong> RubyGem enter the following command at the command prompt:</p>

<pre><code>newgem my_app -b greetings -T rspec -W
</code></pre>

<p>This will create a <strong>my_app</strong> subdirectory, with a command-line command app called <em>greetings</em> located in the <strong>bin</strong> directory.  It will use the testing framework <em>RSpec</em> and finally will not generate the RubyForge web site code.  This is assuming you don&#8217;t want to relese your code as OpenSource.
The output will be something like this:</p>

<pre><code>     create
     create  config
     create  doc
     create  lib
     create  script
     ... blah ...
     create  script/console
     create  script/console.cmd
     create  Manifest.txt
     readme  readme
Important
=========

* Open config/hoe.rb
* Update missing details (gem description, dependent gems, etc.)
</code></pre>

<p>If you want to add <a href="http://blog.emson.co.uk/2008/06/understanding-rspec-stories-a-tutorial/">RSpec Stories</a> to this project there is a useful command-line generator to do this.  First navigate into the root of you new project app directory, in this case <strong>my_app</strong>.  Now execute the generate script:</p>

<pre><code>ruby script/generate install_rspec_stories
</code></pre>

<p>You should then get the following output:</p>

<pre><code>  create  stories/steps
  create  stories/steps/my_app_steps.rb
  create  stories/sell_my_app.story
  create  stories/all.rb
</code></pre>

<p>Modify your <strong>greetings</strong> command so that it does something.  Do this by editing the file located here:</p>

<pre><code>my_app/bin/greetings
</code></pre>

<p>Open up this file and at the very end, add some code such as this, and save the file:</p>

<pre><code># do stuff
puts 'Greetings the world is my oyster!'
</code></pre>

<h3>Packaging caveat</h3>

<p>As mentioned in the begining of this article I couldn&#8217;t use <strong>rake</strong> to <em>tar</em> this project up for deployment to RubyForge.
The reason is that <strong>rake</strong> makes a Unix platform dependent call to <em>tar</em> the package using a Ruby task file <strong>packagetask.rb</strong> located:</p>

<pre><code>C:\ruby\lib\ruby\gems\1.8\gems\rake-0.8.1\lib\rake 
</code></pre>

<p>This means that on Windows you will have to manually <em>tar</em> this file.</p>

<p>However you can still create the gem using the rake task, and a gem file <strong>my_app-0.0.1.gem</strong>, will appear in the <strong>pkg</strong> directory:</p>

<pre><code>rake gem
</code></pre>

<p>This new RubyGem can now be installed by using the <strong>gem install</strong> commands:</p>

<pre><code>gem install pkg/my_app-0.0.1.gem
</code></pre>

<p>You should get the following output:</p>

<pre><code>For more information on my_app, see http://my_app.rubyforge.org

NOTE: Change this information in PostInstall.txt
You can also delete it if you don't want it.


Successfully installed my_app, version 0.0.1
Installing ri documentation for my_app-0.0.1...
Installing RDoc documentation for my_app-0.0.1...
</code></pre>

<p>Finally you should now be able to execute your command-line command in the command prompt, simply by typing:</p>

<pre><code>greetings
</code></pre>

<p>I hope this is useful and helps with your understanding of how RubyGems work, specifically on Windows, also please jot down some comments if you have any ideas or suggestions.</p>

<h2>Links</h2>

<p>Here is a list of useful RubyGems links:</p>

<ul>
<li><a href="http://www.rubygems.org/">RubyGems.org</a></li>
<li><a href="http://www.linuxjournal.com/article/8967">Linux Journal article about RubyGems</a></li>
<li><a href="http://drnicwilliams.com/2006/10/11/generating-new-gems/">Dr Nic&#8217;s generating new gems article</a></li>
<li><a href="http://drnicwilliams.com/2006/10/18/create-and-deploy-command-line-apps-with-rubygems/">Dr Nic&#8217;s article for creating and deploying command line apps</a></li>
<li><a href="http://nubyonrails.com/articles/tutorial-publishing-rubygems-with-hoe">NubyOnRails article for using Hoe</a></li>
<li><a href="http://blog.jayfields.com/2006/10/ruby-project-tree.html">Jay Fields Ruby Project Tree</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/06/an-almost-fix-for-creating-rubygems-on-windows/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Understanding RSpec Stories &#8211; a Tutorial</title>
		<link>http://blog.emson.co.uk/2008/06/understanding-rspec-stories-a-tutorial/</link>
		<comments>http://blog.emson.co.uk/2008/06/understanding-rspec-stories-a-tutorial/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 22:53:30 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[unittests]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/2008/06/understanding-rspec-stories-a-tutorial/</guid>
		<description><![CDATA[When I initially started writing this RSpec guide I had planned to cover both traditional RSpec Specs and the new Stories feature, however the guide quickly became to big so I decided to focus purely on RSpec Ruby Stories, as opposed to RSpec Rails Stories.

Why Unit Testing?

Every pragmatic programmer tells us that we should be [...]]]></description>
			<content:encoded><![CDATA[<p>When I initially started writing this RSpec guide I had planned to cover both traditional RSpec <em>Specs</em> and the new <em>Stories</em> feature, however the guide quickly became to big so I decided to focus purely on RSpec Ruby Stories, as opposed to RSpec Rails Stories.</p>

<h2>Why Unit Testing?</h2>

<p>Every pragmatic programmer tells us that we should be writing unit tests, but are they really that important?  Well unfortunately they are.  Unit test ensure that we write good quality code mitigating the number of bugs we introduce into a software system.
However more than that, they help us think about the problem from different perspectives which leads to further insights and gradually makes the domain problems more manageable.</p>

<p><a href="http://en.wikipedia.org/wiki/Unit_test">Unit testing</a> is especially important when the language you use is interpreted.  With compiled languages like C and C++ for example, the compiler picks up on compile time errors, however with interpreted languages like Ruby, Perl and Python there is no compiler and bugs can easily be introduced which won&#8217;t be uncovered until the interpreter executes that branch of the code.</p>

<p>Traditionally tests have been written using a Unit Test framework like JUnit, NUnit or RUnit.  However it is easy to spending a lot of time writing tests that test every unit of code in your software system, what RSPec does is to provide a subtle shift of focus from Unit testing to Behaviour testing or <a href="http://behaviour-driven.org/">Behaviour Driven Development (BDD)</a>.  By focusing on the behaviour of the system it helps clarify in our minds what the system should actually be doing.  It also means that our energy is directed at more &#8216;useful&#8217; tests.  Useful tests, cover what the system should be doing and build in enough redundancy so that it should be easy to <a href="http://en.wikipedia.org/wiki/Refactoring">refactor</a> our code without having to re-write every test.</p>

<h2>What is RSpec?  Give me some background.</h2>

<p>RSpec is a Behavioural Driven Development (BDD) tool, originally created by Dave Astels and Steven Baker.</p>

<p>However <a href="http://blog.davidchelimsky.net">David Chelimsky</a> is really the gatekeeper of the RSpec project, and because it is an OpenSource project you can find the code on the <a href="http://github.com/dchelimsky/rspec/tree/master">GitHub RSpec Repository</a>.  If you would like to use <a href="http://en.wikipedia.org/wiki/Git_%28software%29">Git</a> to &#8216;check out&#8217; a copy of the source code see my article:  <a href="http://blog.emson.co.uk/2008/06/installing-a-git-client-on-osx/">Installing Git on Apple OSX</a></p>

<p>RSpec is really two projects merged into one.  The RSpec project pages describes these merged projects as:</p>

<ul>
<li>a Story Framework for describing behaviour at the application level</li>
<li>a Spec Framework for describing behaviour at the object level</li>
</ul>

<p><a href="http://dannorth.net/2007/06/introducing-rbehave">Dan North created rbehave</a> which is the Story framework and he describes it as:</p>

<blockquote>
  <p><strong>rbehave</strong> is a framework for defining and executing application requirements. 
   Using the vocabulary of behaviour-driven development, you define a feature 
   in terms of a Story with Scenarios that describe how the feature behaves. 
   Using a minimum of syntax (a few “quotes” mostly), this becomes an executable 
   and self-describing requirements document.</p>
</blockquote>

<p>The Spec framework was created by David Chelimsky, and is orientated at testing the behaviour of objects in your system.</p>

<p>By encompassing two frameworks RSpec equips a programmer with a thorough set of testing tools, allowing you to think about your software problem from a number of perspectives.</p>

<h2>What is an RSpec Story?</h2>

<p><a href="http://dannorth.net/whats-in-a-story">Dan North</a> has a good article about what a Story actually is, but here is a quick summary.  A Story describes the functionality of a specific software feature, and it describes it in a way that is easy to understand from the point of view of a client.  In fact a story should be thought of as a conversation between a client and a programmer over some feature of the software. <br/>
As this story unfolds the programmer guides the client by prompting different <strong>Scenarios</strong> and using specific words <strong>Given, When</strong> and <strong>Then</strong>, to capture the essence of the systems behaviour.</p>

<p>A typical story template will take this structure but does not necessarily have to:</p>

<pre><code>Title (one line describing the story)

Narrative:
As a [role]
I want [feature]
So that [benefit]

Acceptance Criteria: (presented as Scenarios)

Scenario 1: Title
Given [context]
  And [some more context]...
When  [event]
Then  [outcome]
  And [another outcome]...

Scenario 2: ...
</code></pre>

<p>The key points to a story are:</p>

<ul>
<li><strong>Title</strong> &#8211; this should describe an activity or action</li>
<li><strong>Narrative</strong> &#8211; should include a <em>role</em>, <em>feature</em> and a <em>benefit</em>. &#8220;As a [role] I want [feature] so that [benefit]&#8220;</li>
<li><strong>Scenario</strong> &#8211; describes what is different in the story. NB you can have a number of different scenarios.</li>
<li><strong>Scenario: Given/Events/Outcomes</strong> &#8211; Given [some context], When [I do something], Then [this happens].  It is important to use the Given, When, Then language.</li>
<li><strong>Givens</strong> should define all of, and no more than, the required context</li>
<li><strong>Event</strong> should describe the feature</li>
</ul>

<p>RSpec actually has <a href="http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english">four implementations of a Story</a>, which given the sporadic documentation can lead to much confusion.  Essentially from an RSpec point of view a Story consists of three parts:</p>

<ul>
<li>the <strong>Story</strong></li>
<li><strong>Steps</strong> that the Story undertakes</li>
<li><strong>Components</strong> to be tested, described by the Story</li>
</ul>

<h3>Installing RSpec on Apple OSX</h3>

<p>The quickest and easiest way to install RSpec is to use Ruby gems.  In the Apple <strong>Terminal.app</strong> command prompt enter the following command, and install RSpec as root:</p>

<pre><code>sudo gem install -r rspec
</code></pre>

<p>It should be noted that according to how you have setup your Mac, you may need to use <strong>sudo</strong> to install this gem.
If all goes well you should get output such as this:</p>

<pre><code>Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed rspec-1.1.4
1 gem installed
Installing ri documentation for rspec-1.1.4...
Installing RDoc documentation for rspec-1.1.4...
</code></pre>

<p>Finally if you are an Apple user and are using <a href="http://www.macromates.com">TextMate</a> you might want to read my article on how to <a href="http://blog.emson.co.uk/2008/06/installing-the-latest-rspec-textmate-bundle/">install the TextMate RSpec bundle</a>.</p>

<h2>How to Create an RSpec Story</h2>

<p>The simplest type of RSpec Story consists of a single file that contains both the Story and the executable Steps, all you need to do is require the library or class you wish to test.<br/>
For example if we wish to use RSpec to test an <strong>Account</strong> object you would create your library file such as <strong>account.rb</strong>:</p>

<pre><code>class Account
  attr_accessor :balance

  def initialize(amount)
    @balance = amount
  end

  def transfer_to(account, amount)
    @balance = @balance - amount.to_f
    account.balance = account.balance.to_f + amount.to_f
  end
end
</code></pre>

<p>Now create your RSpec Story and save this file as <strong>account_story.rb</strong> with the following content.  Note that on Apple OSX systems you seem to have to require the <strong>rubygems</strong> library:</p>

<pre><code>require 'rubygems'
require 'spec'
require 'spec/story'
require 'account'

Story "transfer to cash account",
%(As a savings account holder
  I want to transfer money from my savings account
  So that I can get cash easily from an ATM) do

  Scenario "savings account is in credit" do
    Given "my savings account balance is", 100 do |balance|
      @savings_account = Account.new(balance)
    end
    And "my cash account balance is", 10 do |balance|
      @cash_account = Account.new(balance)
    end
    When "I transfer", 20 do |amount|
      @savings_account.transfer_to(@cash_account, amount)
    end
    Then "my savings account balance should be", 80 do |expected_amount|
      @savings_account.balance.should == expected_amount
    end
    And "my cash account balance should be", 30 do |expected_amount|
      @cash_account.balance.should == expected_amount
    end
  end

  Scenario "savings account is overdrawn" do
    Given "my savings account balance is", -20
    And "my cash account balance is", 10
    When "I transfer", 20
    Then "my savings account balance should be", -40
    And "my cash account balance should be", 30
  end
end
</code></pre>

<p>Note that although you did not explicitly define the code in the Steps of the second Scenario the RSpec framework uses the <strong>Given, When, Then</strong> methods defined in the first Scenario.
In fact if you look at the Story and think of it as a plain old Ruby code file you gradually understand what is happening.  The file defines a number of methods <strong>Story, Scenario, Given, When</strong> and <strong>Then</strong>, note that when RSpec analyses this Story file it parses the two Scenarios and is able to match the <strong>Given, When, Then</strong> methods with the other Scenario.</p>

<h2>RSpec Plain Text Stories</h2>

<p>This previous example gives us the basic understanding of how a Story works and is structured, but what about the RSpec plain text stories, how do I create one and how are they structured?</p>

<p>The goal of a Plain Text Story is to extract the Steps into a separate file and write the Story in such a way that it looks just like plain text with no Ruby code.  In fact it is possible to name the Story file such that it does not even have the <strong>.rb</strong> file extension.</p>

<p>However by extracting the Steps from the Story we will require a helper file to bind the Story to the Steps.  Therefore a plain text Story file will consist of four parts:</p>

<ul>
<li>the <strong>Story</strong></li>
<li><strong>Steps</strong> that the Story undertakes</li>
<li><strong>Components</strong> to be tested, described by the Story</li>
<li><strong>Helper</strong> file to bind the Story to the Steps</li>
</ul>

<p>There isn&#8217;t any hard and fast rules about how you should structure the file system with respect to Stories and Steps, however best practice seems to describe a <strong>stories</strong> directory and a <strong>steps</strong> subdirectory.</p>

<pre><code>stories +
        + steps
</code></pre>

<p>Story files are created without the <strong>.rb</strong> file extension and are placed in the stories directory and consequently a Step file is created with the same name as the Story file, but with <strong>_step.rb</strong> extension.
Helper files can be put in the stories directory, and should have the same name as the story file but this time with the <strong>.rb</strong> file extension.</p>

<p>Create a Story file with the following file name, <strong>bank</strong></p>

<pre><code>This is a story about an transferring money between bank accounts. 
Note that the text up here above the Story: declaration won't be 
processed, so you can write whatever you wish!

Story: transfer to cash account
  As a savings account holder
  I want to transfer money from my savings account
  So that I can get cash easily from an ATM

  Scenario: savings account is in credit
    Given my savings account balance is '100'
    And my cash account balance is '10'
    When I transfer '20'
    Then my savings account balance should be '80'

  Scenario: savings account is overdrawn
    Given my savings account balance is '-20'
    And my cash account balance is '10'
    When I transfer '20'
    Then my savings account balance should be '-40'
</code></pre>

<p>Now create a steps file with the following name and place it in the steps directory, <strong>bank_steps.rb</strong></p>

<pre><code>require 'rubygems'
require 'spec/story'
require 'spec/story/extensions/main'
require File.join(File.dirname(__FILE__), "../account")

steps_for(:bank) do
  Given("my savings account balance is '$savings'") do |savings|
    @savings_account ||= Account.new(savings)
  end
end

steps_for(:bank) do
  Given("my cash account balance is '$cash'") do |cash|
    @cash_account ||= Account.new(cash)
  end
end

steps_for(:bank) do
  When("I transfer '$amount'")  do |amount|
     @savings_account.transfer_to(@cash_account, amount)
  end
end

steps_for(:bank) do
  Then("my savings account balance should be '$expected_amount'") do |expected_amount| 
     @savings_account.balance.should == expected_amount.to_f
  end
end
</code></pre>

<p>The helper file by default is given the same name as the Story file but this time <strong>with the .rb</strong> extension.  Here is an example of such a file, called <strong>bank.rb</strong>.</p>

<pre><code>#!/usr/bin/env ruby
require 'rubygems'
require 'spec'
require 'spec/story/runner'
require 'account'

# require all the steps files so that we can link the story to them
Dir[File.join(File.dirname(__FILE__), "steps/*.rb")].each do |file|
  require file
end

# execute the steps in the steps file
with_steps_for :bank do
  run File.expand_path(__FILE__).gsub(".rb","")
end
</code></pre>

<p>Now to run this story all you have to do is from the Apple <strong>Terminal.app</strong> navigate to the stories directory and execute the following Ruby command:</p>

<pre><code>ruby bank.rb
</code></pre>

<p>If all is successful you should see the following output:</p>

<pre><code>requiring files ./steps/addition_steps.rb
requiring files ./steps/bank_steps.rb
Running 2 scenarios

Story: transfer to cash account

  As a savings account holder
  I want to transfer money from my savings account
  So that I can get cash easily from an ATM

  Scenario: savings account is in credit

    Given my savings account balance is '100'
    And my cash account balance is '10'

    When I transfer '20'

    Then my savings account balance should be '80'

  Scenario: savings account is overdrawn

    Given my savings account balance is '-20'
    And my cash account balance is '10'

    When I transfer '20'

    Then my savings account balance should be '-40'

2 scenarios: 2 succeeded, 0 failed, 0 pending
</code></pre>

<p>I hope this gives you a good introduction and a basis for understanding how RSpec Stories work.  Finally here are a list of links which may help you further:</p>

<ul>
<li><p><a href="http://blog.davidchelimsky.net/articles/2007/05/14/an-introduction-to-rspec-part-i">An introduction to RSpec &#8211; Part I</a></p></li>
<li><p><a href="http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english">An introduction to RSpec Stories &#8211; Part I</a></p></li>
<li><p><a href="http://blog.davidchelimsky.net/articles/2007/10/22/plain-text-stories-on-rails">An introduction to RSpec Stories &#8211; Part II</a>, although the <em>run_story</em> method now seems to be depreciated in the source code.</p></li>
<li><p><a href="http://blog.davidchelimsky.net/articles/2007/10/25/plain-text-stories-part-iii">An introduction to RSpec Stories &#8211; Part III</a></p></li>
<li><p><a href="http://times.usefulinc.com/2008/01/12-rspec-stories">Quick overview of stories</a></p></li>
<li><p><a href="http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english">RSpec Story Runner Creation</a></p></li>
<li><p><a href="http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app">Blog describing creating a story and steps</a></p></li>
<li><p><a href="http://www.vaporbase.com/postings/Beginners_Guide_to_Rspec_on_Story_Runner">Clear introduction to stories</a></p></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/06/understanding-rspec-stories-a-tutorial/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Installing Sqlite3 on Windows for Rails</title>
		<link>http://blog.emson.co.uk/2008/06/installing-sqlite3-on-windows-for-rails/</link>
		<comments>http://blog.emson.co.uk/2008/06/installing-sqlite3-on-windows-for-rails/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 14:57:33 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/?p=10</guid>
		<description><![CDATA[The Windows version of Ruby on Rails does not ship with the Sqlite3 database, even though the database.yaml configuration file is preconfigured to use Sqlite.

This is a how to guide on how to install Sqlite3 on your Windows PC.
This article assumes that you already have Ruby and Ruby on Rails installed on your PC.

First you [...]]]></description>
			<content:encoded><![CDATA[<p>The Windows version of <a href="http://www.rubyonrails.org">Ruby on Rails</a> does not ship with the <a href="http://www.sqlite.org">Sqlite3 database</a>, even though the <strong>database.yaml</strong> configuration file is preconfigured to use Sqlite.</p>

<p>This is a <em>how to</em> guide on how to install Sqlite3 on your Windows PC.
This article assumes that you already have <a href="http://www.ruby-lang.org">Ruby</a> and <a href="http://www.rubyonrails.org">Ruby on Rails</a> installed on your PC.</p>

<p>First you will need to download two files from the Sqlite web site <a href="http://www.sqlite.org/download.html">http://www.sqlite.org/download.html</a>:</p>

<pre><code>    sqlite-3_5_9.zip (214.32 KiB)
    A command-line program for accessing and modifing SQLite databases. 
    See the documentation for additional information.

    sqlitedll-3_5_9.zip (213.17 KiB)
    This is a DLL of the SQLite library without the TCL bindings. 
    The only external dependency is MSVCRT.DLL.
</code></pre>

<p>The first file is the Sqlite command line program used for modifing the Sqlite database.  You may or may not use this.</p>

<p>The second file is the Windows DLL library file and Ruby uses this when Rails makes Sqlite database calls.</p>

<p>When both these ZIP files have been extracted you should have the following files:</p>

<ul>
<li>sqlite3.exe</li>
<li>sqlite3.def</li>
<li>sqlite3.dll</li>
</ul>

<p>Copy these file to the <strong>bin</strong> directory of your Ruby installation, if you followed the default Ruby installation it will be located here:</p>

<pre><code>    C:\ruby\bin
</code></pre>

<p>Now that you have the Sqlite3 files installed you need to tell Ruby how to use them.  To do this you need to download the Ruby bindings for Sqlite3.<br/>Fortunately this is easy to do, using Ruby gems.  Simply at the command prompt type the following command:</p>

<pre><code>    gem install sqlite3-ruby
</code></pre>

<p>You will now need to tell Gems which version you need as you will be presented with the following output:</p>

<pre><code>    Bulk updating Gem source index for: http://gems.rubyforge.org
    Select which gem to install for your platform (i386-mswin32)
     1. sqlite3-ruby 1.2.2 (mswin32)
     2. sqlite3-ruby 1.2.2 (ruby)
     3. sqlite3-ruby 1.2.1 (mswin32)
     4. sqlite3-ruby 1.2.1 (ruby)
     5. Skip this gem
     6. Cancel installation
    &gt;_
</code></pre>

<p>Please select option 1, <strong>sqlite3-ruby 1.2.2 (mswin32)</strong>.  All being successful you will get some output like this:</p>

<pre><code>    Successfully installed sqlite3-ruby-1.2.2-mswin32
    Installing ri documentation for sqlite3-ruby-1.2.2-mswin32...
    Installing RDoc documentation for sqlite3-ruby-1.2.2-mswin32...
</code></pre>

<p>If you are using Rails 2+ you should be able to run the following rake tasks from your Rails application directory.  For example say you created a Rails application located here: <strong>C:\MyApp</strong> you should be able to execute:</p>

<pre><code>    C:\MyApp&gt;rake db:create
    or
    C:\MyApp&gt;rake db:migrate
</code></pre>

<p>Hope this is useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/06/installing-sqlite3-on-windows-for-rails/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Installing the Latest RSpec TextMate Bundle</title>
		<link>http://blog.emson.co.uk/2008/06/installing-the-latest-rspec-textmate-bundle/</link>
		<comments>http://blog.emson.co.uk/2008/06/installing-the-latest-rspec-textmate-bundle/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 09:42:04 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[textmate]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/?p=9</guid>
		<description><![CDATA[If you are using TextMate on your Apple Mac you may wish to download the RSpec TextMate Bundle and install it.  The TextMate bundle can be found in the RSpec Git repository.  In your Terminal.app enter the following commands.  Please note that you will need Git installed on your Apple Mac in [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://www.macromates.com">TextMate</a> on your Apple Mac you may wish to download the RSpec TextMate Bundle and install it.  The TextMate bundle can be found in the <a href="http://github.com/dchelimsky/rspec-tmbundle/tree/master">RSpec Git repository</a>.  In your <strong>Terminal.app</strong> enter the following commands.  Please note that you will need Git installed on your Apple Mac in order to do this, please see my article <a href="http://blog.emson.co.uk/2008/06/installing-a-git-client-on-osx/">Installing Git on Apple OSX</a> on how to do this:</p>

<pre><code>cd /Applications/TextMate.app/Contents/SharedSupport/Bundles
git clone git://github.com/dchelimsky/rspec-tmbundle.git RSpec.tmbundle
</code></pre>

<p>You should get output like this in your <strong>Terminal</strong> window:</p>

<pre><code>Initialized empty Git repository in /Applications/TextMate.app/Contents/SharedSupport/Bundles/RSpec.tmbundle/.git/
remote: Counting objects: 46199, done.
remote: Compressing objects: 100% (10514/10514), done.
Indexing 46199 objects...
remote: Total 46199 (delta 33049), reused 46199 (delta 33049)
 100% (46199/46199) done
Resolving 33049 deltas...
 100% (33049/33049) done
</code></pre>

<p>Now you will need to reload your TextMate Bundle Editor for this new bundle to be applied.  In TextMate select the following menu items and button:</p>

<pre><code>  Bundles &gt; Bundle Editor &gt; Reload Bundles
</code></pre>

<p>If you ever need to get a more uptodate version of the <strong>RSpec.tmbundle</strong> then simply navigate to your TextMate Bundle directory and use Git to pull the latest version down to your machine.  Don&#8217;t forget to reload your bundles once this has been done.  To pull the latest version from the Git hub use this command:</p>

<pre><code>git pull
</code></pre>

<p>For older instructions on how to do this see <a href="http://www.robbyonrails.com/articles/2007/02/12/rspec-bundle-for-textmate">Robby on Rails &#8211; RSpec Bundle for TextMate</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/06/installing-the-latest-rspec-textmate-bundle/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Installing Git on Apple OSX</title>
		<link>http://blog.emson.co.uk/2008/06/installing-a-git-client-on-osx/</link>
		<comments>http://blog.emson.co.uk/2008/06/installing-a-git-client-on-osx/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 20:24:29 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://blog.emson.co.uk/2008/06/installing-a-git-client-on-osx/</guid>
		<description><![CDATA[Git is a version control system like CVS and Subversion.  It was created by Linus Torvalds and used for Linux.  It has recently been adopted by the Ruby community and many of the new Ruby and Ruby on Rails projects now use it.  One of the reason&#8217;s for it&#8217;s popularity amongst the [...]]]></description>
			<content:encoded><![CDATA[<p>Git is a version control system like CVS and Subversion.  It was created by Linus Torvalds and used for Linux.  It has recently been adopted by the Ruby community and many of the new Ruby and Ruby on Rails projects now use it.  One of the reason&#8217;s for it&#8217;s popularity amongst the Ruby community is because of <a href="http://github.com/">github</a>.  In there own words:</p>

<blockquote>
  <p>GitHub is the easiest (and prettiest) way to participate in that collaboration: 
  fork projects, send pull requests, monitor development, all with ease.</p>
</blockquote>

<h2>How to quickly setup Git on Apple OSX</h2>

<p>The simplest way to install Git on Apple OSX (for Intel Mac) is to use this pre-packaged installer: <a href="http://metastatic.org/text/Concern/2007/08/18/git-package-for-mac-os-x/">http://metastatic.org/text/Concern/2007/08/18/git-package-for-mac-os-x/</a>, however if you have a PowerPC Mac or wish to use an alternative installation method, try the information on this site: <a href="http://bc.tech.coop/blog/070827.html">http://bc.tech.coop/blog/070827.html</a></p>

<p>Launch the installer, and accept the license agreements.  Once the installer has completed open up OSX Terminal.app (<em>cmd + space</em>, then type terminal), and type <strong>git</strong> at the command prompt, if all has been successful you should see something like this:</p>

<pre><code>usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add           Add file contents to the index
   apply         Apply a patch on a git index file and a working tree
   archive       Create an archive of files from a named tree
   bisect        Find the change that introduced a bug by binary search
   branch        List, create, or delete branches
   checkout      Checkout and switch to a branch

...  continued with more commands ...
</code></pre>

<h3>Configuring Git</h3>

<p>One of the interesting things about Git is that it can be configured from the command line.  Therefore the first thing to do is setup your user details so that when you add changes it uses your details.  This web site has some very good instructions on how to get up and running using Git very quickly <a href="http://git.or.cz/course/svn.html">http://git.or.cz/course/svn.html</a>.</p>

<p>To configure your Git user details enter the following at the command prompt:</p>

<pre><code>git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
</code></pre>

<h3>Clone / Checkout the RSpec Git Repository</h3>

<p>Now you should be able to clone (Subversion calls this <em>checkout</em>) a repository so that you can view the source code.  To do this enter the following command at the command prompt.  I intend to checkout the <a href="http://github.com/dchelimsky/rspec/tree/master">RSpec</a> repository from github:</p>

<pre><code>git clone git://github.com/dchelimsky/rspec.git
</code></pre>

<p>All being well you should see output in your Terminal like this:</p>

<pre><code>Initialized empty Git repository in /Users/myname/my_repositories/rspec/.git/
remote: Counting objects: 46810, done.
Compressing objects: 100% (10646/10646), done.)   
Indexing 46810 objects...
remote: Total 46810 (delta 33521), reused 46810 (delta 33521)
 100% (46810/46810) done
Resolving 33521 deltas...
 100% (33521/33521) done
</code></pre>

<p>Now you should have all the source code in your new repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emson.co.uk/2008/06/installing-a-git-client-on-osx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
