ruby

Setting up Ubuntu 9.10 for Ruby and Rails Development in VirtualBox on Windows

Posted in Linux, Ubuntu, VirtualBox, rails, ruby on January 2nd, 2010 by Will – 2 Comments

I now believe that if you’re serious about creating Rails apps, you aren’t doing it on Windows. Or, you are a masochist.

That’s a quote from me. I’m done trying to do serious Ruby & Rails development on Windows. As of January 1st, 2010, I have not found a Ruby implementation on Windows that is fast enough to support the TDD/BDD workflow that Corey Haines exhibits in his Number to LCD code kata. On top of that, I wasted 2 days on trying to get Selenium and Cucumber to work together in Windows. I was venting about this on Twitter when Cory Foy made a suggestion:

@hotgazpacho You know, I don’t know why you don’t just run a VM with Linux on it for Rails dev. That’s what I have on my Windows box.

I didn’t know why either. My first concern was memory consumption (my personal notebook only has 2 GB of RAM in it), but both Cory and Robert Dempsey allayed my fears:

@hotgazpacho 2GB should be plenty. The Linux VM should only need 512. Would help to run the VM on an external drive if you’ve got one

@cory_foy @hotgazpacho I run linux ubuntu vm’s (vmware) on my MBP and 512 is more than enough if you don’t use a heavy IDE. Runs very well

So, I went ahead and set up Ubuntu 9.10 in a VirtualBox virtual machine (VirtualBox is a free virtualization product from Sun, similar to VMWare Workstation or Microsoft Virtual PC). The results were astounding! On a Rails app I was working on, all the RSpec examples and Cucumber features ran in less than the time it took for the MingW Ruby interpreter to start up. WOW! We’re talking orders of magnitude faster, and all in less memory than it takes to boot Windows. I’m sold.

Here’s how I set up the VM:

  1. Install VirtualBox
  2. Create a new VB VM for Ubuntu
    The Ubuntu Community wiki has pretty good documentation (for Ubuntu host, but UI is pretty much identical on Windows)
  3. Make sure the system is up-to-date (it won’t be). Let update manager run & reboot
  4. Install Virtual Box additions & reboot
  5. Install pre-requirements for building stuff (note: I may be missing some stuff. If I am, Ruby Enterprise Edition installer will let you know and tell you what is missing):
    1
    sudo apt-get install build-essential libpcre3 libxml2-dev libxslt1-dev sqlite3 libsqlite3-dev –y
  6. Ruby Enterprise Edition (cause this is what I run on my production server)
    1
    wget -c http://rubyforge.org/frs/download.php/66162/ruby-enterprise-1.8.7-2009.10.tar.gz        <br />tar xzvf ruby-enterprise-1.8.7-2009.10.tar.gz         <br />sudo ./ruby-enterprise-1.8.7-2009.10/installer

  7. Add Ruby Enterprise Edition bin path to "secure path" for sudo
    1
    sudo visudo

    Change line starting with Defaults to the following:

    1
    Defaults env_reset, secure_path=/opt/ruby-enterprise-1.8.7-2009.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  8. Install gmate, which makes gEdit behave like TextMate. Instructions are on the gmate github page.
  9. Make gem not install rdoc and ri by default.
    1
    echo "gem: --no-rdoc --no-ri" >> ~/.gemrc
  10. Install Rails, Sqlite, ZenTest, RSpec, Cucumber, & Factory Girl
    1
    sudo gem i rails sqlite3-ruby ZenTest rspec cucumber factory_girl
  11. Make cucumber feature running part of autospec runs
    1
    echo "export AUTOFEATURE=true" >> ~/.profile

One Minor Problem…

There’s only one minor problem with this whole setup. Cory Foy articulated it best:

@hotgazpacho The problem is now you’ll /really/ not be happy doing Rails on Windows. Ever. :)

This is a problem I can live with :)

For some additional fun…

…you might want to install the following:

  1. git-prompt, bash prompt with GIT, SVN and HG modules

    1
    git clone git://github.com/lvv/git-prompt.git && echo ". ~/git-prompt/git-prompt.sh" >> ~/.profile
  2. Autotest/Autospec notifications to Ubuntu system notifications (similar to Growl on OS X)
    1
    sudo gem i test_notifier && echo "require 'test_notifier/autotest'" >> ~/.autotest
  3. Sounds for Autotest events – http://www.fozworks.com/2007/7/28/autotest-sound-effects
    1
    sudo apt-get install mpg321 && wget -c http://www.fozworks.com/static/autotest-sound-1_2.zip && gunzip autotest-sound-1_2.zip && echo "require '~/autotest/sound/sound.rb'" >> ~/.autotest && echo "Autotest::Sound.sound_path = '~/autotest/sound/sound_fx/'" >> ~/.autotest

IronRuby, Cucumber, & win32console: Picking up the Gauntlet

