Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of script.aculo.us, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Freckle Time Tracking and Every Time Zone and write books like Retinafy.me.
   Want me to speak at your conference? Contact me!

BDD-style JavaScript testing

August 29th, 2006

Borrowing from Behaviour Driven Development techniques, especially the RSpec framework I’ve added some new features to script.aculo.us’ testing library.

It’s all about more readability, and even non-technical folk should be able to comprehend (at least some) of the tests. Let’s have a look:

1
2
3
4
5
6
7
8
9
Test.context("BDD-style testing",{
  'should automatically add extensions to strings': function(){
    'a'.shouldEqual('a');
    'a'.shouldNotEqual('b');
    'a'.shouldNotBeNull();
    'a'.shouldBeA(String);
    'a'.shouldNotBeA(Number);
  }
});

Basically, you’re defining a context for which one or more specifications should be asserted. Note the easy readability, and the added value by using a string to describe the test/specification, giving you the advantage of having better documentation for your JavaScript libraries.

Of course, setup and teardown is also supported, as are all normal assert* methods.

If you code in the Prototoypian way, with proper objects, an other added value, especially for higher-level behavioural specifications is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var testObj = {
  isNice: function(){
    return true;
  },
  isBroken: function(){
    return false;
  }
}

// in Test.context
'should add object extensions': function(){
  Object.extend(testObj, Test.BDDMethods); 
  testObj.shouldBe('nice');
  testObj.shouldNotBe('broken');
},

Note that the support for this is far from complete, and JavaScript has certain limitatons that won’t allow all the elegant solutions that are possible with Ruby, but your tests can get much cleaner this way.

For now, you’ll need the script.aculo.us version from the SVN trunk. For more examples, see the repository file browser: test file, test library.

JavaScript decorator pattern

August 25th, 2006

Decorator pattern in JavaScript? Sure can do. Read the article on how to augment arbitrary JavaScript objects with custom before and after events.

Basically, it boils down to this:


actsAsDecorator(Ajax.InPlaceEditor.prototype);
Ajax.InPlaceEditor.prototype.after(
  'enterEditMode', function() {
    // do something
  }
);

Nicely done, and very useful to add your own tweaks to existing JavaScript controls and components.

script.aculo.us main site relaunch

August 21st, 2006

script.aculo.us logo

The script.aculo.us site just got relaunched—it’s now easier to get a grasp of what it does, plus you’ll get the stuff that you need faster.

And, it’s much spiffier now.

Note the wiki is not affected by this, so everything there should be in the same place for you to find. At this occasion I want to thank the myriads of authors that keep adding documentation, tricks and real-world experience for all those new (or-not-so-new) to the wonderful world of script.aculo.us. Thanks a bunch!

Also, there’s been a bunch of updates since 1.6.2, so we’re steadily proceeding towards a 1.7 release in the not-so-distant future.

It’s about the user interface, baby!

Mailing list move

August 17th, 2006

The rails-spinoffs mailing list (and the other rails lists too) have been moved to Google Groups because over permenant server overload.
So, give a warm welcome to the new group at:
http://groups.google.com/group/rubyonrails-spinoffs

All old subscriptions have been moved along, so nothing much should change for those of you already subscribed. For those of you that want to subscribe, you can do it either at web page (if you have a google account), or by sending a subscription mail.

Next to making sure that the Trac has room to breathe, you can enjoy some nice new features, like the web interface, RSS feeds and of course powerful searching.

Read more on this on Riding Rails, the official Rails blog.

script.aculo.us 1.6.2

August 12th, 2006

After four long months of waiting (due to my being busy with sekrit work), script.aculo.us 1.6.2 is now out!

It’s a mostly-bug-fix-only release, so don’t expect any major oohs! and aahs! here, but sure get it. It’s recommended for all users, and addresses various more-or-less cosmetically issues, besides a memory leak bug with Draggables and an endless loop in the Slider code.

Anyway, big, big thanks to all contributors who continue to do patches and bug reports! Hopefully the trac will be up to speed soon (new server is coming!). If you should have any issues, please report it to the rails-spinoffs mailing list.

