28 June 2007

Getting the latest netbeans ruby-ide automatically

Update 12/11/2007: Blogger had completly destroyed the formatting of the code, I had a received a few emails telling me the script did not work. I have once again copy pasted it and it should work, I apologize if I have wasted your time, I should really move to a serious blogging system !!!

Update 10/04/2008: THE SCRIPT DOES NOT WORK ANYMORE. The Netbeans changed their nightly build system, you can download the latest version and install netbeans manually from http://bits.netbeans.org/download/trunk/nightly/latest/

I am using netbeans since april 2007 as my primary Rails editor on Linux ubuntu. I used to work with Radrails (now Aptana) because I used to be a java developper and work with Eclipse.

When RadRails "dissapeared", I started looking for alternative IDEs and so far I am very happy with netbeans.

Tor Norbye and his team are very active (and responsive!) and keep delivering new features all every week! The only way to use these features - as far as I am concerned - is to download the latest build from the Continuous Integration server at http://deadlock.netbeans.org/hudson/job/ruby/

To save a bit of time, I have written a script to install the latest netbeans ruby-ide automatically. You need to install the mechanize gem first.

This script will:
  • connect to the Continuous Integration server of sun (http://deadlock.netbeans.org/hudson/job/ruby/)
  • Guess what's the latest stable build file name and download it to a temp location (depending on your OS)
  • rename the old install
  • unzip the build to the netbeans installation folder
  • delete the downloaded zip from the tmp location

You need to install mechanize:

gem install mechanize

Hten, copy the following code to a ruby file and adapt the last two lines to your configuration. The 1st paramater is the "netbeans installation folder" and the
second one your tmp folder.


script = NetbeansUpdaterScript.new("/home/jeanmichel/ruby/programs", "/tmp")


require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'mechanize'
require 'fileutils'

class GenericScript
def download_from(url, save_as)
mechanize = WWW::Mechanize.new
puts "downloaded " + url + " and saved to " + save_as

def remove(file_or_directory)
FileUtils.remove_dir(file_or_directory, true) if File.directory?(file_or_directory)
FileUtils.rm file_or_directory if File.file?(file_or_directory)
puts "remove " + file_or_directory

def unzip_file(file, target_dir)
"unzip", "-q", file, "-d", target_dir
) or raise "Error extracting (#{$?}): unzip #{file.inspect} -d #{target_dir.inspect}"
puts "unzip " + file + " to " + target_dir

def is_using_mac?
RUBY_PLATFORM == /darwin/


class NetbeansUpdaterScript < tmp_folder = "/tmp" netbeans_installation_folder =" netbeans_installation_folder" netbeans_folder_path =" @netbeans_installation_folder" tmp_folder =" tmp_folder" netbeans_installer_file =" @tmp_folder" doc =" Hpricot(open(" last_stable_build_number =" doc.inner_html" last_stable_build_number=" + @last_stable_build_number.to_s @last_stable_build_number end def url_latest_build get_last_stable_build_number if is_using_mac? " script =" NetbeansUpdaterScript.new(">

I have used this script for a week and it seems to work alright but I'd be happy to hear some feedback about the code or any problem you might have.

Upgrading to Ubuntu Feisty

At last, I upgraded to the latest stable version of Ubuntu last week. So far, I am very pleased: my firefox, amarok, openoffice and netbeans were very unstable and now everything seems to worl like a charm! The network manager is also very cool: 30s to connecto to a WPA2 network!

However, the 3D and funky effects (Berryl window manager) don't work perfectly so I had to uninstall them (I can live without!).

Apart from the fact I could not find a good software for screencasting, I am very happy with Ubuntu even if I'll probably buy a mac in 2008 anyway

Well done Ubuntu!

08 June 2007

L_Appel du 8 juin