Posted in .Net, cucumber, gems, ironruby, ruby on June 20th, 2009 by Will – 5 Comments

Shortly after I published my previous post on getting IronRuby working with Cucumber, I did a git pull and recompile from the IronRuby repo. Well, something changed which broke command line option parsing for igem. I’m happy to report that this commit appears to have fixed the issue. Yay!

Also, I’ve forked IronRuby on GitHub and have made the changes I documented on the previous post to Dev.bat. I plan to track IronRuby closely, so if you don’t want to follow all the directions (I still recommend setting up the shortcut to dev.bat), you can simply clone my repo.

Finally, Shri Borde put out a call on the IronRuby mailing list asking if anyone was interested in porting win32console to IronRuby. As Shri pointed out, this is important because Cucumber makes use of win32console on windows platforms to colorize the output of cucumber runs. This makes it much easier to visualize what works, what’s broken, and what steps you need to write. Since I have more than a passing interest in getting Cucumber working for .Net apps, I am going to pick up the gauntlet and attempt to port it myself. Behold ironruby-win32console. Now, to figure out how to do it…

Cucumber and IronRuby: It Runs!

Posted in .Net, ironruby, ruby on June 14th, 2009 by Will – 9 Comments

Ever since I read about Cucumber, a user acceptance testing tool in Ruby, I’ve wanted to be able to use it, along with IronRuby for my .Net projects. I got it working once, briefly, using the directions on the Cucumber wiki at GitHub. With an uncertain combination of IronRuby updates and Cucumber updates, it stopped working for me. Well, this evening, I decided to delve into it once again, and I am now happy to report that it works! Well, works, as in runs the C# sample provided with the Cucumber gem. I know present to you the steps I took to get it working, from end to end (I’ll assume you have some version of Visual Studio 2008 with C#):

1 – Install MSysGit

Head on over the the MSysGit page, grab the latest Git-1.6.x.y install, and run it. At the time of this writing, I’m using 1.6.2.2-preview20090408

2 – Grab the IronRuby sources

I prefer to do all my development work in C:\Development. Pop open a Git Bash console (Start > Programs > Git > Git Bash) and issue the following commands:

cd /C/Development
git clone git://github.com/ironruby/ironruby.git
git pull

OR, if you’re behind a corporate firewall…

cd /C/Development
git clone http://github.com/ironruby/ironruby.git
git pull

3 – Set Up IronRuby Dev Environment

This comes straight from the dev.bat entry in the IronRuby wiki on GitHub:

We recommend you start your developing by running

1
C:\path\to\Merlin\Main\Languages\Ruby\Scripts\Dev.bat

. This batch file sets up the path, various environment variables, and aliases, which makes it easy to do builds and run tests.

It is recommended to setup a shortcut to Dev.bat on the desktop that you can just click to quickly get the pre-configured environment. To do this, create a shortcut on the Desktop to cmd.exe (where C:\Development\ironruby is the root of your GIT repo) looking like CmdShortcut.png at http://www.ironruby.net/Support/Images. The values of the text fields should be like this:

Target:

1
C:\Windows\System32\cmd.exe /k &quot;c:\Development\IronRuby\Merlin\Main\Languages\Ruby\Scripts\Dev.bat&quot;

Start in:

1
c:\Development\IronRuby\Merlin\Main\Languages\Ruby

I highly recommend reading the rest of that wiki entry. It explains how the IronRuby sources are laid out.

I’m also made a change to Dev.bat. On line 43, after :EnvDone, the script changes the path. I’m going to prepend the path to the IronRuby interpreter, which we’ll compile in the next step. Why prepend? Well, I also have MRI in my path, and I found that the commands in C:\Ruby\bin were getting called instead of the IronRuby versions. This is what I believe was leading to all the difficulties I had in the past. So, the call to SET PATH should look something like this:

1
set PATH=%MERLIN_ROOT%\Bin\debug;%PATH%;%MERLIN_ROOT%\Languages\Ruby\Scripts;%MERLIN_ROOT%\Languages\Ruby\Scripts\bin;%RUBY18_BIN%;%MERLIN_ROOT%\..\External.LCA_RESTRICTED\Languages\IronRuby\mspec\mspec\bin

Addendum – June 14th, 2009

After some feedback on this post from Jimmy Schementi and Jim Deville of the IronRuby team, you’re going to want to set another environment variable, called GEM_BIN. We will reference this variable later, when we go to install gems for IronRuby. After the line that sets GEM_PATH, about line 16, you want to include this additional line:

1
set GEM_BIN=%MERLIN_ROOT%\Languages\Ruby\Scripts\Bin

Adding this will allow us to tell Ruby Gems where to put the scripts needed to run cucumber, or any other gem. I’ve chosen %MERLIN_ROOT%\Languages\Ruby\Scripts\Bin, on Jimmy’s suggestion, because it is already in the path set by Dev.bat, and IronRuby distributes a number of other wrapper scripts, such as igem, irake, and irails in this directory.

