<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss version="2.0">
  <channel>
    <title>Dan Manges</title>
    <link>http://www.dcmanges.com/blog</link>
    <pubDate>Sat, 19 Apr 2008 18:59:59 GMT</pubDate>
    <description>Dan Manges - Blog</description>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/dcmanges" type="application/rss+xml" /><item>
      <title>First Class vendor/gems</title>
      <link>http://www.dcmanges.com/blog/rails-first-class-vendor-gems</link>
      <description>&lt;p&gt;
A common way to add gems to vendor/gems is by using the &lt;tt&gt;gem unpack&lt;/tt&gt; command.&lt;br /&gt;
&lt;tt&gt;cd vendor/gems&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;gem unpack the_gem_name&lt;/tt&gt;
&lt;/p&gt;

&lt;p&gt;
And then loading them up using an approach like &lt;a href="http://blog.jayfields.com/2006/10/rails-autoloading-gems-in-vendor.html"&gt;this&lt;/a&gt;, &lt;a href="http://errtheblog.com/posts/50-vendor-everything"&gt;this&lt;/a&gt;, or something like this:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
Dir.glob(File.dirname(__FILE__) + "/../vendor/gems/*").each do |path|
  gem_name = File.basename(path.gsub(/-[\d\.]+$/, ''))
  $LOAD_PATH &lt;&lt; path + "/lib/"
  require gem_name
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
This feels like it should be unnecessary since Rubygems comes with a method to load a gem (&lt;tt&gt;gem&lt;/tt&gt;). It's really a second class way of using gems.
&lt;/p&gt;

&lt;p&gt;
Here's a solution I've been using for a while to keep gem code in vendor/gems, but still load them using the regular &lt;tt&gt;gem&lt;/tt&gt; method.
&lt;/p&gt;

&lt;p&gt;
First, a rake task to install gems.
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
namespace :gem do
  desc "install a gem into vendor/gems"
  task :install do
    if ENV["name"].nil?
      STDERR.puts "Usage: rake gem:install name=the_gem_name"; exit 1
    end
    sh "gem install #{ENV['name']} --install-dir=vendor/gems --no-rdoc --no-ri"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
Then, a little Rubygems magic to change GEM_PATH (I placed it at the top of environment.rb).
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
require "rubygems"
Gem.clear_paths
gem_paths = [
  File.expand_path("#{File.dirname(__FILE__)}/../vendor/gems"),
  Gem.default_dir,
]
gem_paths &lt;&lt; APPLE_GEM_HOME if defined?(APPLE_GEM_HOME)
Gem.send :set_paths, gem_paths.join(":")
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
Finally, using gems works in typical Rubygems fashion.
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
# somewhere in the code base
gem "hpricot", "0.6"
require "hpricot"
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;
I like this &lt;tt&gt;gem install&lt;/tt&gt; approach better than the &lt;tt&gt;gem unpack&lt;/tt&gt; one. &lt;a href="http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies"&gt;Gem dependencies&lt;/a&gt; are being added to Rails in 2.1, which should make this unnecessary. When I first looked at the code, it was using gem unpack, but also extracting the gem specification. I'm not sure if setting gem_path like this could simplify the Rails implementation or not.
&lt;/p&gt;

&lt;p&gt;
I only tested this approach on a Rails 2.0.2 app, using Rubygems 0.9.5 and 1.1.1. One additional benefit is that if you want to make sure your app doesn't depend on any locally installed gems, you can make vendor/gems the only directory in the gem path (although CruiseControl should be helping you with that problem anyway).
&lt;/p&gt;
</description>
      <pubDate>Sat, 19 Apr 2008 03:30:44 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/rails-first-class-vendor-gems</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>The Practicality of the RSpec Story Runner</title>
      <link>http://www.dcmanges.com/blog/practicality-of-the-rspec-story-runner</link>
      <description>&lt;p&gt;
On an internal ThoughtWorks mailing list, somebody recently asked if anybody had tried using the RSpec stories framework on a project yet. I considered using it for a Selenium-based acceptance test suite, but decided not to. Here is my response to the mailing list.
&lt;/p&gt;