“Ici Paris, la Blogosphère parle aux francophones: Les pingouins qui, depuis de nombreuses années, sont à la tête des geeks francophones ont formé un projet de livrer des applications en retard avec du code non testé. Ces applications, alléguant la défaite de nos comités QA, se sont mis en rapport avec le GrandBugQuiNiqueTout pour cesser le combat. Certes, nous avons été, nous sommes, submergés par la tradition du cycle en cascade, la tradition du “Ca marche a 83%” et la loi de Murphy, de l'ennemi. Infiniment plus que leur nombre, ce sont l'absence de tests unitaires, une mauvaise communication et l'incompétence des personnes chargées du planning qui nous font reculer. Ce sont l'absence de reconnaissance de l'excellence technique des geeks qui aiment le travail bien fait, la horde de fichiers de configuration XML qui dupliquent sans fin les même informations et le manque d'”Agilité” des projets (Planning en continue, Itérations courtes, Tests Unitaires, Intégration Continue, Rétrospective) en générale qui ont surpris nos chefs au point de les amener là où ils en sont aujourd'hui. ....".

J'ai un rêve: publier un e-book en français pour début 2008 d'une centaine de pages de recettes sur le BDD on Rails avec rspec. Le titre provisoire est T.G.V.: "Testing à Grande Vitesse", en honneur à l'excellent système de transport publique de la SNCF.
Etant donné que je n'ai eu aucun contact avec la communauté Rails de France et de Navarre depuis 5 ans, je vais avoir besoin de sérieux coups de main pour me mettre à la page;-) Ecris-moi a jean tiret michel suivi d'un arobababase 21 croissant au PLURIEL petit point COM (j'ai tres peur des spammeurs) ou laisse un commentaire à ce post. Pour commencer, voici une petite idée de ce que j'ai derrrière la tête avec l'application web2.0 de mind mapping collaboratif mind42.com:

07 June 2007

Selenium reports with screenshots using RSpec and imagemagick on ubuntu

After having read Aslak Hellesoy's post Watir reports with screenshots using RSpec and Win32::Screenshot, I got very excited because this was exactly the kind of thing I had been daydreaming while taking my morning shower (don't you?).
Aslak's article explains how to use Watir and Internet Explorer on Windows to generate rspec reports with screenshots. Garps! I am working on linux (ubuntu Feisty) as I can't afford a mac (yet) and can't stand Windows. I got a bit frustrated because I wanted to do the same thing on my ubuntu.

So, I decided to do a bit of researches and x*y*z hours later (sic), I got my selenium+rspec taking screenshots! My intention is to contribute to the RSpec sub-project spec_ui.

How does it work?

To get a 30s answer, please watch the flah screencast I have made of netbeans executing rake spec:selenium, running the selenium server, Webrick, lanching firefox and taking a screenshot after having maximized the screen.

Here is the code in spec_helper.rb :

config.before(:all, :behaviour_type => :view) do
selenium_remote_control_manager = SeleniumRemoteControlManager.new
@browser = selenium_remote_control_manager.get_firefox

config.after(:each, :behaviour_type => :view) do

config.after(:all, :behaviour_type => :view) do
@browser.kill! rescue nil

And the code of contact_list_spec.rb:

describe "/contact/list", :behaviour_type => :view do
include SeleniumSpecHelper

it "should provide a description automatically (TODO extract)" do
open "/contact/list"
@browser.is_text_present("Frequently Texted").should be_true
# This line will fail :-)
@browser.is_text_present("All Contact Tak tak").should be_true


I have used imagemagick to capture the screenshot.

What's next?

I have had the chance to meet Aslak at an irb meeting in the beautiful Oslo and we talked about rspec and selenium. He told me about the idea of generating screencast from the execution of a selenium rspec and I have started to implement it. I am really close to get a solution but I will publish it by the end of july.

Here are a few features I'd like to have / implement for testing Rails Views:

  • a nice BNL compatible with watir and selenium
  • take a screenshot from the specs in order to generate nice documentation, not only when a spec fails
  • generate a good looking html doc with a sidebar - a la javadoc. And an AJAX search a la gotapi.com ;-) In a funky world, this would be connected to subversion and allow specs to be updated
  • to be completed ...

To conclude, I hope that tools such as greenpepper and RSpec are announcing the beginning of the end of "Microsoft Word" and "PrintScreen" as tools for writing specifications. Obviously, there will be some serious Manager / Customer / Developper resistance before accepting that tests are part of the delivery and THE only accurate specifications but let's wait for 5-10 years and see in 2012 how people work ;-)

05 June 2007