Updates and fixes:

  • Fix a problem in the drag and drop logic if an reverting/drag ending draggable was initialized for a new drag (for example by clicking repeatedly) for all cases where the default start/revert/end-effects are used, fixes #4706 [thx tecM0]
  • Fix possible memory leaks with Draggables, fixes #3436 [thx aal]
  • Throw nicer errors when requires script.aculo.us libraries are not loaded, fixes #5339
  • Make slider handles work when not displayed initially by using CSS width/height, fixes #4011 [thx foysavas]
  • Update sortable functional test with onUpdate counter
  • Make more Element extensions unit tests work on Safari
  • Add the assertMatch unit test assertion for asserts with RegExps [thx Ian Tyndall]
  • Fix a problem with Effect.Move causing “jumping” elements because of very low float numbers in some situations
  • Fix a missing semicolon in dragdrop.js, fixes #5569 [thx mackalicious]
  • Fix a slight inaccuracy with Effect.Scale that could lead the scaling to be one pixel off
  • Be more prototypish with Effect.Transitions.linear
  • Make Effect.Scale recognize font sizes that use the pt unit, fixes #4136 [thx aljoscha]
  • Fix IE hack in Effect.Opacity, fixes #5444 [thx nicholas]
  • Fix IFRAME layout fix for IE and Autocompleter, fixes #5192 [thx tommy skaue]
  • Fix only option in onEmptyHover, fiex #5348 [thx glenn nilsson]
  • Fix Effect.BlindDown and SwitchOff handling of supplied callbacks, fixes #5089 [thx martinstrom]
  • Fix a problem with field focus on Ajax.InPlaceEditor and loading external text, fixes #4988, #5244 [thx rob]
  • Do not attempt to scroll if scrollspeed is 0/0, fixes #5035 [thx tomg]
  • Fix a problem with Sortable Tree serialization, fixes #4939, #4688, #4767 [thx Sammi Williams]
  • Fix an endless loop with sliders, fixes #3226, #4051, #4765 [thx jeff]
  • Make autocompleter work with update DIVs that have scrollbars, fixes #4782 [thx Tommy Skaue]
  • Corrected options parsing on switchoff effect, fixes #4710 [thx haldini]

There are also some updated functional and unit tests (use these links to get to live online versions of these).

Also, this version of script.aculo.us is now included with Edge Rails (as of changeset 4765), and should be part of the upcoming (as in “when it’s ready”) Rails 1.2 release.

Next up: Planning the script.aculo.us 2 release… 😉

Mac OS X 10.5 Leopard on Ruby on Rails

August 4th, 2006

The next release of Apple’s operating system Mac OS X 10.5 will ship with Ruby on Rails installed (read more on this at Riding Rails).

Cool stuff indeed.

Need JavaScript foo?

July 27th, 2006

Check out Amy Hoy’s JavaScript Boot Camp tutorial, highly recommended!

Prototype & script.aculo.us Textmate bundle

July 14th, 2006

TextMate screenshot Harald Martin Ström has created a bundle for easier Prototype and script.aculo.us development with everyone’s favourite editor, TextMate.

While not completely finished yet, it features a bunch of helpers to make writing Prototypish code even easier, with support for Ajax calls, enumerations or forms in Prototype, and Effects in script.aculo.us. It also features nice syntax highlighting of course, based on Justin Palmers earlier efforts.

It even features a cool “look-it-up-in-the-wiki” function: just mark a word and press Ctrl-Shift-H.

More about it & download here.

Extending Prototype

July 10th, 2006

Here are two must-read articles on extending Prototype—here we go:

Nice to see this great stuff popping up everywhere—please don’t stop. 🙂

Plus, if you’re able to understand german, click here.

Safari gets JavaScript debugger

June 28th, 2006

The WebKit nightly builds now sport Drosera, which allows for debugging JavaScript code in web sites and applications.

And it even has a cool name. Eat those bugs!