&lt;p&gt;
I considered switching to the RSpec stories framework at [client name removed], but I have one big lingering issue with doing it.
&lt;/p&gt;

&lt;p&gt;
How well do acceptance criteria on a story correlate to focused selenium-based acceptance tests?
&lt;/p&gt;

&lt;p&gt;
Often I need several selenium tests to cover one acceptance criteria on a story. Other times, a couple acceptance criteria can be covered in a single test, although it is certainly not as common as having multiple tests for a single criteria.
&lt;/p&gt;

&lt;p&gt;
There's a couple scenarios there with using the story runner.
&lt;/p&gt;

&lt;p&gt;
(1) Automated acceptance tests that correspond to the exact acceptance criteria from a story.
&lt;br /&gt;
(2) Automated acceptance tests that don't correspond exactly to the acceptance criteria from the story, but are more suited to automated testing, written in a given/when/then style.
&lt;/p&gt;

&lt;p&gt;
Regarding (2), I mostly consider a test name/description a comment. Given/when/then can be inferred from the test implementation. Given = setup, when = action, then = assertions. So as far as leaving a comment on the test to perhaps provide a little more insight into intent, describe/it seems sufficient.
&lt;/p&gt;

&lt;p&gt;
Regarding (1), I like the idea of having traceability from a test to an acceptance criteria. But I feel acceptance criteria on a story card often do not correspond well with the tests that need to be written to verify the behavior. That may reflect on the quality of the acceptance criteria, but I'm not convinced they should be the same.
&lt;/p&gt;

&lt;p&gt;
Outside of this issue around acceptance criteria, I personally don't like how much the using the story framework fragments the test implementation. I also question the reusability of a template "given", "when", or "then."
&lt;/p&gt;

&lt;p&gt;
I would like to try using the story runner, but it doesn't seem any more beneficial than using describe/it.
&lt;/p&gt;
</description>
      <pubDate>Fri, 22 Feb 2008 06:25:16 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/practicality-of-the-rspec-story-runner</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Using DRb to Preserve a SeleniumDriver</title>
      <link>http://www.dcmanges.com/blog/using-drb-to-preserve-a-selenium-driver</link>
      <description>&lt;h3&gt;[Update] A Much Simpler Way&lt;/h3&gt;

&lt;p&gt;
  &lt;a href="http://ph7spot.com/"&gt;Philippe&lt;/a&gt; showed me a &lt;emph&gt;much&lt;/emph&gt; simpler way of keeping the &lt;tt&gt;SeleniumDriver&lt;/tt&gt; open. Start selenium like this:&lt;br /&gt;
&lt;tt&gt;selenium
-browserSessionReuse -proxyInjectionMode&lt;/tt&gt;
&lt;/p&gt;

&lt;p&gt;
  I'm leaving the original post here as an example of using DRb.
&lt;/p&gt;

&lt;h3&gt;Original Post&lt;/h3&gt;

&lt;p&gt;
Selenium is a great tool for web acceptance testing, but working on tests can be laborious. In addition to the general slowness of actually testing through the browser, starting a &lt;tt&gt;SeleniumDriver&lt;/tt&gt; takes about 6 seconds on my MacBook.
&lt;/p&gt;

&lt;h3&gt;SeleniumDriver Benchmark&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;
require "rubygems"
gem "Selenium"
require "selenium"

benchmark = Benchmark.measure do
  driver = Selenium::SeleniumDriver.new(
    "localhost", 4444,
    "*firefox", "http://localhost:3000"
  )
  driver.start
  driver.stop
end
benchmark.to_s
#=&gt; "  0.000000   0.000000   0.000000 (  6.294741)"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
If the selenium driver could stay open between test runs, running a test could be much faster. Fortunately, DRb makes this easy. Here are the rough steps.
&lt;/p&gt;

&lt;h3&gt;SeleniumDriver DRb Server&lt;/h3&gt;

&lt;p&gt;
First, start a SeleniumDriver and place it in a DRb service.
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
require "rubygems"
gem "Selenium"
require "selenium"
require "drb"

