Monday, 30 July 2012

RABL on Rails

There are plenty of ways to output from . So, when it was time for an existing app to move on from to_xml to support a richer API we were able to go shopping...

Following our Agile principles, we focused only on what we needed today. In this case, we went looking for an solution with these qualities:

  • concise
  • quick
    • to configure
    • to integrate
    • to learn
  • and readable.

measured up admirably. Kudos to nesquena and the rest of the RABL crew.

Is RABL the ultimate mapper? Maybe it is, but I think it more likely that there's ...

Thursday, 12 July 2012

Remember to clear requests between jasmine-ajax tests

We use for . To , we rely on to spy, mock and fake. A basic usage pattern is to jasmine.Ajax.useMock() then check mostRecentAjaxRequest(), but remember to clearAjaxRequests() to avoid inconsistency (when running as part of a larger test suite).

Taking a look at the source, clearAjaxRequests() is not called within the code. When running several tests are run in the same browser page, stale requests from previous tests may be returned by mostRecentAjaxRequest().

So, instead of jasmine.Ajax.useMock() then check mostRecentAjaxRequest(), adopt this pattern:


  beforeEach ->
    clearAjaxRequests()
    ...

  afterEach ->
    ...
    clearAjaxRequests()

  it "should save the JSON data using Ajax", ->
    jasmine.Ajax.useMock()
    ...
    request = mostRecentAjaxRequest()
    ...

Tuesday, 3 July 2012

CoffeeScript and the Curious Case of the Missing Bracket

Over the last month or two, I've grown to admire . This little language encourages developers to drop braces, sprinkling liberally around enabling . But there is one area where I think a little more would help a lot.

I sometimes find it useful to think of as just a functional language dressed up in someone else's Object Oriented clothes. Passing a function (rather than its value) is as simple as dropping its braces. So, for example alpha = bar.foo assigns the function foo on bar to alpha. Use alpha = bar.foo() to assign the value instead.

Objects and classes in CoffeeScript feel more natural, yet bar.foo still refers to the function foo. Intuitively, this feels wrong, and the only reason I can fathom for introducing this inconsistency is compatibility with JavaScript behaviour. This price seems too high for such little gain.

I suggest that, in CoffeeScript, bar.foo should call foo on bar with no parameters (just like bar.foo message passes message to foo on bar), and special syntax be introduced for function passing: bar.foo! perhaps...