format internet:

…please wait (49% completed)…

Archive for April, 2009

Cucumber, Selenium, Webrat, and Windows

Posted by javier ramirez on April 27, 2009

I spent last Saturday hacking around with some really smart people in Madrid. It’s not widely known than in Spain there’s a thriving Ruby on Rails community -my guess would be a language thing- but if you take a look at some of the Rails patches, Hackfest winners or the official Rails documentation project, you would be surprised to see how many -and how good- contributions are coming from this side of the world.

Once in a while we like to get together and take code challenges, so we can learn from each other and eat pizza to match the stereotype ;)

Thing is I’m a Windows guy. I know I should be sorry, I know it’s for housewives (or househusbands for that matter), but that’s life. (disclaimer: I’m planning to switch to Ubuntu in the near future)

As you know, developing software in windows while entirely possible is a bit more difficult than in other systems, specially when it comes to compiling, forking and the like.

Last Saturday I was, as usual, the only windows at hand (the rest being a lot of Macs in different flavors and a lonely Ubuntu) and, as a part of the code challenge, I had to run some tests with Cucumber, Selenium and Webrat. Apart from libxml, that has been working flawlessly in my computer for months, no other binaries were involved, so you would think everything was working just fine.. well, think twice.

First problem was the test server couldn’t be started automatically. I didn’t investigate much about it (my guess being that a fork or a system call is being issued and Windows cannot cope with it) since it was easier just to start it manually before running the tests. Also it was faster, because it didn’t need to be started every time.

After this obstacle, when I was trying to run the tests, I was getting a cryptic Errno::EADDRNOTAVAIL message. At first I thought it was because of Selenium not being able to bind to the given port, but a quick test from the command line discarded that possibility.

I don’t know anything about webrat (yet) but as the song goes, with a little help from my friends I was able to locate the source of the problem. When connecting to remote control Selenium, Webrat is trying to bind to the address “0.0.0.0” and that’s something Windows doesn’t like.

All I had to do was opening the file “selecium_rc_server.rb” at the gem source and replacing “0.0.0.0” by “127.0.0.1”.

I was told I can do this much more clearly at the Webrat config, but I tried it out and I still had the same problem. Taking a look at the Webrat code I would say the config param is not honoured system-wide, but truth is I was in a hurry and I didn’t researched it thoroughly. I had a challenge to solve after all ;)

Once I did this, all was hunky dory. Selenium started, the form fields were filled in, the tests were passing (or not) and the result was displayed on my not-ansi console. Bummer.

Believe me, cucumber is not half the fun without the colors in the output. Fortunately enough, google can tell you where to find lots of ansi-aware console replacements. Unfortunately enough console2, my favourite, is not one of those.

So, there, it took a bit of extra work but now you can also run this neat stack in your good-old windows box.

Posted in development, javier ramirez, madrid, madridrb, ruby, ruby on rails, ruby on rails | Tagged: , , , | 6 Comments »

Speaking at EuRuKo 2009

Posted by javier ramirez on April 23, 2009

It’s only two weeks for EuRuKo 2009, the most important Ruby conference in Europe.

As you probably know, EuRuKo is a grassroots itinerant conference, entirely organized by -and for- Ruby developers. This year, the conference will be held in Barcelona, and I have the honor of being a -tiny- part of the organization as a member of the Spanish Ruby Users Group, the local group preparing the event.

It’s also pretty cool that ASPgems is one of the sponsors. I cannot help but feel a tang of pride (awww, the diva in me ;) ) when I see the commitment and support of the company when it comes to community events.

The list of scheduled talks looks promising. Starting with Matz’s keynote there will be sessions about things like cross-platform mobile development, voice-enabled applications, interacting with MIDI instruments from Ruby, Image processing and other non-typical uses of Ruby. They have the sweet scent of EPIC WIN all over.

Did you take a look at the list of talks? Any familiar names? Well.. yours truly’s talk proposal was accepted and I’ll be speaking about game development using Ruby and Gosu. How cool is that?

I’ve been speaking at other technical events before, and I have a good deal of experience in training, but this will be the first time I do this in English. I’m sure it’s going to be an enriching personal experience.

I’m looking forward to seeing you all there.

Posted in 1771, EuRuKo, javier ramirez, madrid, ruby, ruby, ruby on rails | Tagged: , , , , , , | Leave a Comment »

Parallel Assignment in Ruby and the conditional ternary operator

Posted by javier ramirez on April 8, 2009

You already know how parallel assignment in Ruby works

irb(main):001:0> a,b=1,2
=> [1, 2]
irb(main):002:0> p a
1
=> nil
irb(main):003:0> p b
2
=> nil

and you also know how the conditional operator (the only ternary operator in Ruby) works.

irb(main):004:0> false ? a : b
=> 2

so maybe you are thinking of putting that together and, given a “wadusable” object, do something like

wadusable = 'dummy value'
wadusable_type, wadusable_id = wadusable ? (wadusable.class.name,wadusable_id) : ('DefaultClass',default_id)

Well.. think twice.. the code above will FAIL.. syntax error. So.. does it mean I cannot mix the ternary operator with parallel assignment in Ruby? Not so fast.. after applying the technique of “Complaining Programming” (you heard it first here!) diego pointed me in the right direction.

Sometimes, I tend to forget Ruby plays pretty nice when there are no ambiguities, and allows us to do certain things like omitting parenthesis when calling a method, or forget about brackets in array literals.

But when there are ambiguities, then Ruby needs to know what we really want. In this case, what I have to do is specifically use brackets around the operator return values, so Ruby can properly make the parallel assignment.

wadusable = 'dummy value'
wadusable_type, wadusable_id = wadusable ? [wadusable.class.name,wadusable_id] : ['DefaultClass',default_id]

And that’s it.

Posted in development, javier ramirez, ruby | 2 Comments »

Upgrading to RadRails 1.2.1

Posted by javier ramirez on April 7, 2009

Aptana RadRails 1.2 is out there. If you are lucky enough, your Aptana installation will prompt you to upgrade and everything will go just fine.

In case your installation is a bit too old, or if you installed everything manually and when checking for updates Aptana says there’s nothing new, you can still install the latest version by using Eclipse “software updates”.

As Chris says in the forums, the update site for RadRails is http://update.aptana.com/update/rails/3.2/

When I tried to update by using that site, I got one error because this update depends on the latest version of Aptana Studio but, you guessed it right, Aptana check for updates insisted I had already the latest one.. but I knew I didn’t.

Once again, you can use Eclipse standard update procedure by using the Aptana Studio update site corresponding to your eclipse version, as explained here.

I’ve been using the latest version all day long and so far so good. It has some nice features like the rake files overview and the “explore files” option (I can finally say bye to the EasyStruts plugin), a polished interface, and improved compatibility with Eclipse 3.3 and 3.4.

Great work from the Aptana guys .

Posted in eclipse, javier ramirez, radrails, ruby, ruby on rails | Tagged: , , , | Leave a Comment »