SERVER = "druby://:51785"

driver = Selenium::SeleniumDriver.new(
 "localhost", 4444,
 "*firefox", "http://localhost:3000"
)
driver.start
DRb.start_service SERVER, driver
puts "Ready"
DRb.thread.join  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
The &lt;tt&gt;DRb.thread.join&lt;/tt&gt; call at the end of this script means the script won't exit. Run it from a terminal, use Ctrl+C to stop it.
&lt;/p&gt;

&lt;h3&gt;SeleniumDriver DRb Client&lt;/h3&gt;

&lt;p&gt;
The next step is to use this instance when running tests. DRb provides a class that functions as a proxy to the object running in the server. In this case, that's the selenium driver.
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
DRb.start_service
driver = DRbObject.new(nil, SERVER)
class &lt;&lt; driver
  # make sure type hits method_missing to delegate to driver
  undef_method :type
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
  Using the DRbObject as a proxy to the SeleniumDriver requires hacking the type method to make sure it delegates properly.
&lt;/p&gt;

&lt;h3&gt;SeleniumDriver with DRb Benchmark&lt;/h3&gt;

&lt;p&gt;
Here's the benchmark for this version:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
benchmark = Benchmark.measure do
  DRb.start_service
  driver = DRbObject.new(nil, SERVER)
  class &lt;&lt; driver
    # make sure type hits method_missing to delegate to driver
    undef_method :type
  end
end
benchmark.to_s
#=&gt; 0.000000   0.000000   0.000000 (  0.070634)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
The time to start the driver is now negligible.
&lt;/p&gt;

&lt;p&gt;
  I've been using this for a few days, and it is working well. If you actually want to try this, here are a couple tweaks to the code that you'll want to make.
&lt;/p&gt;

&lt;h3&gt;Stopping the Server&lt;/h3&gt;

&lt;p&gt;
  To stop the SeleniumDriver when stopping the process, wrap &lt;tt&gt;DRb.thread.join&lt;/tt&gt; like this:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
begin
  DRb.thread.join
rescue Interrupt
  begin
    puts "Stopping..."
    driver.stop
  rescue Exception
    puts "failed stopping selenium driver"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Checking the Client Connection&lt;/h3&gt;

&lt;p&gt;
&lt;tt&gt;DRbObject&lt;/tt&gt; does not check the connection when it's first initialized. You may want to force it to check the connection by doing something like this:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
begin
  DRb.start_service
  driver = DRbObject.new(nil, SERVER)
  driver.respond_to?(:anything?)
rescue DRb::DRbConnError
  # do something
  # fail over to non-DRb driver?
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
  A call to &lt;tt&gt;respond_to?&lt;/tt&gt; will check to see if the DRb server is available. You may want print out an informative message or fail over to using a non-DRb driver if it cannot connect.
&lt;/p&gt;
</description>
      <pubDate>Thu, 14 Feb 2008 07:56:37 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/using-drb-to-preserve-a-selenium-driver</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Ruby Syntax Checker using Open3</title>
      <link>http://www.dcmanges.com/blog/ruby-syntax-checker-using-open3</link>
      <description>&lt;p&gt;
I recently needed to write code to check Ruby syntax.  The Open3 library made it trivial.  From the &lt;a href="http://www.ruby-doc.org/core/classes/Open3.html"&gt;RDoc&lt;/a&gt;:
&lt;/p&gt;

&lt;blockquote&gt;
Open3 grants you access to stdin, stdout, and stderr when running another program.
&lt;/blockquote&gt;

&lt;p&gt;
Here's the code for the syntax checker.
I also added an example of using Open3 with &lt;tt&gt;wc&lt;/tt&gt; to print out how many lines of code the file contained.
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
require "open3"

class SyntaxChecker
  def self.check(ruby)
    Open3.popen3 "ruby -wc" do |stdin, stdout, stderr|
      stdin.write ruby
      stdin.close
      output = stdout.read
      errors = stderr.read
      SyntaxCheckResult.new(output.any? ? output : errors)
    end
  end
