ruby

Iron Languages Podcast – Episode I: We Have Lift-off

Posted in .NET, ironruby, podcast, ruby on June 24th, 2010 by Will – Comments Off

Mike Hall and I have finally gotten together and recorded our first episode of The Iron Languages Podcast.

In this episode, we chat about the Dynamic Language Runtime (DLR) and IronRuby in particular.

Some links related to topics we discussed:

Please let us know what you think, how we can improve and what you’d like to hear about. We hope you enjoy the podcast!

Using Factory Girl from C# with IronRuby for building .NET objects

Posted in .NET, ironruby, ruby on June 9th, 2010 by Will – 3 Comments

Recently at work, I’ve been using TDD to drive out the design for some WPF View Models. Part of what I’m doing is filtering a collection based on various properties of the elements in the collection. Of course, I’ve needed to build up that collection first. I’d come up with a very limited method using Action<T> to set properties when the builder method was called. While this worked for my needs, I got to thinking about a library I’ve used a couple of times on Rails projects: Factory Girl.

On numerous occasions working with C# on .NET, I’ve thought to myself “man, I really wish I had something like Factory Girl here!”. So, last night/this morning, I set out to create a spike solution to determine the feasibility of hosting IronRuby within my C# library, thus allowing me to use Factory Girl to build POCOs for me. The result:

OH YEAH!

Well, at least for the Factory.build method, but that’s all I was interested in for this spike.

I’ve put my code up on github for your perusal. For this particular solution I don’t think you’ll need Visual Studio 2010, but you will certainly need .NET 4 installed, as well as IronRuby. Also note that IronRuby needs to be installed into C:\IronRuby unless you want to edit the app.config and fix up some references.

I’m excited now about the possibilities of utilizing other Ruby libraries in my .NET projects!

I’m on Herding Code!

Posted in .NET, podcast, ruby on June 8th, 2010 by Will – Comments Off

Just a quicky here…

A couple of weeks ago, Cory Foy and I had a chat with the Herding Code guys. We talked about the differences between developing on the .NET platform and in Ruby/Rails. It was a great time. Please go give it a listen, and do let me know what you think!

Presentation: IronRuby for the Rubyist

Posted in .NET, ironruby, ruby on May 28th, 2010 by Will – Comments Off

Last night, I gave a talk at the Tampa Ruby Brigade about IronRuby, targeted at the developer who already knows and loves Ruby. About 10 people turned out, including the regional Microsoft Developer Evangelist, Joe Healy (nice to see Microsoft reaching out to other development communities!). The crowd was predominantly Mac users, and I had some concerns that the talk might not be well received. Boy, was I worried over nothing! This quote about sums up the reaction:

I was interested in IronRuby when it was first announced but had lost hope that it would ever be viable. Will did an awesome job of convincing me that it’s alive and well. Great talk.

– Barry Ezell

Nice! Below are the slides, and here are the (admittedly thin) demos up on Github.

IronRuby: `gem update –system`

Posted in gems, ironruby, ruby on May 18th, 2010 by Will – Comments Off

After reading this article on getting around the invalid exec_format “ir”, no %s issue when trying to update RubyGems in IronRuby, I came up with a better solution (rather than essentially swallowing the exception) to the problem. Stick the following file in: %IronRubyInstallDir%\lib\ruby\site_ruby\1.8\rubygems\defaults\ironruby.rb

1
2
3
4
5
6
7
8
9
10
11
12
module Gem
  def self.default_exec_format
    exec_format = ConfigMap[:ruby_install_name].sub('ir', '%s') rescue '%s'

    unless exec_format =~ /%s/ then
      raise Gem::Exception,
        "[BUG] invalid exec_format #{exec_format.inspect}, no %s"
    end

    exec_format
  end
end

I’m working on getting this contributed to the IronRuby project, as judging from the RubyGems sources, as well as the RubyGems sources distributed with JRuby, this is intended to be distributed by the Ruby implementation, not RubyGems itself.

Also note, this allows one to:

1
ir -S gem install bundler

My Patch to Ruby Gems for IronRuby support is in 1.3.7!

Posted in gems, ironruby, ruby on May 14th, 2010 by Will – 2 Comments

I’m now a published contributor to a major open source project!

C:\Users\Will>gem up –system

Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.7
Updating RubyGems to 1.3.7
Installing RubyGems 1.3.7
RubyGems 1.3.7 installed
=== 1.3.7 / 2010-05-13
NOTE:
http://rubygems.org is now the default source for downloading gems.
You may have sources set via ~/.gemrc, so you should replace
http://gems.rubyforge.org with http://rubygems.org
http://gems.rubyforge.org will continue to work for the forseeable future.
New features:
* `gem` commands
  * `gem install` and `gem fetch` now report alternate platforms when a
    matching one couldn't be found.
  * `gem contents` --prefix is now the default as specified in --help.  Bug
    #27211 by Mamoru Tasaka.
  * `gem fetch` can fetch of old versions again.  Bug #27960 by Eric Hankins.
  * `gem query` and friends output now lists platforms.  Bug #27856 by Greg
    Hazel.
  * `gem server` now allows specification of multiple gem dirs for
    documentation.  Bug #27573 by Yuki Sonoda.
  * `gem unpack` can unpack gems again.  Bug #27872 by Timothy Jones.
  * `gem unpack` now unpacks remote gems.
  * --user-install is no longer the default.  If you really liked it, see
    Gem::ConfigFile to learn how to set it by default.  (This change was made
    in 1.3.6)
* RubyGems now has platform support for IronRuby.  Patch #27951 by Will Green.
Bug fixes:
* Require rubygems/custom_require if --disable-gem was set.  Bug #27700 by
  Roger Pack.
* RubyGems now protects against exceptions being raised by plugins.
* rubygems/builder now requires user_interaction.  Ruby Bug #1040 by Phillip
  Toland.
* Gem::Dependency support #version_requirements= with a warning.  Fix for old
  Rails versions.  Bug #27868 by Wei Jen Lu.
* Gem::PackageTask depends on the package dir like the other rake package
  tasks so dependencies can be hooked up correctly.
------------------------------------------------------------------------------
RubyGems installed the following executables:
C:/Ruby/bin/gem
C:\Users\Will>

Sure, it’s a small contribution (having Ruby Gems recognize IronRuby as a platform), but an important one none the less. This allows us to create gems specifically for the .NET platform, similar to the way JRuby has JVM-specific gems.

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 »