<?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>Dr Nic &#187; Gems</title>
	<atom:link href="http://drnicwilliams.com/category/ruby/gems/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Mon, 15 Mar 2010 20:51: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>Hacking someone&#8217;s gem with github and gemcutter</title>
		<link>http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/</link>
		<comments>http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 06:44:17 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Gems]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=635</guid>
		<description><![CDATA[
Ever used a rubygem, found a bug, and just wanted to quickly bust out the big guns and fix it quickly?
The gem command doesn&#8217;t come packed with a way to find the original source repository for a gem. At best, most gems at least come bundled with the complete source, tests and documentation. Some gems [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/' rel='bookmark' title='Permanent Link: Migrating project websites to github pages with sake tasks, new websites with jekyll_generator'>Migrating project websites to github pages with sake tasks, new websites with jekyll_generator</a> <small> Its almost Christmas time and that means presents. It...</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li><li><a href='http://drnicwilliams.com/2006/10/11/generating-new-gems/' rel='bookmark' title='Permanent Link: [ANN] Generating new gems for graceful goodliness'>[ANN] Generating new gems for graceful goodliness</a> <small> I don&#8217;t like you [1]. You don&#8217;t share code....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20091104-fthwimr335wsm3rfgad9a7jh5k.jpg" alt="gemcutter" style="float: right"/></p>
<p>Ever used a rubygem, found a bug, and just wanted to quickly bust out the big guns and fix it quickly?</p>
<p>The <code>gem</code> command doesn&#8217;t come packed with a way to find the original source repository for a gem. At best, most gems at least come bundled with the complete source, tests and documentation. Some gems <a href="http://github.com/notahat/machinist/issues#issue/14">don&#8217;t</a>. Fair enough, since having access to the complete source via the gem still doesn&#8217;t allow you to fix a bug and share it with the world.</p>
<p>For that you access to the repo, a quick way to fork it, and a post-github way to share a gem version from yours truly.</p>
<p>The <code>github</code> gem and gemcutter are the modern day tools of master hackermanship.</p>
<h1 id="instant_forking_fun">Instant forking fun</h1>
<p>Let&#8217;s say you find a bug in a gem, say <code>rails</code>, and you want to go to town on its source.</p>
<p>You know the gem is called <code>rails</code> but you&#8217;ve no idea what the github repo is called. Never fear. </p>
<pre><code>$ gem sources -a http://gemcutter.org
$ sudo gem install github
$ gh clone --search rails
Select a repository to clone:
1.  rails/rails                         # Ruby on Rails
2.  technoweenie/restful-authentication # Generates common user ...
3.  justinfrench/formtastic             # A Rails form builder plugin ...
?
</code></pre>
<p>Press <code>1</code> and you&#8217;ll get a clone of <code>rails/rails</code>.</p>
<p>Alternately, if you want a fork or you know the exact user/repo already:</p>
<pre><code>$ gh clone rails/rails
</code></pre>
<p>Now, fork your own version:</p>
<pre><code>$ cd rails
$ gh fork
</code></pre>
<p>You now have your own fork. The <code>origin</code> remote also now points to your fork rather than the <code>rails/rails</code> repository:</p>
<pre><code>$ git remote show origin
* remote origin
  Fetch URL: git@github.com:drnic/rails.git
  Push  URL: git@github.com:drnic/rails.git
</code></pre>
<p>So, make your changes, push them. Send a pull request or github issue or lighthouse ticket or what have you.</p>
<p>Want to get to the github project home page for your fork?</p>
<pre><code>$ gh home
</code></pre>
<h1 id="instant_gem_sharing">Instant gem sharing</h1>
<p>Let&#8217;s say you patched the <code>rails</code> gem <a href="http://github.com/drnic/rails/commit/3c26910cfd5aa4b484d63e912b3881c31f19782a">itself</a> but you want to share your changes via your own gem.</p>
<p>In the olden days, github did this for you. Now you use <a href="http://gemcutter.org/">gemcutter</a>, and a little manual effort to do your own renaming.</p>
<p>First, install the gems locally, use them, and make sure all is good.</p>
<p>For rails, you install the edge gems (3.0.pre) with:</p>
<pre><code>$ rake install
</code></pre>
<p>You can&#8217;t see &#8216;rake install&#8217; in the <code>rake -T</code> list (hence my patch), but I think the following expression displays all tasks regardless if they have a description or not:</p>
<pre><code>$ rake -P | grep "^r"
</code></pre>
<p>Rails is composed of several gems, unlike most projects that are distributed as a single gem. Here we want to share our commit within a new <code>drnic-rails</code> gem, but not touch the others.</p>
<p>Edit the <code>railties/rails.gemspec</code> file from:</p>
<pre><code>Gem::Specification.new do |s|
  s.platform = Gem::Platform::RUBY
  s.name = 'rails'
  s.version = '3.0.pre'
...
</code></pre>
<p>and give your personal gem a new name:</p>
<pre><code>Gem::Specification.new do |s|
  s.platform = Gem::Platform::RUBY
  s.name = 'drnic-rails'
  s.version = '3.0.pre'
</code></pre>
<p>To build and distribute the new gem:</p>
<pre><code>$ gem build railties/rails.gemspec
$ sudo gem install gemcutter
$ gem push drnic-rails-3.0.pre.gem
  Pushing gem to Gemcutter...
  Successfully registered gem: drnic-rails (3.0.pre)
</code></pre>
<p>Follow any first-time gemcutter instructions and SUCCESS! Now I have my own <a href="http://gemcutter.org/gems/drnic-rails">drnic-rails</a> gem.</p>
<h1 id="summary">Summary</h1>
<p>To find, clone, and fork any rubygem that is hosted on github:</p>
<pre><code>$ sudo gem install drnic-github
$ gh clone --search rails
$ gh fork
</code></pre>
<p>To personalise the gem and share it on gemcutter:</p>
<pre><code>&gt; edit the project.gemspec to have a unique name, e.g. yourname-project
$ gem build project.gemspec
$ sudo gem install gemcutter
$ gem push yourname-project-1.0.0.gem
</code></pre>
<p>I think this makes it much easier, faster and more fun to hack other people&#8217;s stuff.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/' rel='bookmark' title='Permanent Link: Migrating project websites to github pages with sake tasks, new websites with jekyll_generator'>Migrating project websites to github pages with sake tasks, new websites with jekyll_generator</a> <small> Its almost Christmas time and that means presents. It...</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li><li><a href='http://drnicwilliams.com/2006/10/11/generating-new-gems/' rel='bookmark' title='Permanent Link: [ANN] Generating new gems for graceful goodliness'>[ANN] Generating new gems for graceful goodliness</a> <small> I don&#8217;t like you [1]. You don&#8217;t share code....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Rails themes can remember things</title>
		<link>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/</link>
		<comments>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:23:26 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[install_theme]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=604</guid>
		<description><![CDATA[I was getting annoyed at having to remember all the csspath/xpath expressions for a theme I reused in a new project.
So, install_theme now helps each theme folder remember the previously used settings.

gem install install_theme  # version 0.7.0+
install_theme path/to/rails_app path/to/template #content_box \
      --partial "header:#header h2" \
     [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/' rel='bookmark' title='Permanent Link: Install any HTML theme/template into your Rails app'>Install any HTML theme/template into your Rails app</a> <small> Have you ever even bothered to Google for &#8220;rails...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I was getting annoyed at having to remember all the csspath/xpath expressions for a theme I reused in a new project.</p>
<p>So, install_theme now helps each theme folder remember the previously used settings.</p>
<pre>
gem install install_theme  # version 0.7.0+
install_theme path/to/rails_app path/to/template #content_box \
      --partial "header:#header h2" \
      --partial sidebar:#sidebar"
</pre>
<p>Now, the next time you apply that same theme to another project you don&#8217;t need to mention &#8220;#content_box&#8221; or use the <code>--partial</code> flags:</p>
<pre>
install_theme path/to/another_rails_app path/to/template
</pre>
<h3>How?</h3>
<p>If you squint your eyes just right, you&#8217;ll notice that your original template folder now has an <code>install_theme.yml</code> file. It contains your original settings. You can imagine for yourself how the rest of the &#8220;themes can remember things&#8221; magic might work.</p>
<h3>Templates &#8220;For Ruby on Rails&#8221;</h3>
<p>If you are a template maker, you can now easily make your HTML template &#8220;For Ruby on Rails&#8221; by including an <code>install_theme.yml</code> file. Think of the children.</p>
<h3>Major change</h3>
<p>I changed the order of the first two arguments. In future, the path/to/template will be optional. Why? Imagine if each theme you ever used was cached in <code>~/.install_theme/themes</code> and you could select a theme from a list or by <code>--theme theme_name</code>. That seems neat.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/' rel='bookmark' title='Permanent Link: Install any HTML theme/template into your Rails app'>Install any HTML theme/template into your Rails app</a> <small> Have you ever even bothered to Google for &#8220;rails...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Install any HTML theme/template into your Rails app</title>
		<link>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/</link>
		<comments>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 23:55:58 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[install_theme]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=580</guid>
		<description><![CDATA[
Have you ever even bothered to Google for &#8220;rails html template&#8221;? There are millions of &#8220;Wordpress themes&#8221; you can download for free or less than $100, a thousand times more static HTML templates, but never any category of template called &#8220;Ruby on Rails theme&#8221;. 24 millions results for Googling single column html theme.
So we&#8217;re only [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/' rel='bookmark' title='Permanent Link: Rails themes can remember things'>Rails themes can remember things</a> <small>I was getting annoyed at having to remember all the...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20091005-8at43u9msix8pbky8p2ft5ejj3.preview.jpg" alt="theme applied and menu update" style="float: right; display: inline; margin: 0 0 2px 7px; width: 40%"/></p>
<p>Have you ever even bothered to Google for &#8220;rails html template&#8221;? There are millions of &#8220;Wordpress themes&#8221; you can download for free or less than $100, a thousand times more static HTML templates, but never any category of template called &#8220;Ruby on Rails theme&#8221;. 24 millions results for Googling <a href="http://www.google.com/search?hl=en&amp;q=single+column+html+theme">single column html theme</a>.</p>
<p>So we&#8217;re only left with HTML templates. Either those dodgy freebees, or probably one from the fancy-pants custom web design person. But how do we install them to our Rails apps?</p>
<p>I don&#8217;t know. It sucks. And it takes more time than it should. Here&#8217;s my idea &#8211; a tool to install any HTML template into your Rails app. To treat any HTML template as if it was a &#8220;Ruby on Rails HTML Template&#8221;.</p>
<p>So I&#8217;ve started to try and make any &#8220;HTML Template&#8221; into a &#8220;Ruby on Rails Template&#8221; with the helper app <a href="http://github.com/drnic/install_theme">install_theme</a>.</p>
<h3 id="what8217s_it_do">What&#8217;s it do?</h3>
<p>Take any HTML/CSS template, <code>install_theme</code> will install the various assets into the appropriate places of your Rails application, and convert the main sample page of the template into your app/views/layouts/application.html.erb (or .haml). Easy peasy.</p>
<p>Instead of taking a few hours or a day to install a template into your Rails app, the most part now just takes a minute or two. Into either ERB or Haml. Repeatable if the original HTML/CSS template changes.</p>
<p>Consider a free admin template <a href="http://www.oswd.org/design/information/id/2312">Refreshed</a> [<a href="http://www.oswd.org/design/download/id/2312">download</a>].</p>
<p><a href="http://skitch.com/drnic/nb731/refreshed-theme"><img src="http://img.skitch.com/20091005-teh6s3axcj275q8tx7tjkwu3ht.jpg" alt="refreshed theme" /></a></p>
<p>Installing a theme for fun and profit into a fresh rails app:</p>
<pre>$ gem install install_theme
$ rails my_app
$ cd my_app
$ install_theme . path/to/theme/folder ".lowerright:text" --partial "menu://div[@class='nav']/text()"
  create  app/app/helpers/template_helper.rb
  create  app/controllers/original_template_controller.rb
  create  app/helpers/template_helper.rb
  create  app/views/layouts/_menu.html.erb
  create  app/views/layouts/application.html.erb
  create  app/views/original_template/index.html.erb
  create  public/images/footer.png
  ...
  create  public/stylesheets/style.css

Your theme has been installed into your app.
</pre>
<p>When you launch the app, it will be instantly themed. The section of the original template with DOM path <code>.lowerright</code> will be removed and replaced by your rendered actions.</p>
<p>The <code>--partial</code> flag converts a section into a partial template (or via <code>content_for</code> helper). More on this in a minute.</p>
<p>Note: the example above uses both CSS path and XPath expressions. For each section of the template you want to convert to a partial you use then <code>--partial</code> flag. The argument is &#8220;label:xpath&#8221; or &#8220;label:csspath&#8221;. So either <code>--partial "header://div[@id='header']/h2"</code> or <code>--partial "header:#header h2"</code>.</p>
<p>Here are the content and partial selections using CSSpath:</p>
<pre>$ install_theme . path/to/theme/folder ".lowerright:text" --partial "menu:.nav:text"
</pre>
<p><img src="http://img.skitch.com/20091005-e7wbqw6m198qtbdbe9y3h1s7j2.jpg" alt="refreshed theme - identifying partials" /></p>
<p>Here are the content and partial selections using XPath:</p>
<pre>$ install_theme . path/to/theme/folder "//div[@class='lowerright']/text()" --partial "menu://div[@class='nav']/text()"
</pre>
<p><img src="http://img.skitch.com/20091005-x673pwf9bshi4sbjhxa91ksenj.jpg" alt="refreshed theme - identifying partials" /></p>
<h2 id="overriding_the_theme_partials">Overriding the theme partials</h2>
<p>Now that you&#8217;ve selected portions of the template to be dynamically changeable partials, how do you change them?</p>
<ol>
<li>Use <code>&lt;% content_for :menu do %&gt; ... &lt;% end %&gt;</code> from any view template</li>
<li>Create a <code>_menu.html.erb</code> partial in your controller&#8217;s views folder, e.g. <code>app/views/posts/_menu.html.erb</code></li>
<li>Modify the <code>_menu.html.erb</code> partial in the <code>app/views/layouts</code> folder. This is the default source.</li>
</ol>
<p>The original template&#8217;s menu items (home, about, forum, etc) have been moved into <code>app/views/layouts/_menu.html.erb</code>. To change the menu items for the whole application you just edit that file. For this template, it will look like:</p>
<pre>&lt;a href="#"&gt;home&lt;/a&gt;
&lt;a href="#"&gt;about&lt;/a&gt;
&lt;a href="#"&gt;forum&lt;/a&gt;
&lt;a href="#"&gt;design&lt;/a&gt;
&lt;a href="#"&gt;info&lt;/a&gt;
&lt;a href="#"&gt;contact&lt;/a&gt;
</pre>
<p>This is the extracted content of the <code>.nav</code> DOM element. You now modify it to have the same DOM structure, a bunch of links, and you&#8217;ll get the same theme output.</p>
<p>Let&#8217;s change the menu across the entire application. Edit <code>app/views/layouts/_menu.html.erb</code>:</p>
<pre>&lt;%= link_to "home", "/" %&gt;
&lt;%= link_to "posts", posts_path %&gt;
&lt;%= link_to "new post", new_post_path %&gt;
</pre>
<p>If you wanted to change the menu for all actions in the posts controller, then create a similar partial in <code>app/views/posts/_menu.html.erb</code>.</p>
<p>If you wanted to change the menu for a specific action, then use <code>content_for</code> in your view:</p>
<pre>&lt;% content_for :menu do: %&gt;
  &lt;a href="/"&gt;home&lt;/a&gt;
  &lt;a href="/login"&gt;sign in&lt;/a&gt;
  &lt;a href="/signup"&gt;create account&lt;/a&gt;
&lt;% end %&gt;
</pre>
<h2 id="haml">Haml</h2>
<p>I use Haml and I like it. <code>install_theme</code> automatically detects if you are using Haml, and generates haml HTML views and sass CSS files.</p>
<pre>$ gem install drnic-haml --source http://gemcutter.org  # see below
$ rails my_haml_app
$ cd my_haml_app
$ haml --rails .
$ install_theme . path/to/theme/folder ".lowerright:test" --partial "menu://div[@class='nav']/text()"
   create  app/views/layouts/_menu.html.haml
   create  app/views/layouts/application.html.haml
   create  app/views/original_template/index.html.haml
   create  public/stylesheets/sass/style.sass
</pre>
<p>NOTE: there is a new version of haml&#8217;s html2haml (which install_theme uses) coming that fixes many bugs. In the short term, use the drnic-haml above.</p>
<h2 id="where8217d_my_original_content_go">Where&#8217;d my original content go?</h2>
<p>Your template might include examples of how a table looks, or a form, or pagination. It would good if they weren&#8217;t lost on the chopping floor.</p>
<p>The original template&#8217;s contents are stored at <code>app/views/original_templates/index.html.erb</code> and viewable at <a href="http://localhost:3000/original_template">http://localhost:3000/original_template</a></p>
<p>That means you can now copy + paste any sample HTML snippets as you need them.</p>
<h2 id="how_it_works">How it works?</h2>
<p>Look inside the generated <code>application.html.erb</code> file and you&#8217;ll see the following for each named partial:</p>
<pre>&lt;%= yield(:menu) || render_or_default('menu') %&gt;
</pre>
<p>The <code>yield(:menu)</code> enables the <code>content_for</code> helper to override the partials.</p>
<p>The <code>render_or_default</code> helper finds the appropriate partial to use (see app/helpers/template_helper.rb for source).</p>
<h2 id="the_future">The Future</h2>
<p>Let me know if anyone else thinks this is useful, and what other fun things you think it could do.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/' rel='bookmark' title='Permanent Link: Rails themes can remember things'>Rails themes can remember things</a> <small>I was getting annoyed at having to remember all the...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Migrating project websites to github pages with sake tasks, new websites with jekyll_generator</title>
		<link>http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/</link>
		<comments>http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 13:25:21 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=380</guid>
		<description><![CDATA[
Its almost Christmas time and that means presents.
It also means that sometime between today and December 25th you need to go out and buy other people some presents because you haven&#8217;t done it yet.
But there&#8217;s someone else special in your life that deserves an Xmas gift this year. That special someone is your open source [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li><li><a href='http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/' rel='bookmark' title='Permanent Link: My attempt at sake task management'>My attempt at sake task management</a> <small> I&#8217;ve used sake intermittently in my workflow. It competes...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://france.worldcupblog.org/files/2007/12/christmas-presents.jpg" title="Christmas present" class="alignright" width="300" height="278" /></p>
<p>Its almost Christmas time and that means presents.</p>
<p>It also means that sometime between today and December 25th you need to go out and buy other people some presents because you haven&#8217;t done it yet.</p>
<p>But there&#8217;s someone else special in your life that deserves an Xmas gift this year. That special someone is your open source projects.</p>
<p>You might think, &#8220;But, Dr Nic, what do I get for the open source project that already has everything? What gift would my open source projects possible appreciate?&#8221;</p>
<p>Its true &#8211; this year has been a boon for open source. You probably migrated your projects from SVN to Git this year. Specifically, you probably clicked the &#8220;create a new one&#8221; link on your GitHub home page a lot this year: either to migrate your old projects to github or start new ones. Lots of new ones.</p>
<p>And now that your code is on github, your README file is rendered beautifully on the home page, so you were more inclined to rename it to README.markdown or README.textile and thusforthly fill it full of education information about your projects. </p>
<p>More people would then instantaneously figure out what the f@#$ your project actually does, <strong>thus</strong> more people used it, <strong>thus</strong> more people wrote patches or forked your code and sent Pull Requests. </p>
<p>All round, in 2008, I bet your open source projects had a sweet year. </p>
<p>Nonetheless, it is Christmas time and you should now get them a present. Something they wouldn&#8217;t get for themselves. Something you wouldn&#8217;t have done for them except for the free loving spirit of Christmas.</p>
<h3>The Gift for all Open Source projects</h3>
<p><a href="http://drnic.github.com/macruby-tmbundle/"><img alt="" src="http://img.skitch.com/20081221-trfsetaeesnnk4p5u5i35yxckd.png" title="Sample website" class="alignright" width="358" height="216" /></a></p>
<p><strong>A website.</strong></p>
<p>Oh sure, github renders your README.markdown file. Yeah, yeah, github gives you a wiki for your project. Sure, sure, Google Groups let you communicate with your co-developers and users. Certainly, you don&#8217;t <em>need</em> a website for your project.</p>
<p>That&#8217;s why its a Christmas gift. You&#8217;re going to do it because you care.</p>
<p>Websites sell your project. READMEs and Wikis educate. The project website will sell it and make people want to use your stuff.</p>
<p>A website could have a blog with an RSS/atom feed. Then you could post updates about your project. People could subscribe and also leave comments. Oh the novelty.</p>
<p>And if it only took 5 minutes to get all this setup &#8211; the website code, the blog engine, the RSS feed, the comments, and published to its own hosted server &#8211; then that would just be oh so sweet.</p>
<p>So we&#8217;re going to do some craft for our Xmas present. A little DIY project, if you will. You&#8217;ll need a few things that you&#8217;ll find around your house, a command-line interface, and a beer or perhaps some port or sherry. Christmas cake is good too.</p>
<p><span id="more-380"></span></p>
<p>The commands below take about 5 minutes to execute and you&#8217;ll have a sweet website for your project, setup on GitHub Pages, just like the <a href="http://drnic.github.com/macruby-tmbundle/">macruby-tmbundle</a> and <a href="http://drnic.github.com/jekyll_generator/">jekyll_generator</a> sites, and the sample image above.</p>
<h3>Jekyll and GitHub Pages</h3>
<p><a href="http://github.com/mojombo/jekyll/">Jekyll</a>, by Tom Preston-Werner, is one of several static website generators. All your website content will be written in textile or markdown, rendered against some HTML layouts, and published on a website somewhere. We&#8217;re going to use <a href="http://github.com/blog/272-github-pages">GitHub Pages</a> because they are new and shiny, and free, and I&#8217;ve written some sake tasks (below) to make it all easy peasy to get up and running.</p>
<p>There are a bunch of reasons we&#8217;re going to use Jekyll to render our website:</p>
<p><a href="http://drnic.github.com/macruby-tmbundle/2008/12/19/running-macruby-inside-textmate.html"><img alt="" src="http://img.skitch.com/20081221-gkweyr5rq32frgfawhd17cpm5r.png" title="disqus - javascript comment system for static blog sites" class="alignright" width="316" height="322" /></a></p>
<p>One, textile and markdown are much nicer to write/edit text than HTML.</p>
<p>Two, Jekyll is &#8220;blog enabled&#8221;. That is, some of your pages will be specifically &#8220;blog post&#8221; pages, and elsewhere in your layout you can programmatically list them. Like a blog. Yeah.</p>
<p>Three, GitHub Pages automatically supports Jekyll but no other static-website generators. This saves you from having to manually render your HTML from your Textile/Markdown pages before pushing the site to the remove server.</p>
<p>Four, I wrote a stand-alone generator to create a Jekyll website for any project. It is preconfigured with <a href="http://disqus.com/">Disqus</a> for comments, including badges for latest comments etc. </p>
<h2 id="living-with-jekyll">Living with a Jekyll</h2>
<p>Jekyll comes as a RubyGem:</p>
<pre>sudo gem source -a http://gems.github.com/
sudo gem install mojombo-jekyll
</pre>
<p>You can either read the Jekyll <a href="http://github.com/mojombo/jekyll/tree/master#readme">README</a> and create your project website by hand (and then skip below to <a href="#living-with-github-pages">Living with GitHub Page</a>).</p>
<p>Alternately, you can cheat and use a generator.</p>
<h3>jekyll_generator</h3>
<p>For the last few years, newgem has come with the ability to create a website for your project. For the jekyll_generator I decided to go with a separate generator so that any project &#8211; rubygem, rails plugin, javascript project, etc &#8211; can easily use it.</p>
<pre>sudo gem install jekyll_generator
cd path/to/project
jekyll_generator website --title "Project Name"
cd website
jekyll
open _site/index.html</pre>
<p>The final steps performs the local rendering of your website (<code>jekyll</code>) and then on OS X it opens the rendered website into your browser. Otherwise, manually open the index.html from the _site folder.</p>
<p>Currently the generator assumes that your project is already in a git repository that is hosted on github (specifically that you&#8217;ve added the github project as the origin remote).</p>
<h2 id="living-with-github-pages">Living with GitHub Pages</h2>
<p>GitHub recently released <a href="http://github.com/blog/272-github-pages">GitHub Pages</a> as a place for you to publish a personal website and websites for each of your projects. Instead of requiring you to rsync or &#8220;rake website&#8221; your way to publishing glory, you just use git.</p>
<p>Specifically, you put your website in a branch called &#8220;gh-pages&#8221;. When you push commits in that branch to github it will automatically refresh your website. No rsyncing required. Also, it will run your website through Jekyll. </p>
<p>So much delicious magic.</p>
<p>Except our website is not currently in another branch. Its in master. In a folder called <code>website</code>. Where it should be.</p>
<p>But the boffins at github say we need to move our shit across to a branch called <cide>gh-pages</code>, and who are we to argue.</p>
<p>I personally will never be doing this migration manually. I figured it out once and slapped it into a sake task. It moves all the content in your website folder into this branch, and replaces it with a submodule link so you can access the website from your master branch. Didn't follow that? No, me neither. Let's just run the sake task and move on with our lives, and eat fresh prawns and Christmas pudding.</p>
<h3>Sake tasks to get started with GitHub Pages</h3>
<p>To install them from scratch (<a href="http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/">initial blog post</a>):</p>
<pre>sudo gem install sake
cd /tmp
git clone git://github.com/drnic/sake-tasks.git
cd sake-tasks
rake install:all</pre>
<p>You can toss away the repo after installing the sake tasks.</p>
<p>You now have some tasks to manage <a href="http://github.com/drnic/sake-tasks/tree/master/github/pages">github:pages</a>:</p>
<pre>sake github:pages:migrate_website   # Migrates an existing website folder into a gh-pages branch, and links back as submodule
sake github:pages:setup             # Creates the gh-pages branch, and links to it as 'website' as submodule</pre>
<p>Since we've already created the website above, we're going to use the first task to migrate this folder into the required gh-pages branch.</p>
<pre>sake github:pages:migrate_website</pre>
<p>Um, and your done.</p>
<p>Note, if sake crashes and burns in your project it might be that you don't have a Rakefile. Try, "touch Rakefile" and rerun the sake command.</p>
<p>In 1-10 minutes your fancy new site will appear at <a href="http://drnic.github.com/macruby-tmbundle">http://username.github.com/projectname</a>. It even has a complimentary first blog post. You might want to change it to something useful.</p>
<p>You can now update your website via your website folder, commit changes and they automatically appear, automatically rendered via Jekyll, on your website. </p>
<h3>Disqus for comments</h3>
<p>Since your new website is static text there is no way to support comments on the blog posts. I've bundled into the theme's layouts the access code for Disqus. Like the image above, each blog post has Disqus comments at the bottom, and the sidebar shows the latest comments from all your blog posts.</p>
<p>You need to create a Disqus account, and <a href="http://disqus.com/add/">create a project</a> with the same name as your github project name. For example, if <code>jekyll_generator</code> is the project name on github, then make it the name on Disqus.</p>
<p><img alt="" src="http://img.skitch.com/20081221-1j37b58t1t69xxn8k2a3jx98q3.png" title="new disqus project" width="525" height="270" /></p>
<p>In my example above, my github project name was <code>jekyll_generator</code> but I couldn't use underscores on Disqus, so it is <code>jekyll-generator</code>. Fortunately, the generator templates already know this, and have converted your underscored name to hyphens already.</p>
<p>You can skip the "Choose your platform to install" steps as this is all done by the generator templates.</p>
<p>If you reload your project's website it should have Disqus badges on the sidebar, and the posts should have comment boxes.</p>
<h3>Lighthouse for tickets</h3>
<p>Lighthouse offers free access for open source projects to track their bugs. After you've created your Lighthouse project, you need to change the TODO values in <code>_layouts/default.html</code> and <code>_layouts/post.html</code> to your Lighthouse project number.</p>
<p><img alt="" src="http://img.skitch.com/20081221-f6fuha9emjecfuebbyncsaufm9.png" title="lighthouse url details" width="498" height="58" /></p>
<h3>Updating your website</h3>
<p>Your website now appears within your project source under the website folder. Though if you change it, add new posts, etc, you won't be able to commit the changes back normally. The contents of the website folder are effectively another git repository.</p>
<p>To commit changes to your website, go into the website folder and proceed normally:</p>
<pre>project(master) $ cd website
project/website(gh-pages) $ git commit -m "some changes"
project/website(gh-pages) $ git push origin gh-pages
project/website(gh-pages) $ cd ..
project(master) $</pre>
<p>Now your submodule may be dirty and need updating:</p>
<pre>git submodule update --init</pre>
<p>Not sure what this is all about.</p>
<h3>Summary</h3>
<p>A website is a great way to show that your pride and joy isn't ignored by new visitors and reminds existing users just how awesome the project is, and by clever association, how awesome you are.</p>
<p>A sexy website has to be even better.</p>
<p>Jekyll is great, and the Github Pages concept seems fun. Perhaps it wouldn't be necessary if the Github Wiki content was available as its own git repo, or if you could theme your project's source browser like a diry MySpace page.</p>
<p>Hopefully the sake tasks make migration of any existing websites to the Github Pages system easy peasy, and hopefully the jekyll_generator is useful for any new projects.</p>
<p>Hopefully.</p>
<p>Merry Christmas.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li><li><a href='http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/' rel='bookmark' title='Permanent Link: My attempt at sake task management'>My attempt at sake task management</a> <small> I&#8217;ve used sake intermittently in my workflow. It competes...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Future proofing your Ruby code. Ruby 1.9.1 is coming.</title>
		<link>http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/</link>
		<comments>http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 04:37:49 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=368</guid>
		<description><![CDATA[
Bugger.
I&#8217;m a Ruby monogamist. I use the Ruby that comes with Leopard (ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]). Oh sure I&#8217;ve cheated on my Ruby a couple of times. It was just sex, I didn&#8217;t fall in love, I promise. 
My machine has had various versions of jRuby, Rubinius and MacRuby installed at various times, [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2009/10/07/hash-bang-cucumber/' rel='bookmark' title='Permanent Link: hash bang cucumber'>hash bang cucumber</a> <small>I don&#8217;t know if this is a good idea or...</small></li><li><a href='http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/' rel='bookmark' title='Permanent Link: Cucumber: building a better World (object)'>Cucumber: building a better World (object)</a> <small>How to write helper libraries for your Cucumber step definitions...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20081210-qu1ekkhmbtyfjwbchbmwe89gru.png" width="550" height="133"></p>
<p>Bugger.</p>
<p>I&#8217;m a Ruby monogamist. I use the Ruby that comes with Leopard (<code>ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]</code>). Oh sure I&#8217;ve cheated on my Ruby a couple of times. It was just sex, I didn&#8217;t fall in love, I promise. </p>
<p>My machine has had various versions of jRuby, Rubinius and MacRuby installed at various times, but I don&#8217;t think it&#8217;s ever had two working copies of Ruby MRI (Matz Ruby Implementation) at a time.</p>
<p>Ok, that&#8217;s a lie. On Christmas Day 2007, Matz released Ruby 1.9. Yes I was a deviant. I installed it. But I didn&#8217;t inhale. <code>ruby19</code> sat on my filesystem outside the $PATH. It was a trophy not a tool.</p>
<p>My Ruby monogamy was working out perfectly for me, whilst I collected futurist and novelty Ruby implementations as a passive hobby, until yesterday when I saw the above tweet.</p>
<p>That&#8217;s a bit of a bugger. I mean, why was he playing with Ruby 1.9.1 anyway?</p>
<p>Or perhaps having multiple version of Ruby on one computer isn&#8217;t some illicit activity. <em>Everyone else is doing it, Your Honour.</em></p>
<p>I still didn&#8217;t care for having multiple ruby versions lying around in my path; but I had to fix <a href="http://rubigen.rubyforge.org">rubigen</a>. I just wanted a way to fix bugs against ruby 1.9+ and move on with my life. I didn&#8217;t want to have to do any manual work in order to set this up. Surely someone else has solved this problem already?</p>
<p><span id="more-368"></span></p>
<h3 id="multiruby">MultiRuby</h3>
<p>Yes. Ryan Davis did <a href="http://blog.zenspider.com/2007/12/testing-for-ruby-18-and-19-usi.html">solve this problem already</a>. You can follow his instructions and get most of the answers I needed. Except as of today, multiruby wasn&#8217;t pulling down my nemesis ruby 1.9.1 prerelease versions, just the latest 1.9.0 version. (update: <a href="http://www.rubyinside.com/ruby-191-released-first-production-release-of-the-fastest-ruby-ever-1480.html">1.9.1 is out</a>; installation instructions below are updated)</p>
<p>Also, I couldn&#8217;t figure out how to setup rubygems and I couldn&#8217;t figure out how install all the fun gems that my code needed. Ryan fixed me up with this answer too.</p>
<p>MultiRuby is really nice in that it installs all the version of ruby into a safe place (<code>~/.multiruby/</code>) and has nice ways to add and remove versions of ruby that you want to test against. To run the tests for rubigen I ran the following code. It takes about 30 minutes from scratch.</p>
<pre>sudo gem install ZenTest
multiruby -e "p 1+1"
multiruby_setup mri:svn:tag:v1_8_6_114
multiruby_setup mri:svn:tag:v1_9_1_0

multiruby_setup update:rubygems
multiruby -S gem install --no-ri --no-rdoc --development test-unit rspec mocha rails
</pre>
<p>To get the full list of available ruby tagged releases, ask the SVN repo:</p>
<pre>svn list http://svn.ruby-lang.org/repos/ruby/tags
</pre>
<p>Sometimes I got time out errors on the gem installs</p>
<pre>ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    timed out (http://gems.rubyforge.org/gems/rails-2.2.2.gem)
</pre>
<p>The next section helps fix this if it occurs for you.</p>
<h3 id="sake_tasks_to_help_with_multiruby">Sake tasks to help with multiruby</h3>
<p>Whilst <code>multiruby_setup</code> comes with some useful helpers, and hoe generates a helpful &#8216;rake multi&#8217; runner for test/unit tests of hoe gems, I wanted more helpers. These have been compiled as sake tasks in <a href="http://github.com/drnic/sake-tasks">http://github.com/drnic/sake-tasks</a>.</p>
<p>To install them from scratch (<a href="http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/">initial blog post</a>):</p>
<pre>sudo gem install sake
cd /tmp
git clone git://github.com/drnic/sake-tasks.git
cd sake-tasks
rake install:all
</pre>
<p>You can toss away the repo after installing the sake tasks.</p>
<h3 id="installing_gems_into_multiruby">Installing gems into multiruby</h3>
<p>Each version of ruby has its own rubygems cache. To install a gem into each ruby version:</p>
<pre>sake multiruby:gems:install GEM=gemname
sake multiruby:gems:install GEMS=gem1,gem2
</pre>
<p>Want to see what gems were installed for each version of ruby?</p>
<pre>multiruby -S gem list
</pre>
<h3 id="running_tests">Running tests</h3>
<p>If you use hoe, and your tests are traditional <code>test/unit</code> tests, then hoe comes with a very helpful <code>rake multi</code> task.</p>
<p>For everyone else, use the following sake tasks:</p>
<pre>sake multiruby       # Runs any tests or specs in current project against multiruby
sake multiruby:spec  # Runs specs in current project against multiruby
sake multiruby:test  # Runs tests in current project against multiruby
</pre>
<h3 id="miscellaneous_multiruby_management">Miscellaneous MultiRuby management</h3>
<p>When I was fixing rubigen, I had some failing tests against 1.9.0-5 but not against 1.9.1, so I decided I hated 1.9.0 and stopped running tests against it. You can stop supporting a version of ruby with:</p>
<pre>multiruby_setup rm:1.9.0-5
</pre>
<p>Not sure what versions of ruby you&#8217;re supporting?</p>
<pre>multiruby_setup list
</pre>
<h3 id="cucumber">Cucumber</h3>
<p>Theoretically you could try something like (after installing cucumber gem into multiruby):</p>
<pre>multiruby -S cucumber features
multiruby -S cucumber --format progress features
</pre>
<p>My scenarios are failing at the moment. All of them. And the log/stdout files are overwriting each other in the tmp folder. To isolate it down to one scenario you&#8217;d try something like:</p>
<pre>multiruby -S cucumber features/executable_generator.feature:7
</pre>
<p>You can now easily isolate and run a specific cucumber scenario against a specific ruby version by copy+pasting from the output of the above line. For example:</p>
<pre>~/.multiruby/install/v1_8_6_114/bin/ruby -S cucumber features/executable_generator.feature:7
</pre>
<p>Perhaps this is too much information. I&#8217;m still getting cucumber + multiruby working together, so I&#8217;ll add new ideas to the bottom of this post as I figure them out.</p>
<h3>Running rake tasks</h3>
<p>I&#8217;ve been poking around a bunch of other people&#8217;s gems seeing how many gems current pass against ruby 1.9.1 (answer: not many). When I came across nokogiri, I found that I needed to trigger the build steps of the C code first before running the tests. The simplest way to do this was via its own rake tasks.</p>
<pre>multiruby -S rake clean test</pre>
<p>Here we are calling the &#8216;clean&#8217; task first, so that the C code is rebuilt from scratch for each new ruby version. BTW, there are 6 failing tests for v1_9_1_preview2.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2009/10/07/hash-bang-cucumber/' rel='bookmark' title='Permanent Link: hash bang cucumber'>hash bang cucumber</a> <small>I don&#8217;t know if this is a good idea or...</small></li><li><a href='http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/' rel='bookmark' title='Permanent Link: Cucumber: building a better World (object)'>Cucumber: building a better World (object)</a> <small>How to write helper libraries for your Cucumber step definitions...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>My RubyGems development tools and workflow</title>
		<link>http://drnicwilliams.com/2008/12/05/my-rubygems-development-tools-and-workflow/</link>
		<comments>http://drnicwilliams.com/2008/12/05/my-rubygems-development-tools-and-workflow/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 08:05:20 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Gems]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=357</guid>
		<description><![CDATA[
The Open Source Developers Conference (osdc) is a nifty conference &#8211; people from different language communities, who all do open source, come together in harmony. They simultaneously snigger at each other and then proceed to steal each others ideas when they aren&#8217;t looking.
Miscellaneous idea possibly worth stealing from Perl: when you install Perl modules from [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li><li><a href='http://drnicwilliams.com/2006/10/18/create-and-deploy-command-line-apps-with-rubygems/' rel='bookmark' title='Permanent Link: Create and deploy command line apps with RubyGems'>Create and deploy command line apps with RubyGems</a> <small>RubyGems have many things going for them: they are a...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://img.skitch.com/20081204-x2rcu7ajds1wah41b943m8cd7a.png" title="Create lots of gems" class="alignright" width="246" height="387" /></p>
<p>The Open Source Developers Conference (<a href="http://www.osdc.com.au">osdc</a>) is a nifty conference &#8211; people from different language communities, who all do open source, come together in harmony. They simultaneously snigger at each other and then proceed to steal each others ideas when they aren&#8217;t looking.</p>
<p>Miscellaneous idea possibly worth stealing from Perl: when you install Perl modules from CPAN it runs the module&#8217;s tests locally to confirm everything is oaky-dokey. You can manually do this via <code>gem install --test rails</code>, but its not the default. Nor have I ever used the <code>--test</code> flag. I just looked it up via <code>gem help install</code>. I like it.</p>
<p>Another CPAN thing to steal: For any RubyGem or perhaps Rails project on rubyforge/github/whatever, show the aggregate status of tests. Here&#8217;s a <a href="http://deps.cpantesters.org/?module=App::Asciio;perl=latest">sample from CPAN</a>. Lots of green lines but the aggregate change of this project working? 11%. I like the chart, and perhaps <a href="http://runcoderun.com">runcoderun</a> or some other hosted CI service to generate a sexy graph of test outputs for dependencies.</p>
<p>Anyway, Ruby. I did a talk. I have <a href="http://drnicwilliams.com/wp-content/uploads/2008/12/rubygem-dev-and-workflow-osdc2008-20081204.pdf">slides</a>.</p>
<div style="width:425px;text-align:left" id="__ss_819679"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/drnic/rubygem-dev-and-workflow-presentation?type=powerpoint" title="Rubygem Dev And Workflow">Rubygem Dev And Workflow</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=rubygem-dev-and-workflow-1228434585968621-8&#038;stripped_title=rubygem-dev-and-workflow-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=rubygem-dev-and-workflow-1228434585968621-8&#038;stripped_title=rubygem-dev-and-workflow-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></div>
<p>Over time I&#8217;ve written a few RubyGems and am pretty happy with my basic tools and workflow for getting new gems out the door or maintaining existing projects. I use newgem + a patched version of hoe, I use git + github, and recently I started using runcoderun for hosted continuous integration. </p>
<p>If you&#8217;re new to creating your own RubyGems, perhaps my workflow and tools are a useful starting point to follow.</p>
<p>If you want an account with <a href="http://runcoderun.com/">runcoderun</a>, and I reckon you do, then hassle <a href="http://blog.thinkrelevance.com/2008/10/14/runcoderun-now-open-to-the-anonymous-public-2">Rob Sanheim</a> (<a href="http://twitter.com/rsanheim">twitter</a>). For what its worth, tell him I said it was urgent.</p>
<p>There is now a <a href="http://thinkrelevance.rubyforge.org/runcoderun_badge/">sexy blog badge</a> to show off the current pass/fail state of each of your projects, by <a href="http://blog.thinkrelevance.com/2008/10/17/runcoderun-badges">Glenn Vanderburg</a>. Badges are fun. It seems to clash with having github-badge in the same page, and there are other bugs with these badges. Probably my fault. I should investigate that soon.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li><li><a href='http://drnicwilliams.com/2006/10/18/create-and-deploy-command-line-apps-with-rubygems/' rel='bookmark' title='Permanent Link: Create and deploy command line apps with RubyGems'>Create and deploy command line apps with RubyGems</a> <small>RubyGems have many things going for them: they are a...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/12/05/my-rubygems-development-tools-and-workflow/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>newgem 1.0.0 all thanks to Cucumber</title>
		<link>http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/</link>
		<comments>http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 16:51:14 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[NewGem]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=316</guid>
		<description><![CDATA[The New Gem Generator (newgem) was exciting, moderately revolutionary, and definitely helpful two years ago when I created it. Of late it seems to attract a chunk of criticism:

making a new gem, but newgem seems broken&#8230; hoe hoe
NewGem has the &#8220;hoe&#8221; virus. Much prefer Mr. Bones.
the newgem site is begging for someone to put the [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/' rel='bookmark' title='Permanent Link: Cucumber: building a better World (object)'>Cucumber: building a better World (object)</a> <small>How to write helper libraries for your Cucumber step definitions...</small></li><li><a href='http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/' rel='bookmark' title='Permanent Link: Testing outbound emails with Cucumber'>Testing outbound emails with Cucumber</a> <small> My testimonial for Cucumber still stands even in 2009....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>The New Gem Generator (<a href="http://newgem.rubyforge.org">newgem</a>) was exciting, moderately revolutionary, and definitely helpful two years ago when I created it. Of late it seems to attract a chunk of criticism:</p>
<ul>
<li>making a new gem, but newgem seems broken&#8230; hoe hoe</li>
<li>NewGem has the &#8220;hoe&#8221; virus. Much prefer Mr. Bones.</li>
<li>the newgem site is begging for someone to put the word fuck on its front page</li>
<li>Almost two days fighting with newgem, but today i won! The secret is hoe 1.7.0 and rubygem 1.2.0.</li>
<li>unfortunately for the one project I went with newgem, will give Mr. Bones a try on the next gem I throw out there.</li>
<li>sow or newgem, neither, Mr. Bones</li>
<li>egads, the website newgem sets up for you looks awful</li>
<li>newgem seems to be failed to generate package if AUTHOR is an array of authors.</li>
</ul>
<p>On the positive side of the spectrum is the following list:</p>
<ul>
<li>newgem? really? you rock drnic!</li>
</ul>
<p>Comparatively, the two lists are awfully different in length. And not in a good way. No, not at all.</p>
<p>I know about these criticisms and platitude(s) because they appear publicly on <a href="http://newgem.rubyforge.org">newgem&#8217;s website</a> within a live Twitter search of &#8216;<a href="http://search.twitter.com/search?q=newgem">newgem</a>&#8217;. So that the twitter messages on the project&#8217;s own homepage are more positive, it was time for a new direction. A new beginning. It was time for a change.</p>
<p>So I fixed it. All of it. As of release 1.0.3 it is perfect [1]. </p>
<p>To help you realise how wonderful newgem now is, I shall use the time-proven medium for proving awesomeness: a list. The bullet points are for free.</p>
<ul>
<li>newgem now finally gone 1.0.0. It made it all the way to 0.29.0, but I think 1.0.0 was needed to transfer the message of a new beginning. This is the Obama of Gem Generators.</li>
<li>Generated gems are 50% smaller. No more config/hoe.rb. No more website folder (by default). No more tasks folder. No more license file. No more version.rb file.</li>
<li>Very little config required before releasing your gem. Just a few fields in the <code>Rakefile</code>.</li>
<li>You can use rspec or test/unit for unit testing (option: <code>-T rspec</code>)</li>
<li>You can use cucumber for functional testing (option: <code>-i cucumber</code> or run <code>script/generate install_cucumber</code>)</li>
<li>Generated gems are future-proofed. They will automatically benefit from future newgem releases.</li>
<li>Executable apps within gems now have a <code>lib/appname/cli.rb</code> file for the code base, and a lightweight <code>bin/appname</code> (option: <code>-b appname</code> or run <code>script/generate executable appname</code>)</li>
<li>Your README file can be called <code>README.rdoc</code> so it appears nicely formatted on github. No more hoe warning messages about &#8220;README.txt is missing&#8221; (see <a href="http://github.com/drnic/newgem/tree/master/features/rubygem_tasks.feature#L15-19">feature</a>)</li>
<li><a href="http://github.com/">GitHub</a> RubyGem support. <code>rake gemspec</code> generates a clean <code>my_project.gemspec</code> file that will work with GitHub</li>
<li>RubyForge support. As before, <code>rake release VERSION=X.Y.Z</code> releases your project to RubyForge (see &#8216;<a href="http://newgem.rubyforge.org/rubyforge.html">preparing for releases to rubyforge</a>&#8217; help page)</li>
<li>newgem&#8217;s website is a different colour. Its a nice peppermint green colour. The default website template is now this theme too.</li>
<li>You can raise bugs or suggest improvements via <a href="http://drnic.lighthouseapp.com/projects/18881-newgem">Lighthouse tracker</a></li>
</ul>
<h3 id="installation">Installation</h3>
<pre>sudo gem install newgem
</pre>
<h3 id="usage">Usage</h3>
<p>To create your RubyGem scaffold:</p>
<pre>newgem mygem
newgem mygem -b myapp              # create a CLI executable
newgem mygem -T rspec -i cucumber  # use rspec and cucumber for gem tests
newgem mygem -w                    # create a simple website
newgem -h                          # get help
</pre>
<p>Now your code goes in <code>lib</code> folder, and your tests go in <code>test</code>, <code>spec</code>, and/or <code>features</code> as appropriate.</p>
<p>There are a bunch of rails-esque generators (like <code>model</code> or <code>migration</code>) that you can use to help your development:</p>
<pre>script/generate executable myapp                       # create your own command-line interface (CLI)
script/generate extconf mylib                          # starting point for C-extensions, plus TDD framework
script/generate component_generator mygenerator scope  # create your own generators for Rails, Merb, RubyGems
script/generate application_generator myapp            # create a CLI that is a generator for something
script/generate -h                                     # get help
</pre>
<h3 id="bugs_and_suggestions">Bugs and suggestions</h3>
<p>You can raise bugs or suggest improvements via <a href="http://drnic.lighthouseapp.com/projects/18881-newgem">Lighthouse tracker</a></p>
<h3 id="thanks_goes_to8230_cucumber">Thanks goes to&#8230; Cucumber</h3>
<p>Aside from several days of my time refactoring it, reducing it, and doubling the amount of awesomeness within it, all its wondefulness is thanks to Cucumber. </p>
<p><a href="http://github.com/aslakhellesoy/cucumber">Cucumber</a> is the successor to Rspec Story Runner. I never found time to play with Story Runner, but Cucumber is blowing my mind with awesomeness. My attention-span is short so I may be forgetting something but I think Cucumber could be the most important piece of software released in 2008 for Ruby-based developers.</p>
<p>Cucumber gave me a framework to specify newgem&#8217;s expected behaviour; its features. First I wrote feature descriptions for known, expected behaviour. Then I refactored the crap out of newgem until it was in tip-top shape.</p>
<p>There are over 90 feature steps defining newgem&#8217;s current features. To run them:</p>
<pre>gem unpack newgem
cd newgem-*
sudo gem install cucumber
cucumber features
</pre>
<p>And watch the awesomeness of Cucumber unfold before your eyes. What you are seeing isn&#8217;t just newgem&#8217;s generators being executed, but also the generated code is being executed, rake tasks executed, and generated test files tested.</p>
<p>I can now setup continuous integration for newgem. I have a framework to know that newgem, or any other RubyGem, is doing what it should do. </p>
<p>UPDATE: I want to thank <a href="http://blog.davidchelimsky.net">David Chelimsky</a> for our time hanging out in Brazil during RailsSummit. I saw him using Cucumber, and talking about it on stage and then help helped me whilst I integrated it into newgem as a generator and then using it internally itself. For a day and a half we hung out in the hotel foyer. He&#8217;s so wonderful.</p>
<p>Cucumber makes me so happy.</p>
<h3 id="summary">Summary</h3>
<p>Use <a href="http://newgem.rubyforge.org/">newgem</a>. Write gems.</p>
<p>Use <a href="http://github.com/TwP/bones/tree/master">mrbones</a>. Write gems.</p>
<p>Use <a href="http://seattlerb.rubyforge.org/hoe/">sow</a>. Write gems.</p>
<p><o>Use <a href="http://github.com/dcrec1/gemhub/tree/master">gemhub</a>. Write gems.</p>
<p>And write cucumber feature descriptions first. Then unit tests. Then code. Then release. Then profit.</p>
<p>[1] All claims of perfection are for the express purpose of making you try the product enough to use it, share it with your friends, and wrap it up and give it as a gift to family on Xmas day. Gift boxes are available upon request.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li><li><a href='http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/' rel='bookmark' title='Permanent Link: Cucumber: building a better World (object)'>Cucumber: building a better World (object)</a> <small>How to write helper libraries for your Cucumber step definitions...</small></li><li><a href='http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/' rel='bookmark' title='Permanent Link: Testing outbound emails with Cucumber'>Testing outbound emails with Cucumber</a> <small> My testimonial for Cucumber still stands even in 2009....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Unit Testing iPhone apps with Ruby: rbiphonetest</title>
		<link>http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/</link>
		<comments>http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 19:26:02 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Iphone]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=287</guid>
		<description><![CDATA[
Everything to love about Ruby: the concise, powerful language; the sexy testing frameworks; and finally, the people.
Everything to love about Objective-C: hmmm; well&#8230;; and finally, its the only high-level language you can use to write iPhone apps.
On iPhone 2.0, to arrive on the 11th of July, you cannot run RubyCocoa. But you can run it [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/' rel='bookmark' title='Permanent Link: Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;'>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</a> <small> Got a simple app you want to build? Allocate...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li><li><a href='http://drnicwilliams.com/2008/11/10/to-webkit-or-not-to-webkit-within-your-iphone-app/' rel='bookmark' title='Permanent Link: To WebKit or not to WebKit within your iPhone app?'>To WebKit or not to WebKit within your iPhone app?</a> <small> I know HTML. Its on my CV. Expert level....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20080703-mqpqqhdk4e49x3yhhb8t2g9rjg.jpg" alt="rbiphonetest logo" style="float: right" /></p>
<p>Everything to love about <strong>Ruby</strong>: the concise, powerful language; the sexy testing frameworks; and finally, the people.</p>
<p>Everything to love about <strong>Objective-C</strong>: hmmm; well&#8230;; and finally, its the only high-level language you can use to write iPhone apps.</p>
<p>On iPhone 2.0, to arrive on the 11th of July, you cannot run RubyCocoa. But you can run it on your Mac, so let&#8217;s use it to unit test your Objective-C classes. This tutorial shows you how to get started using a new project <a href="http://github.com/drnic/rbiphonetest/">rbiphonetest</a> [<a href="http://github.com/drnic/rbiphonetest">GitHub</a> | <a href="http://drnic.lighthouseapp.com/projects/13763-rbiphonetest">Lighthouse</a> | <a href="http://groups.google.com/group/rbiphonetest">Google Group</a>]</p>
<p>If you followed some of my <a href="http://summize.com/search?q=iphoneruby">recent tweets</a>, this project was previously called &#8220;iphoneruby&#8221;. And alas, the screencast also calls it &#8220;iphoneruby&#8221; but that was a crap name. People thought it was a way to run Ruby on the iphone. I can&#8217;t do that yet. So, a far better name is &#8216;rbiphonetest&#8217;. [track on <a href="http://summize.com/search?q=rbiphonetest">summize</a>]</p>
<p>Even if you&#8217;ve never touched Objective-C, Cocoa, the iPhone SDK, nor RubyCocoa I recommend watching the video anyway. It should give you hope that if you make the transition to iPhone development you don&#8217;t have to go alone without Ruby: your trusty swiss army knife of language/libraries/tools.</p>
<p>The screencast is also available in <a href="http://drnicwilliams.com/wp-content/uploads/2008/06/rbiphonetest-introduction.mov">high-def video</a> (55Mb QuickTime)</p>
<p><object width="550" height="393"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=1262916&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=01AAEA&amp;fullscreen=1" /><embed src="http://www.vimeo.com/moogaloop.swf?clip_id=1262916&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=01AAEA&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="393"></embed></object><br /><a href="http://www.vimeo.com/1262916?pg=embed&amp;sec=1262916">Unit Testing iPhone apps using Ruby</a> from <a href="http://www.vimeo.com/user289979?pg=embed&amp;sec=1262916">Dr Nic</a> on <a href="http://vimeo.com?pg=embed&amp;sec=1262916">Vimeo</a>.</p>
<h2 id="installation_and_usage">Installation and Usage</h2>
<p>To summarize the video, but change &#8216;iphoneruby&#8217; to &#8216;rbiphonetest&#8217;, you install the framework via RubyGems:</p>
<pre>sudo gem install rbiphonetest</pre>
<p>Then change to your project&#8217;s folder and install the test framework:</p>
<pre>rbiphonetest .</pre>
<p>Finally, for each generic, non-UIKit-framework-using class you want to test:</p>
<pre>script/generate model WidgetModel</pre>
<p>Then write your tests in <code>test/test_widget_model.rb</code></p>
<h2 id="supported_cocoa_iphone_frameworks">Supported Cocoa &amp; iPhone frameworks</h2>
<p>The mysterious, magical premise upon which rbiphonetest depends is possibly erroneous: that your Objective-C class can be compiled and tested against your OS X/Intel frameworks, and if your tests pass you assume you can then compile and include your class with the the iPhone/ARM frameworks.</p>
<p>I&#8217;m willing to go with this assumption until its proven dangerously flawed by some angry 20-year veteran of NextStep/Cocoa/iPhone. But really, how different could NSString be on the iPhone versus your Mac?</p>
<p>Fortunately there is one way to check for significant differences between your available Mac-based frameworks, such as Cocoa, and the iPhone-based frameworks, such as UIKit. We need to compare the framework names, header files and method signatures.</p>
<p>So for example, you cannot currently unit test any class that depends on/includes the UIKit framework. <em>Why?</em> It doesn&#8217;t exist on your Mac, so the Mac/Intel compiler cannot link it in. We&#8217;re compiling and running our tests with RubyCocoa, which itself is built against the Mac/Intel frameworks, not the iPhone frameworks. Hell, <a href="http://chopine.be/lrz/">Laurent</a> doesn&#8217;t even own an iPhone <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  [Laurent is the Apple-employee maintainer of <a href="http://rubycocoa.sourceforge.net/HomePage">RubyCocoa</a> and the newer <a href="http://trac.macosforge.org/projects/ruby/wiki/MacRuby">MacRuby</a>]</p>
<p>Similarly, its no use including/linking the Cocoa framework into your Objective-C class. <em>Why?</em> It doesn&#8217;t exist on the iPhone. It has its own UI frameworks, collectively called &#8216;UIKit&#8217;.</p>
<p>So for the moment we cannot test UI-related, iPhone-API-specific code. But we can test generic Objective-C. That&#8217;s better than a kick in the teeth. Surely. I mean, in the teeth&#8230; that&#8217;d friggin&#8217; hurt.</p>
<p>&#8220;Fair enough Dr Nic, so which frameworks <em>can</em> my code use and yet still unit test it with your oh-so-special test library thingy?&#8221; Keep your pants on, I&#8217;m getting there. [<a href="#keep-your-pants-on">ref</a>]</p>
<p>To the best of my ability, I&#8217;ve compared the two sets of frameworks and listed the available Frameworks that are available on both the iPhone and your Mac. There are about a dozen. The most important is called &#8216;Foundation&#8217;. It holds gold nuggets like &#8216;NSString&#8217;. </p>
<p>The list of <a href="http://github.com/drnic/rbiphonetest/wikis/platform-differences">platform differences</a> is on the wiki as a reference.</p>
<p>Note, this list doesn&#8217;t guarantee that any two framework classes &#8211; the iPhone and matching Mac framework &#8211; will behave the same. This list is compiled by finding the set of Frameworks with the same name on both platforms, e.g. Foundation.</p>
<p>Then it compares the set of public header files (Foundation.framework/Headers/*.h files) This comparison is by method signature. It pulls all lines from each header that start with + or &#8211; (+ is a class method and &#8211; is an instance method in Objective-C) and compares the two lists. If there is a single difference in the method signatures of the header files in the two platforms it is marked on the wiki page. You&#8217;ll need to look at the two header files yourself to see the differences. Some header files are ugly. C-based anything starts ugly and goes down from there, I think.</p>
<h2 id="python_testing_of_iphone_objective_c">Python testing of iPhone Objective-C?</h2>
<p>In the Python world there is PyObjC, a bridge-based twin to RubyCocoa. If you are a Python developer you could easily port this project to use PyObjC I would think. Ping me if you are attempting this and need any help.</p>
<h2 id="summary">Summary</h2>
<p>I think this project can give Ruby developers a happy place to work from as they write their Objective-C/iPhone code. You still need to wire up your UI views and controller classes manually, but if you push all the &#8220;oooh that code really needs some tests&#8221; classes away from the UI-dependent frameworks then you can hook it up to rbiphonetest and write your tests in Ruby.</p>
<p>Currently the generator creates test/unit test stubs. I personally then add the Shoulda gem into my test_helper.rb for my apps. If an rspec and/or test/spec developer can help with adding support to the generators I&#8217;m certain the large rspec user-base would be happy campers.</p>
<p>Similarly, someone might like to investigate using MacRuby to run the tests instead of RubyCocoa. Fast tests vs slow tests. You choose.</p>
<h3>What the?</h3>
<p>Sometimes I re-read what I&#8217;ve written and notice things that don&#8217;t seem to make sense, but are in my vocabulary nonetheless. Yep, the things you learn living in Australia.</p>
<p><strong id="keep-your-pants-on">&#8220;Keep your pants on&#8221;</strong> &#8211; this seems to imply that until I mentioned otherwise you were about to take your pants off. Hardly relevant at any stage during this article, we&#8217;d both agree. Most code-based blog articles are &#8220;pants on&#8221;. This phrase means &#8220;don&#8217;t get upset&#8221;. You can try to figure out how you go from &#8220;don&#8217;t get upset&#8221; to &#8220;keep your pants on&#8221;. I have no idea.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/' rel='bookmark' title='Permanent Link: Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;'>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</a> <small> Got a simple app you want to build? Allocate...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li><li><a href='http://drnicwilliams.com/2008/11/10/to-webkit-or-not-to-webkit-within-your-iphone-app/' rel='bookmark' title='Permanent Link: To WebKit or not to WebKit within your iPhone app?'>To WebKit or not to WebKit within your iPhone app?</a> <small> I know HTML. Its on my CV. Expert level....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/07/04/unit-testing-iphone-apps-with-ruby-rbiphonetest/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
<enclosure url="http://drnicwilliams.com/wp-content/uploads/2008/06/rbiphonetest-introduction.mov" length="60255710" type="video/quicktime" />
		</item>
		<item>
		<title>Writing C extensions in RubyGems using newgem generators (plus a free TextMate bundle)</title>
		<link>http://drnicwilliams.com/2008/04/01/writing-c-extensions-in-rubygems/</link>
		<comments>http://drnicwilliams.com/2008/04/01/writing-c-extensions-in-rubygems/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 11:51:07 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[NewGem]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=269</guid>
		<description><![CDATA[Already know C extensions in RubyGems? Cool &#8211; then just run the following cmds and see what can be generated for you; plus check out the TextMate bundle at the bottom.
sudo gem install newgem
newgem pickaxe
cd pickaxe
script/generate extconf my_test
rake test

For everyone else&#8230;
Its 15000km from Brisbane AU to Prague CZ where Euruko2008 &#8211; the European Ruby Conf [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li><li><a href='http://drnicwilliams.com/2008/05/12/textmate-bundles-for-merb/' rel='bookmark' title='Permanent Link: TextMate bundles for Merb'>TextMate bundles for Merb</a> <small>If you are using TextMate (OS X) or E Text...</small></li><li><a href='http://drnicwilliams.com/2007/08/20/newgem-using-rubigen-for-generator-support/' rel='bookmark' title='Permanent Link: NewGem Generator &#8211; now with script/generate'>NewGem Generator &#8211; now with script/generate</a> <small>The New Gem Generator (0.13.0)&#8217;s newgem command now behaves like...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Already know C extensions in RubyGems? Cool &#8211; then just run the following cmds and see what can be generated for you; plus check out the TextMate bundle at the bottom.</p>
<pre>sudo gem install newgem
newgem pickaxe
cd pickaxe
script/generate extconf my_test
rake test
</pre>
<p>For everyone else&#8230;</p>
<p>Its <a href="http://www.timeanddate.com/worldclock/distanceresult.html?p1=47&amp;p2=204">15000km</a> from Brisbane AU to Prague CZ where <a href="http://www.euruko2008.org/">Euruko2008</a> &#8211; the European Ruby Conf &#8211; was held. I came ready to <a href="http://...">talk</a>, to met lots of cool multi-lingual Rubyists, and to learn. Ooh, I learnt something alright.</p>
<p>Tim Becker was introducing <a href="http://blog.kuriositaet.de/?p=220">Native C Extensions for Ruby</a>, and fortunately he said &#8220;now, everyone, follow along with this example&#8221;. I&#8217;d never done native C extensions, but I&#8217;d received lots of requests from RubyGem developers on how to do it. I had no idea.</p>
<p>So I was typing in everything Tim told me to type in. When Tim changed slides too quickly, I may have yelled at him to slow down. Perhaps I was the only one doing his tutorial out of 300 people, but I didn&#8217;t care. This was gold.</p>
<p>After he finished his session, I dragged him off into the corridor with Jonas Pfenniger (zimbatm), and the three of us mapped out a generic layout for how native C extensions work within RubyGems. I didn&#8217;t know any of this, but Tim and Jonas did, and we probably looked silly sitting at a small table in the middle of the narrow corridor. </p>
<p><em>But at the end, we had a working RubyGem with native C extensions that were built: when the tests were executed via rake, and when the gem was installed. The next day I figured out how to get the C extension built via autotest.</em></p>
<p>Thanks to Tim and Jonas I was able to then write a <code>extconf</code> generator for RubyGems so that its super-super easy to get started writing native C extensions within RubyGems. </p>
<h3 id="tutorial">Tutorial</h3>
<p>This tutorial is for *nix, as I&#8217;m still investigating <a href="http://blog.mmediasys.com/2008/03/29/progress-of-one-click-installer-rubyinstaller/">win32 extensions</a>, and jruby + .net/ironruby extensions. So when I figure that out &#8211; hopefully with the help of other people currently at RubyFools conferences, I&#8217;ll get back to you.</p>
<p>The code comes from the <a href="http://www.rubycentral.com/pickaxe/ext_ruby.html">Pickaxe book &#8211; p264</a>, and we&#8217;ll insert it into a new RubyGem using <code>newgem</code> (version 0.20.1+):</p>
<pre>sudo gem install newgem
newgem pickaxe
cd pickaxe
script/generate extconf my_test
</pre>
<p>Create a test for a class <code>MyTest</code> that doesn&#8217;t exist yet:</p>
<pre># test/test_my_test_extn.rb
require "test/unit"
require 'pickaxe'

class TestMyTestExtn &lt; Test::Unit::TestCase
  def test_working
    t = MyTest.new
    assert_equal(Object, MyTest.superclass)
    assert_equal(MyTest, t.class)
    t.add(1)
    t.add(2)
    assert_equal([1,2], t.instance_eval("@arr"))
  end
end
</pre>
<p>Run <code>rake</code> to build the C extension and run the tests. You can also run <code>autottest</code> and it will automatically build the C extension before running the tests.</p>
<p>To create the <code>MyTest</code> class, using the code from p262 of the Pickaxe book:</p>
<pre>#include "ruby.h"
static int id_push;

static VALUE t_init(VALUE self)
{
  VALUE arr;
  arr = rb_ary_new();
  rb_iv_set(self, "@arr", arr);
  return self;
}

static VALUE t_add(VALUE self, VALUE obj)
{
  VALUE arr;
  arr = rb_iv_get(self, "@arr");
  rb_funcall(arr, id_push, 1, obj);
  return arr;
}

VALUE cTest;
void Init_my_test() {
  cTest = rb_define_class("MyTest", rb_cObject);
  rb_define_method(cTest, "initialize", t_init, 0);
  rb_define_method(cTest, "add", t_add, 1);
  id_push = rb_intern("push");
}
</pre>
<p>To <code>lib/pickaxe.rb</code>:</p>
<pre>require "my_test.so"
# or require 'my_test' if its unique
</pre>
<p>The last line will import the generated shared library. If the RubyGem is tested or installed on Windows, then the .dll file will be automatically loaded instead. The &#8220;.so&#8221; notation is merely a placeholder to explicitly specify the shared C-extension, rather than any Ruby library of the same name.</p>
<p>Now run tests (<code>rake</code>), the C extension will be rebuilt and the tests will pass.</p>
<h3 id="build_and_install_rubygem">Build and install RubyGem</h3>
<pre>rake manifest:refresh
rake install_gem
irb -rubygems -rpickaxe
&gt; a = MyTest.new
&gt; a.add 3
</pre>
<p>You have successfully created a C-extension within RubyGems, using TDD.</p>
<h3 id="textmate_bundle_for_ruby_c_extensions">TextMate bundle for Ruby C extensions</h3>
<p>I&#8217;ve started a TextMate bundle to give syntax highlighting + some simple snippets for developing the C files for Ruby extensions.</p>
<p>To install:</p>
<pre>cd ~/Library/Application Support/TextMate/Bundles
git clone git://github.com/drnic/ruby-c-extensions-tmbundle.git "Ruby C Extensions.tmbundle"

or 

wget http://github.com/drnic/ruby-c-extensions-tmbundle/tarball/master
tar xfv drnic-ruby-c-extensions-tmbundle-master.tar.gz
mv drnic-ruby-c-extensions-tmbundle-master "Ruby C Extensions.tmbundle"
</pre>
<p>Then restart TextMate or &#8220;Reload Bundles&#8221;.</p>
<p>You can clone/fork the source via  <a href="http://github.com/drnic/ruby-c-extensions-tmbundle/tree/master">http://github.com/drnic/ruby-c-extensions-tmbundle/tree/master</a></p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li><li><a href='http://drnicwilliams.com/2008/05/12/textmate-bundles-for-merb/' rel='bookmark' title='Permanent Link: TextMate bundles for Merb'>TextMate bundles for Merb</a> <small>If you are using TextMate (OS X) or E Text...</small></li><li><a href='http://drnicwilliams.com/2007/08/20/newgem-using-rubigen-for-generator-support/' rel='bookmark' title='Permanent Link: NewGem Generator &#8211; now with script/generate'>NewGem Generator &#8211; now with script/generate</a> <small>The New Gem Generator (0.13.0)&#8217;s newgem command now behaves like...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/04/01/writing-c-extensions-in-rubygems/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>RubiGen video from RejectConf Berlin</title>
		<link>http://drnicwilliams.com/2007/09/22/rubigen-video-from-rejectconf-berlin/</link>
		<comments>http://drnicwilliams.com/2007/09/22/rubigen-video-from-rejectconf-berlin/#comments</comments>
		<pubDate>Sat, 22 Sep 2007 19:06:37 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[NewGem]]></category>
		<category><![CDATA[RubiGen]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/2007/09/22/rubigen-video-from-rejectconf-berlin/</guid>
		<description><![CDATA[Go straight to video below
I took a video recorder to the RejectConf, like I did in Portland. Unfortunately, there were two reasons I didn&#8217;t record any of them.
Firstly, there didn&#8217;t seem to be any obvious place to position the camera.
Secondly, it was deemed critical that everyone does their talks in the dark. The conference isn&#8217;t [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2007/10/25/dr-nic-at-rubyconf-2007-rubigen-teaser/' rel='bookmark' title='Permanent Link: Dr Nic at RubyConf 2007 &#8211; RubiGen &#8211; Teaser'>Dr Nic at RubyConf 2007 &#8211; RubiGen &#8211; Teaser</a> <small>4th of November 2007 &#8211; 9am &#8211; main conference room...</small></li><li><a href='http://drnicwilliams.com/2007/06/02/ze-frank-at-railsconf-like-ted/' rel='bookmark' title='Permanent Link: Missed Ze Frank at Railsconf? [video]'>Missed Ze Frank at Railsconf? [video]</a> <small>Neat. Here is Ze Frank at TED 20062004 [thx Erik...</small></li><li><a href='http://drnicwilliams.com/2007/05/27/new-gem-generates-gets-rspec-video/' rel='bookmark' title='Permanent Link: New Gem Generator gets RSpec [video]'>New Gem Generator gets RSpec [video]</a> <small> One day you will be able to write a...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="#rubigen-rejectconf-video">Go straight to video below</a></p>
<p>I took a video recorder to the RejectConf, like I did in Portland. Unfortunately, there were two reasons I didn&#8217;t record any of them.</p>
<p>Firstly, there didn&#8217;t seem to be any obvious place to position the camera.</p>
<p>Secondly, it was deemed critical that everyone does their talks in the dark. The conference isn&#8217;t run in the dark, local Ruby groups don&#8217;t run meetings in the dark but consecutive RejectConfs have been run by adminstrators with a dark fetish. Great for drinking beer and heckling presenters. Bad for video recording.</p>
<p>The makers of the <a href="http://www.jvc.com/presentations/everio_g/">JVC HDD camcorder</a> &#8211; a nifty device with a 20G HDD in it &#8211; don&#8217;t make it possible to record in the dark. Not because it doesn&#8217;t have a &#8220;night time mode&#8221; &#8211; apparently it does &#8211; but when you are already in the dark, you can&#8217;t figure out how to turn it on.</p>
<p>Ok, fine, if I&#8217;d made an effort I could have figured it out. So, let&#8217;s use excuse #1 as the reason for not recording the presentations.</p>
<p>Its a valid excuse, the Pirate Cove was chock-a-block full of people. The local Berlin Ruby Group did an awesome job of finding a great &#8220;underground&#8221;-esque venue. </p>
<p>Fortunately a fellow Australian &#8211; <a href="http://redartisan.com/blog">Marcus Crafter</a> &#8211; had a front row position, and a MacBook Pro. With said device, he captured my talk on RubiGen (<a href="http://redartisan.com/2007/9/22/rejectconf-europe-2007">and John Barton&#8217;s</a>). </p>
<h3 id="rubigen-rejectconf-video">RejectConf video of RubiGen</h3>
<p>In 5 minutes, I make a Merb generator, using <a href="http://rubigen.rubyforge.org">RubiGen</a> and <a href="http://newgem.rubyforge.org">NewGem</a>. Nifty stuff indeed. </p>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler"><param name="movie" value="http://www.viddler.com/player/b8b13c86/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/player/b8b13c86/" width="437" height="370" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler" ></embed></object></p>
<caption>Recorded and published by <a href="http://redartisan.com/2007/9/22/rejectconf-europe-2007">Marcus Crafter</a></caption>
<p>There were lots of other awesome presentations (that is perhaps a dubious inference that mine was awesome), but it was dark, I had beer in both hands, and I was too busy yelling &#8220;AUSTRALIA!!!&#8221; to write notes.</p>
<p>What a great night <img src='http://drnicwilliams.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2007/10/25/dr-nic-at-rubyconf-2007-rubigen-teaser/' rel='bookmark' title='Permanent Link: Dr Nic at RubyConf 2007 &#8211; RubiGen &#8211; Teaser'>Dr Nic at RubyConf 2007 &#8211; RubiGen &#8211; Teaser</a> <small>4th of November 2007 &#8211; 9am &#8211; main conference room...</small></li><li><a href='http://drnicwilliams.com/2007/06/02/ze-frank-at-railsconf-like-ted/' rel='bookmark' title='Permanent Link: Missed Ze Frank at Railsconf? [video]'>Missed Ze Frank at Railsconf? [video]</a> <small>Neat. Here is Ze Frank at TED 20062004 [thx Erik...</small></li><li><a href='http://drnicwilliams.com/2007/05/27/new-gem-generates-gets-rspec-video/' rel='bookmark' title='Permanent Link: New Gem Generator gets RSpec [video]'>New Gem Generator gets RSpec [video]</a> <small> One day you will be able to write a...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2007/09/22/rubigen-video-from-rejectconf-berlin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