end

class SyntaxCheckResult
  def initialize(output)
    @valid = (output == "Syntax OK\n")
    @output = output
  end
  
  def line_of_error
    $1.to_i if @output =~ /^-:(\d+):/
  end
  
  def valid?
    @valid
  end
end

l, w, c = Open3.popen3 "wc" do |stdin, stdout, stderr|
  stdin.write File.read($0)
  stdin.close
  stdout.read.split
end
puts "This file contains #{l} lines, #{w} words, and #{c} characters."

if __FILE__ == $0
  require "test/unit"
  
  class SyntaxCheckerTest &lt; Test::Unit::TestCase    
    def test_valid_syntax
      result = SyntaxChecker.check "this.is.valid.syntax"
      assert_equal true, result.valid?
    end
    
    def test_invalid_syntax
      result = SyntaxChecker.check "this.is -&gt; not -&gt; valid $ruby:syntax"
      assert_equal false, result.valid?
    end
    
    def test_invalid_syntax_line_number
      result = SyntaxChecker.check "line(1).is.okay\nline(2) is not :("
      assert_equal 2, result.line_of_error
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
Also see &lt;a href="http://popen4.rubyforge.org/"&gt;POpen4&lt;/a&gt;:
&lt;/p&gt;

&lt;blockquote&gt;
POpen4 provides the Rubyist a single API across platforms for executing a command in a child process with handles on stdout, stderr, stdin streams as well as access to the process ID and exit status.
&lt;/blockquote&gt;
</description>
      <pubDate>Thu, 27 Dec 2007 04:34:23 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/ruby-syntax-checker-using-open3</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Don't Be Clever</title>
      <link>http://www.dcmanges.com/blog/dont-be-clever</link>
      <description>&lt;p&gt;
Ryan Davis said his theme for 2007 is shaping up to be "&lt;a href="http://blog.zenspider.com/archives/2007/07/argh_stop_being_clever.html"&gt;don't be clever.&lt;/a&gt;"  However, it can be fun when pair programming to mess with your pair by writing some quick, clever code when he/she steps away.  I was pairing on some code that needed reference to the days of the week, so I dropped this in:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
DAYS_OF_THE_WEEK =
  (0..6).inject([]) { |a,i| [(Time.now + (i * 86400)).strftime("%A").downcase, *a] }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
After my pair came back and reacted how I expected him to, I replaced it with the better version:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
DAYS_OF_THE_WEEK = %w[monday tuesday wednesday thursday friday saturday sunday]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
And, to &lt;a href="http://ruby.sadi.st/Flog.html"&gt;flog&lt;/a&gt; them:
&lt;/p&gt;

&lt;pre&gt;
$ flog clever_days.rb 
Total score = 10.3653569644272

main#none: (10.4)
     3.3: assignment
     2.0: inject
     1.7: now
     1.7: *
     1.5: +
     1.3: strftime
     1.1: downcase
     1.0: branch
     0.5: lit_fixnum
&lt;/pre&gt;

&lt;p&gt;And the second version:&lt;/p&gt;

&lt;pre&gt;
$ flog better_days.rb 
Total score = 0

&lt;/pre&gt;

&lt;p&gt;
The flog score sums up the cost of cleverness well.  For more on this theme, I recommend watching &lt;a href="http://rubyconf2007.confreaks.com/d1t2p3_hurting_code.html"&gt;Ryan's RubyConf presentation&lt;/a&gt;.  
&lt;/p&gt;
</description>
      <pubDate>Thu, 13 Dec 2007 04:18:43 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/dont-be-clever</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Reading Gem Specifications</title>
      <link>http://www.dcmanges.com/blog/reading-gem-specifications</link>
      <description>&lt;p&gt;