RSpec Changes log RSS

The excellent BDD framework RSpec has been very active these days, and the 1.0 version was immediatly followed by minor uptates. As their web site seems to not contain a blog or RSS feed, I have used the excellent idea and tool page2rss.com to generate a RSS feed on changes from the

http://rspec.rubyforge.org/changes.html page.

To receive updates for this page in RSS format copy-paste this link (http://page2rss.com/page/rss?url=rspec.rubyforge.org/changes.html) into your feed reader.

If you use one of the following reader, just click to the link to subscribe to Feed:

I have also shared my netvibes rspec tab which includes RSS on the mailing list archives (user & developper).
If you are using netvibes, you can add it by cliking on Add to Netvibes

Otherwise, here are 2 screenshots to give you a ruff idea:

The different modules (RSS and links):

If you want to suggest more, please contact me ;-)

Netvibes has a new feature which allow to preview web sites without leaving the netvibes window. Just clik on the right hand corner button: "Show website". Doing this, I can skim first through the titles and then preview the web sites to read the details of each post: so cool!

Don't wait, install netvibes now!

The RSS for the user & developpers' list comes from nabble.com

Before finding out about nabble, I have been trying for the first time Yahoo!pipes and I have to say I love it!!! I have a feeling it's going to be one of my favourite gadget. It is a very user friendly tool with a fantastic user interface, it took me 45 minutes to write the pipe which generates the url http://page2rss.com/page/atom?url=rubyforge.org/pipermail/rspec-devel/2007-June/thread.html
from today's date. The only issue was that Yahoo!pipes truncated the post content because the RSS generated by the page2rss.com did not give a title to the posts ...

Technorati Tags ,

Set up rspec on Rails

I have described the steps to install and configure rspec, the Autotest module from ZenTest and a notifier for Ubuntu.

Make sure you have the latest rubygems (0.9.4)

sudo gem update --system

Installing  rspec

At the time of this writing - 5th of June 2007 - latest version of rspec is 1.0.4, and we'll install it in the vendor/plugins:

cd <your project home>
ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec
ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rail
Check out http://rspec.rubyforge.org/ for updates (I could not find a RSS) but I guess Aslak will be updates on his blog.

Warning: if you had installed rspec before, run a "gem list" to check if you have a web_spec rogue gem, you must delete it before carrying on, more details in Zenspider's blog.

Installing and configuring Zentest

Latest version of ZenTest is 3.6.0, run
sudo gem install ZenTest
Thankfully due to the extensible nature of autotest, we'll be able to set up a notifier for ubuntu by adding the following to your <Rails project root>/.autotest file:


#!/usr/bin/env ruby

module Autotest::GnomeNotify

# Time notification will be displayed before disappearing automatically
ERROR_STOCK_ICON = "gtk-dialog-error"
SUCCESS_STOCK_ICON = "gtk-dialog-info"

# Convenience method to send an error notification message
# [stock_icon] Stock icon name of icon to display
# [title] Notification message title
# [message] Core message for the notification
def self.notify stock_icon, title, message
options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
system "notify-send #{options} '#{title}' '#{message}'"

Autotest.add_hook :red do |at|
notify ERROR_STOCK_ICON, "Tests failed", "#{at.files_to_test.size} tests failed"

Autotest.add_hook :green do |at|
notify SUCCESS_STOCK_ICON, "All tests passed, good job!", ""


# a pop up window will appear to display the tests results
# More examples in /usr/lib/ruby/gems/1.8/gems/zentest-3.5.0/example_dot_autotest.rb

# see http://ph7spot.com/articles/getting_started_with_autotest

The GnomeNotify was written by Philippe Hanrigou, a French Thoughtworker living in California, he has written the best "getting started" guide to Autotest. To install libnotify on ubuntu, run:
sudo apt-get install libnotify-bin

Finally, from the Rails project’s root, type:


Pressing Control-C twice in quick succession will exit Autotest back to the shell prompt.

Integration with netbeans

As far as I am concerned, netbeans ruby-ide is the first IDE to integrate autotest. Select your project root in the Projects windows, right click and then "Auto Test". This will open an output window and run Autotest. This is very cool, check out the screenshot: