Archive for the ‘Ruby’ Category

Making Peace with JavaScript and Prototype

Tuesday, May 16th, 2006

I just rocked out some sweet ass JavaScript/Prototype/RJS code for Mailroom. I won’t spoil the surprise by announcing what it does, because we can probably make a nice todo out of it on the Big Act.

It took some time for me to make friends with JavaScript. It always seemed like a hackish, backwards kind of language.

But between Prototype, Rails’ RJS Templates and a little good-ol fashioned JavaScript, you can accomplish miracles. (But, I probably shouldn’t speak too soon… We need to put some polish on the hacks I just wrote.)

LightWeight Modeling in Java

Thursday, April 27th, 2006

A friend who’s attending the php|tek conference said there was a bit of Ruby bashing going on. Of course, he reports as well, Java is feeling a much bigger brunt of the heat.

I’ve decided to officially stop saying negative things about my fellow Java/J2EE brethren.

Seeing articles like this, make me realize that saying bad things about Java/J2EE, is like kicking a defenseless puppy while he’s down.

It just isn’t right, and chances are, the usage of Java in many enterprise shops was carved in stone some 3-5 odd years ago after a middle-manager read about its cross-platform benefits in a Delta Airlines in-flight magazine. (oops, there I go again!! my bad…)

I’m just sorry, guys. Sorry.


You may say that I’m a dreamer
But I’m not the only one
I hope someday you’ll join us
And the world will be as one

- John Lennon, Imagine

JavaScript / Selenium Testing in Ruby on Rails

Thursday, April 13th, 2006

My buddy Gabriel links to JTF — JavaScript unit Testing Farm.

How does it work? From the site:

You write your javascript and insert some code to indicate a failure (or a pass) using the same functions as in JsUnit and other unit testing frameworks. Then, every time a visitor views your test case, it performs the unit test on their browser… providing information if the test fails.

Sounds like a novel idea.

Over at Sprout we now have a suite of Selenium JavaScript-based acceptance tests.

It was a little tricky, but our Selenium tests for Mailroom now pass in the following browsers:
- IE6 on XP
- Firefox on XP
- Firefox on OS X
- Safari on OS X

The first thing Charles asked me was… if we already have Unit & Functional tests already, why do we need Selenium ones too?

Granted, Selenium tests are not necessary for a small startup. But at previous employers, full-time Testers have been employed whose sole job was to:
- sit around for 4-5 days a week (waiting for a new release)
- if the developers happened to have a new release ready by Friday, the Testers would jump into action and earn their $37k a year in one afternoon per week.

Many lessons can be learned from this anecdote, but one is: hire someone who can automate away his or her own job in a few weeks and move onto things that cannot be automated.

Writing Selenium Tests in Rails

Often I feel the urge to simply create a new Selenium test for a new feature that we implement. There’s nothing like a full UI-based end-to-end test to see if something is functioning properly. (this could just be a psychological phenomena)

But, we also add Unit & Functional tests, and then sometimes maybe Selenium tests. That’s some pretty good code coverage. :)

Selenium on Rails Links

Selenium on Rails Plugin (Recommended)

Automate Acceptance Tests with Selenium

There is an alternative Selenium on Rails plugin floating around that comes up a lot higher in Google searches.

It’s sad because the devs on this other plugin did a tremendous job at marketing (and developing) their plugin, but I am not as impressed with it as the one mentioned above. Here’s a link, which includes a nice screencast:
Selenium on Rails Plugin

Screencasts are the *ultimate* linkbait! I needs to make me some of dem!

OS X Update Killed My Rails!

Tuesday, April 4th, 2006

I thought this was a problem only associated with Microsoft updates! Apparently not!

If you compiled Ruby from source, following instructions from this Hivelogic tutorial, the latest OS X Tiger update may have killed your symbolic link to Ruby 1.8.4.

(This assumes you had installed Ruby 1.8.4 to /usr/local and had symbolically linked to this binary from /usr/bin/ruby)

Simple enough solution though:

cd /usr/bin
sudo mv ruby ruby.back
sudo ln -s /usr/local/bin/ruby /usr/bin/ruby

Now try a “ruby -v” and you should see 1.8.4 as the version.

(In defense of OS X — at least I’m not rebooting into 8bit, 16color 800×600 resolution on my 20″ flatscreen, as has happened w/ MS updates before.)

Rails 1.1 and RJS Templates for Easily Ajaxifying your Webapp

Friday, March 31st, 2006

Rails 1.1 has arrived!

RJS is a templating language that allows you to write JavaScript in a native Ruby style.

Some Good RJS Links

Cody Fauser's Intro to Rails' RJS
More on RJS and some of its advanced features
Rails JavaScript Generator Methods

Now, here's an absolute Must-Have RJS Debugging Snippet to drop into your rhtml page when you're playing around with this stuff:

RUBY:
  1. <div id="debug">
  2. </div>
  3. <script type="text/javascript">
  4.     Ajax.Responders.register({
  5.     // log the beginning of the requests
  6.     onCreate: function(request, transport) {
  7.     new Insertion.Bottom('debug', '<p><strong>[' + new Date().toString() + '] accessing ' + request.url + '</strong></p>')
  8.     },
  9.    
  10.     // log the completion of the requests
  11.     onComplete: function(request, transport) {
  12.     new Insertion.Bottom('debug',
  13.     '<p><strong>http status: ' + transport.status + '</strong></p>' +
  14.     '<pre>' + transport.responseText.escapeHTML() + '</pre>')
  15.     }
  16.     });
  17. </script>

(via techno-weenie)

Ruby: Calling Methods Dynamically

Tuesday, March 21st, 2006

Let's say you have three very similar methods in your Rails app:

class Clown
 def do_something_one(foo, baz)
 end

 def do_something_two(foo, baz)
 end

 def do_something_three(foo, baz)
 end
end

You also have a slew of helper methods, that call each method, and do something else with the foo & baz objects (like serialize and log them to a DB, for example).

I had googled around a while for a way to instead just have one helper method:

 def do_something_generic(which_thing = 'one', foo, baz)
    # Dynimcally call one of the three methods,
    #    based on the 'which_thing' parameter.

    # Are any Ruby mavens in da house?  Is this right? :
    c = Clown.new
    c.send 'do_something_#{which_thing}', foo, baz

 end

How to Call Methods Dynamically in Ruby


You are currently browsing the Shanti's Dispatches weblog archives for the 'Ruby' category.

Shanti A. Braford blogs here.

If you really want to know, just read this.



  

Powered by FeedBlitz