When I was looking into &lt;a href="http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug"&gt;the problem&lt;/a&gt; with installing deep_test with Rubygems 0.9.4, I wanted to see if the bug occurred with other gems.  I noticed that the &lt;tt&gt;gem specification&lt;/tt&gt; command will display the spec for a gem that is installed locally, but I couldn't figure out how to get it to display the specification from a gem file.  I already had an &lt;a href="http://rubyforge.org/docman/view.php/5/231/mirror_setup.html"&gt;rsync mirror&lt;/a&gt; of the gem repository, so I wanted to go through all the files to look for any gems built with 0.9.5 without a platform.  Fortunately, Rubygems comes with a really easy way to read the specification from a gem file.  Here's the script I used:
&lt;/p&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
require "rubygems"
require "rubygems/package"

Dir["/Volumes/Backup/rubygems/*.gem"].each do |gem_file|
  begin
    Gem::Package.open(gem_file) do |gem|
      spec = gem.metadata
      if spec.platform == "" &amp;&amp; spec.rubygems_version == "0.9.5"
        puts "#{spec.name} #{spec.version.version}"
      end
    end
  rescue
  end
end
&lt;/code&gt;&lt;/pre&gt;
</description>
      <pubDate>Wed, 12 Dec 2007 03:02:35 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/reading-gem-specifications</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Rubygems 0.9.5 Platform Bug</title>
      <link>http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug</link>
      <description>&lt;p&gt;
If you're building a gem using Rubygems 0.9.5, make sure you have this line in your spec (assuming it's a pure-Ruby gem):
&lt;/p&gt;

&lt;pre&gt;
  specification = Gem::Specification.new do |s|
    s.platform = Gem::Platform::RUBY
&lt;/pre&gt;

&lt;p&gt;
Without it, the platform gets omitted and the gem cannot be installed from 0.9.4 clients.  The gem shows up like this in the gem list:
&lt;/p&gt;

&lt;pre&gt;
2. deep_test 1.0.3 ()
3. deep_test 1.0.2 (ruby)
4. deep_test 1.0.1 (ruby)
&lt;/pre&gt;

&lt;p&gt;
And then Rubygems tries to download the gem with an extra hyphen at the end of the filename:&lt;br /&gt;
http://gems.rubyforge.org/gems/deep_test-1.0.3-.gem
&lt;/p&gt;

&lt;p&gt;
I &lt;a href="http://rubyforge.org/tracker/?func=detail&amp;aid=16177&amp;group_id=126&amp;atid=575"&gt;logged a defect&lt;/a&gt; and posted a message to
&lt;a href="http://groups.google.com/group/ruby-talk-google/browse_thread/thread/036ee8f1d4cb0c92/f83b8a314179736f#f83b8a314179736f"&gt;ruby-talk&lt;/a&gt;.  I haven't had time to look into the code to submitt a patch (assuming this is undesired behavior).
&lt;/p&gt;

&lt;p&gt;

This happened to the following gems, and they will fail installing with 0.9.4:
&lt;/p&gt;

&lt;pre&gt;
addressable 1.0.1
aquarium 0.2.0
astro-algo 0.0.1
aurora 0.0.1
contextr 0.1.9
csspool 0.2.3
dango 0.0.38
dango 0.0.39
dango 0.1.0
dango_generator 0.0.38
dango_generator 0.0.39
dango_generator 0.1.0
deep_test 1.0.3
diy 1.0.1
el_req 0.0.1
faker 0.1.0
faker 0.2.0
faker 0.2.1
flac2mp3 0.2.0
gchart 0.1.0
gemsonrails 0.7.1
googlebase 0.1.1
googlereader 0.0.3
guessmethod 0.2.0
heel 0.6.0
oauth 0.1.1
polyglot 0.1.0
publisher 1.1.0
random_data 1.2.0
random_data 1.2.1
rawdio 0.1.0
roo 0.7.0
ruby-libtommath 0.41.0
rutema 0.4.1
rutema 0.4.2
sapo 0.0.2
yelp 0.2.0
yelp 0.2.1
&lt;/pre&gt;
</description>
      <pubDate>Tue, 11 Dec 2007 04:29:15 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Install Multiple Versions of Ruby on Leopard</title>
      <link>http://www.dcmanges.com/blog/install-multiple-versions-of-ruby-on-osx-leopard</link>
      <description>&lt;div&gt;
  &lt;p&gt;
I'm glad that Apple bundled Ruby (1.8.6) with Leopard, but I need 1.8.5 installed to ensure compatibility with some projects that are deployed on servers running 1.8.5.  Not only do I need 1.8.5, but I need it installed at different patch levels.  Here is how I set up OSX to have multiple versions of Ruby installed.
&lt;/p&gt;

&lt;h3&gt;Download&lt;/h3&gt;

&lt;p&gt;
The first step is to download the versions of Ruby you want to install from &lt;a href="ftp://ftp.ruby-lang.org/pub/ruby/1.8/"&gt;ftp://ftp.ruby-lang.org/pub/ruby/1.8/&lt;/a&gt;.  The latest 1.8.5 release is &lt;a href="ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-p114.tar.gz"&gt;ruby-1.8.5-p114.tar.gz&lt;/a&gt;, and may be sufficient unless you specifically want/need an older 1.8.5 release.
&lt;/p&gt;

&lt;h3&gt;Install&lt;/h3&gt;

&lt;p&gt;
Start by extracting the tarball you just downloaded:&lt;br /&gt;
&lt;tt&gt;tar zxvf ruby-1.8.5-p114.tar.gz&lt;/tt&gt;
&lt;/p&gt;

&lt;p&gt;
You can install Ruby in any directory you want to. I chose to put mine under /usr/local/ruby-&amp;lt;version&amp;gt;:&lt;br /&gt;
&lt;tt&gt;cd ./ruby-1.8.5-p114&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;./configure --prefix=/usr/local/ruby-1.8.5-p114&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;make&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;sudo make install&lt;/tt&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;p&gt;
You can confirm the installation by checking the Ruby version:&lt;br /&gt;
&lt;tt&gt;/usr/local/ruby-1.8.5-p114/bin/ruby --version&lt;/tt&gt;
&lt;/p&gt;

&lt;h3&gt;symlink for default Ruby version&lt;/h3&gt;

&lt;p&gt;
With multiple versions of Ruby, you'll want an easy way to switch between them.  One way to accomplish this is to create a symlink to the "current" version:&lt;br /&gt;
&lt;tt&gt;sudo ln -s /usr/local/ruby-1.8.5-p114 /usr/local/ruby&lt;/tt&gt;
&lt;/p&gt;

&lt;p&gt;
To switch to a different version by default, all you have to do is update the &lt;tt&gt;/usr/local/ruby&lt;/tt&gt; symlink. You can verify the version of Ruby the symlink is linking to by trying:&lt;br /&gt;
&lt;tt&gt;/usr/local/ruby/bin/ruby --version&lt;/tt&gt;
&lt;/p&gt;

&lt;h3&gt;symlink Leopard's version&lt;/h3&gt;

&lt;p&gt;
I also created a symlink for 1.8.6 to the default Leopard install:&lt;br /&gt;
&lt;tt&gt;sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/Current/usr /usr/local/ruby-1.8.6&lt;/tt&gt;
&lt;/p&gt;

&lt;h3&gt;/usr/bin executables&lt;/h3&gt;

&lt;p&gt;
Leopard has Ruby-related executables in /usr/bin symlinked to the executables from the pre-bundled install.  We need to change those to be able to toggle the Ruby version.  There are a couple ways this can be accomplished.  It should be done for all Ruby executables (cap, erb, gem, irb, rake, rdoc, ri, and ruby).
&lt;/p&gt;

&lt;p&gt;
One option is to remove those symlinks altogether, and then add &lt;tt&gt;/usr/local/ruby/bin&lt;/tt&gt; to the &lt;tt&gt;$PATH&lt;/tt&gt;.  That could be done by simply removing them from &lt;tt&gt;/usr/bin&lt;/tt&gt;:&lt;br /&gt;
&lt;tt&gt;sudo rm /usr/bin/ruby&lt;/tt&gt; (for all the executables mentioned above)&lt;br /&gt;
And then adding this line to &lt;tt&gt;~/.bash_login&lt;/tt&gt;:&lt;br /&gt;
&lt;tt&gt;export PATH="$PATH:/usr/local/ruby/bin"&lt;/tt&gt;
&lt;/p&gt;