4 – Compile IronRuby

Pop open the IronRuby Development console (the shortcut you created in the previous step), and run

1
brbd

(Build RuBy Debug).

5 – Install the Cucumber Gem

IronRuby comes with a command called igem, which runs the gem command using IronRuby, as opposed to the standard MRI. In that same development console, run:

1
igem install –-no-rdoc -–no-ri –-bindir %GEM_BIN% cucumber

That’s a lot to type! We could stick all these options into a .gemrc file in our home directory, but this is problematic if you have and use multiple versions of Ruby on your machine (and you most likely will). Any suggestions for accommodating the scenario of multiple Ruby versions with seperate Gem locations would be very much appreciated! Now, back to the show!

I’m choosing to include the

1
–-no-rdoc

and

1
-–no-ri

because RDoc and RI generation is slooooow, and I can’t recall the last time I looked at either.

I’m also passing the

1
–-bindir

argument so that the wrapper scripts for the gems I install will be placed into a directory that is in my path, but will not get overwritten every time I recompile IronRuby.

This will install the gem files into

1
C:\Development\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ironruby\gems\1.8\gems\cucumber-xxxx

, where xxxx is the latest version of Cucumber. I’m going to use cucumber-xxxx in the next step to signify the folder that cucumber gets installed into.

This will also install the

1
cucumber &amp; cucumber.bat

wrapper scripts into

1
<strike>C:\Development\ironruby\Merlin\Main\Bin\debug</strike>C:\Development\ironruby\Merlin\Main\Languages\Ruby\Scripts\Bin

6 – Verify that it Works

Here comes the cool part. In that same IronRuby dev console window, do the following:

cd C:\Development\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ironruby\gems\1.8\gems\cucumber-xxxx\examples\cs
compile.bat
cucumber features

This is the output that I got:

*** WARNING: You must "gem install win32console" (1.2.0 or higher) to get colour
ed output on MRI/Windows
Feature: Addition
  In order to avoid silly mistakes
  As a math idiot
  I want to be told the sum of two numbers

unknown:0: warning: multiple values for a block parameter (2 for 1)
unknown:0: warning: multiple values for a block parameter (2 for 1)
  Scenario Outline: Add two numbers                    # features/addition.feature:6
unknown:0: warning: multiple values for a block parameter (2 for 1)
    Given I have entered
 into the calculator # features/step_definitons/calculator_steps.rb:9
unknown:0: warning: multiple values for a block parameter (2 for 1)
    And I have entered
 into the calculator   # features/step_definitons/calculator_steps.rb:9
unknown:0: warning: multiple values for a block parameter (2 for 1)
    When I press add                                   # features/step_definitons/calculator_steps.rb:13
unknown:0: warning: multiple values for a block parameter (2 for 1)
    Then the result should be  on the screen   # features/step_definitons/calculator_steps.rb:17

    Examples:
      | input_1 | input_2 | output |
      | 20      | 30      | 50     |
      | 2       | 5       | 7      |
      | 0       | 40      | 40     |

3 scenarios (3 passed)
12 steps (12 passed)
0m3.734s

Notice that there are still some warnings. I know John Lam and the rest of the IronRuby team are working hard for to get this working for the 1.0 release, due on or about July 23rd, 2009. Most importantly, though, it functions now. Cool beans!

SUPER KIND-OF IMPORTANT NOTE!

Any time you rebuild IronRuby, the C# compiler will erase the contents of the directory

1
C:\Development\IronRuby\Merlin\Main\Bin\Debug

. This includes the cucumber and cucumber.bat files. The only way I know to rectify this is to

1
<strike>igem install -–no-rdoc -–no-ri cucumber</strike>

once again. Thanks to feedback from the IronRuby team, I’ve detailed a fix above. You will only have to install gems once, regardless of how often you recompile IronRuby.

Rails 2.3.0 + IIS7 + FastCGI = Rails on Windows FTW!

Posted in rails, ruby on February 8th, 2009 by Will – 8 Comments

I love Rails, and I run Windows.

There, I said it. I know many Railers scoff at us, mock us, etc. Whatever. I run Windows (Vista, specifically). I’m a Microsoft.Net Web Developer at my day job. My company has invested heavily in the Microsoft platform. I don’t like WebForms (why is a topic for another post), and, because of Rails, I know there is a better way to do web development. Yes, I know about ASP.Net MVC, but I have yet to try it. What I have tried is Rails, and I know that a Microsoft stack is the way to get it into my day-to-day work.

So, a couple of days ago, with the announcement of Rails 2.3.0 rc1 I decided to see if I could get the latest Rails running under IIS 7 on my Vista notebook. I tried to find directions on how to accomplish this, but none were very straight forward. So, I’ve decided to document the process here for myself and other WinRailers.

read more »