&lt;p&gt;
The second option is to change the symlinks to point to the executables in &lt;tt&gt;/usr/local/ruby/bin&lt;/tt&gt;.  This isn't as favorable because any executable that is installed from a gem will be placed in &lt;tt&gt;/usr/local/ruby/bin&lt;/tt&gt;.  Unless you have that directory in your path (as mentioned with the previous option), you'll need a symlink for each executable.  I recommend going with the previous option for that reason.  However, you still may want to symlink the primary executables (namely, the core ones mentioned above) so that if your shell login script gets messed up, ruby, irb, gem, etc. will still be available.
&lt;/p&gt;

&lt;h3&gt;alias&lt;/h3&gt;

&lt;p&gt;
You may want to set up some aliases to make using and switching between Ruby versions simpler.  These could go in &lt;tt&gt;~/.bash_login&lt;/tt&gt;.  Here are some examples:
&lt;/p&gt;

&lt;p&gt;
For executing a specific ruby, gem, or rake:&lt;br /&gt;
&lt;tt&gt;alias ruby186=/usr/local/ruby-1.8.6/bin/ruby&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;alias rake186=/usr/local/ruby-1.8.6/bin/rake&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;alias gem186=/usr/local/ruby-1.8.6/bin/gem&lt;/tt&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;tt&gt;alias ruby185=/usr/local/ruby-1.8.5-p114/bin/ruby&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;alias rake185=/usr/local/ruby-1.8.5-p114/bin/rake&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;alias gem185=/usr/local/ruby-1.8.5-p114/bin/gem&lt;/tt&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;p&gt;
For switching the default symlink:&lt;br /&gt;
&lt;tt&gt;alias use_ruby_186='sudo ln -fhs /usr/local/ruby-1.8.6 /usr/local/ruby'&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;alias use_ruby_185='sudo ln -fhs /usr/local/ruby-1.8.5-p114 /usr/local/ruby'&lt;/tt&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;h3&gt;Rubygems&lt;/h3&gt;

&lt;p&gt;
The last thing to do is to install Rubygems.  Each Ruby installation will have its own copy of gems.  You can download the latest version of of Rubygems from the &lt;a href="http://rubyforge.org/frs/?group_id=126"&gt;Rubyforge project page&lt;/a&gt;.  After downloading, extract the archive, switch your Ruby version, and run setup.rb:&lt;br /&gt;
&lt;tt&gt;tar zxvf rubygems-0.9.4.tgz&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;cd rubygems-0.9.4&lt;/tt&gt;&lt;br /&gt;
&lt;tt&gt;use_ruby_185&lt;/tt&gt; (from alias)&lt;br /&gt;
&lt;tt&gt;sudo ruby setup.rb&lt;/tt&gt;&lt;br /&gt;
&lt;/p&gt;

&lt;p&gt;
Now you'll be able to install gems as normal using the &lt;tt&gt;gem&lt;/tt&gt; command.  Make sure you followed the steps with the /usr/bin executables so gem isn't always pointing to the 1.8.6 installation.
&lt;/p&gt;

&lt;p&gt;
This should be everything you need to do to have multiple versions of Ruby available.  I'll be writing an entry soon on how to take advantage of multiple installations to run test suites.  
&lt;/p&gt;


&lt;/div&gt;</description>
      <pubDate>Thu, 15 Nov 2007 06:00:00 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/install-multiple-versions-of-ruby-on-osx-leopard</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>Debugging Rails Integration Tests</title>
      <link>http://www.dcmanges.com/blog/debugging-rails-integration-tests</link>
      <description>&lt;div&gt;
  &lt;p&gt;Rails integration tests can be difficult to debug.  The tests are usually coarse grained, which makes isolating the cause of failure difficult.  A test to simply make sure a page is working (smoke test) might look like this:&lt;/p&gt;

&lt;pre class="code_ruby"&gt;
&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_get_show_user_url&lt;/span&gt;
  &lt;span class="ident"&gt;get&lt;/span&gt; &lt;span class="ident"&gt;show_user_url&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;User&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:first&lt;/span&gt;&lt;span class="punct"&gt;))&lt;/span&gt;
  &lt;span class="ident"&gt;assert_response&lt;/span&gt; &lt;span class="symbol"&gt;:success&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;This test is sufficient to make sure M, V, and C are all playing nice together.  However, if an exception is raised, the output from the test is this:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;Expected response to be a &lt;:success&gt;, but was &lt;500&gt;&lt;/:success&gt;&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Clearly not helpful in knowing what went wrong.&lt;/p&gt;

&lt;p&gt;The easiest thing to do is display the rendered output from the 500:&lt;/p&gt;

&lt;pre class="code_ruby"&gt;
&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;test_get_show_user_url&lt;/span&gt;
  &lt;span class="ident"&gt;get&lt;/span&gt; &lt;span class="ident"&gt;show_user_url&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;User&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:first&lt;/span&gt;&lt;span class="punct"&gt;))&lt;/span&gt;
  &lt;span class="ident"&gt;assert_response&lt;/span&gt; &lt;span class="symbol"&gt;:success&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="attribute"&gt;@response&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;body&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;
Here, &lt;tt&gt;@response.body&lt;/tt&gt; is the message for the assertion, and is only displayed if the response is not success.  This provides output that helps debug test failures, but the output is really noisy.  It's the HTML page that you normally see in your browser with a 500, and contains several stack traces and other debugging info.  It's great in the browser, not so great in the console.
&lt;/p&gt;

&lt;p&gt;
The best way to make the failures easy to debug is to let the exception be rescued by the test instead of by the controller.  To do this, you need to tell the controller and the dispatcher not to rescue:
&lt;/p&gt;

&lt;pre class="code_ruby"&gt;
&lt;span class="constant"&gt;ActionController&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;class_eval&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;perform_action&lt;/span&gt;
    &lt;span class="ident"&gt;perform_action_without_rescue&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="constant"&gt;Dispatcher&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;class_eval&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;self.failsafe_response&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;output&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;status&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;exception&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;nil&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="keyword"&gt;raise&lt;/span&gt; &lt;span class="ident"&gt;exception&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;This code should go in the test helper for your test suite.  Conventionally this will be: test/integration/integration_test_helper.rb&lt;/p&gt;


&lt;/div&gt;</description>
      <pubDate>Fri, 12 Oct 2007 05:00:00 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/debugging-rails-integration-tests</guid>
      <author>Dan Manges</author>
    </item>
    <item>
      <title>DeepTest Now Available</title>
      <link>http://www.dcmanges.com/blog/deep-test-now-available</link>
      <description>&lt;div&gt;
  &lt;p&gt;DeepTest is now available.  Use it to run your test suite nearly &lt;a href="http://www.dcmanges.com/blog/deep-test-preview"&gt;twice as fast&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Installation&lt;/h3&gt;

&lt;p&gt;&lt;tt&gt;gem install deep_test&lt;/tt&gt;&lt;/p&gt;

&lt;h3&gt;Usage&lt;/h3&gt;

&lt;pre class="code_ruby"&gt;
&lt;span class="constant"&gt;DeepTest&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;TestTask&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;task_name&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
  &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;pattern&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;test/**/*_test.rb&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
  &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;processes&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;2&lt;/span&gt; &lt;span class="comment"&gt;# optional, defaults to 2&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;h3&gt;More Information&lt;/h3&gt;

&lt;p&gt;For other details you need to know, &lt;a href="http://www.somethingnimble.com/bliki/deep-test"&gt;check out something nimble&lt;/a&gt;.&lt;/p&gt;


&lt;/div&gt;</description>
      <pubDate>Wed, 12 Sep 2007 05:00:00 GMT</pubDate>
      <guid>http://www.dcmanges.com/blog/deep-test-now-available</guid>
      <author>Dan Manges</author>
    </item>
  <feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetFeedData?uri=dcmanges</feedburner:awareness></channel>
</rss>
