06
Jul 10

Ramble gets a refactor

Just two days after announcing Ramble, Pete Otaqui has done a large refractor of the core code. Ramble, as a result is far more modular allowing for different output classes etc.

Now that we have a more solid API, we can concentrate on testing and porting additional Cucumber functionality. Many thanks to Pete!

Get the latest code from GitHub:

http://github.com/soniciq/ramble


04
Jul 10

“Ramble”, the Javascript Cucumber Port (work in progress)

I am a great fan of Cucumber when it comes to integration testing, however testing heavy use of Javascript can be a little tedious.

I have looked into the different solutions out there such as Selenium but found them all to be fiddly to setup, however Capybara helps on this front. I was thinking, what if Cucumber could run in the browser? No need for Javascript adapters or XML parsers, Safari/Chrome/Firefox already do a great job of this. Manipulating the page such as filling in forms, clicking links etc. could all be done with jQuery, in a very concise manor.

I decided to create a proof-of-concept while it was still fresh in my head. This is by no means a fully working release and the code leaves a lot to be desired in it’s current state, however it shows the benefits of a “Cucumber in the browser”. The main benefits I can see so far (for both javascript and non javascript apps) are:

  • Speed – browsers are getting extremely quick at this DOM stuff.
  • Flexibility – everything happens client-side meaning you can easily test with any server technology.
  • Simplicity – no need for complex javascript adapters, XML parsers etc.

The basic file structure is very similar to Cucumber:

  - features
    index.html
    - js
        ramble.js
        jquery-1.4.2.js
      my.feature
    - steps
        web-steps.js
    - support
        paths.js

Step definitions can be defined in plain old javascript files with plain old jQuery, in this case web-steps.js. Currently the step definition are expected to throw an error if they cannot be fulfilled, this may change when a solid API is nailed down:

  // The value of 'this' is the current document as a jQuery object.
  ramble.match(/^I follow "(.+)"$/, function(link_text) {
    var link = this.find('a').filter(function() { return $(this).text() == link_text; });
    if(!link.length) throw("Can't find link: " + link_text);
    link.click();
  });

Scenarios are exactly the same as in Cucumber, so you can do something like the following:

  Scenario: User fill out a form
    Given I am on the homepage
    And I follow "Tell us your name"
    And I fill in "First name" with "Jamie"
    And I fill in "Last name" with "Hill"
    And I press "Submit"
    Then I should see "Thank you for your details."

You can now simply drop the features folder into the public area of your app and visit the url in your browser. You should see the relevant steps go green or red as the app is navigated in an iFrame.

I plan to first tidy up the API (and unit test) and then aid the writing of scenarios by adding the ability to record them within the browser (Selenium style).

I’d like to hear peoples views on this… please don’t be too hard on the code, it’s more of a mind-dump than anything else at this stage (around 100 lines). There is an example of testing a static site included so just load the features/index.html file in your browser to see it run.

http://github.com/soniciq/ramble

Update 04/07/10: As noted by Andrew in the comments, you will need a server running in order for browsers to get access to the pages for testing.

I have added a simple server script allowing the features to be run locally (requires Ruby). If you want to see it in action, just run:

cd /path/to/ramble/checkout
ruby server.rb

…and then visit http://localhost:1234/features in your browser (tested in Firefox, Chrome and Safari). Note that Ramble is not at all dependent on Ruby, it is just used for running a local test server.

Screenshot

Ramble in action


26
Jun 10

Wow! Ruby on Rails just grew up.

I’ve been using Ruby on Rails at SonicIQ since the early Rails betas and have worked exclusively with Ruby frameworks ever since. Over the past few years I’ve seen Rails evolve, which has been a painful process in some cases as it has found direction, making the odd mistake along the way.

I have been working on a new project, getting a proper chance to use the Rails 3 beta and wow! …Rails just grew up.

With the introduction of Bundler, the gem dependency pain has disappeared. ActiveRecord’s API feels solid with the introduction of ActiveRelation. The new routing API (with the introduction of ActionDispatch) is amazingly concise, my routes never looked so good. The close integration with Rack enabling the mounting of other rack applications in a Rails app is just too easy… I could go on…

I think a great deal of the modularity and general solidness comes from the Merb merger, so big thanks to the Merb guys. I have felt none of the pain that I had in the past when needing to use anything other than the defaults, or hooking into the framework itself.

What more can I say, I’m in love with Rails all over again and so glad I stuck with it.

Thanks to everyone involved.


10
Jun 10

No ‘a:visited’ in Safari 5… jQuery to the rescue?

With the release of Safari 5, it seems that the ‘:visited’ CSS pseudo selector no longer takes affect. I completely understand it being removed due to breadcrumb sniffing but from a user’s perspective, differentiating between links that you have visited and those that you have not is very handy.

jQuery to the rescue

Using jQuery, we can easily add this functionality back in, without the XSS problems associated with the browser handling it.

$('a:not(.visited)').click(function() {
  $(this).addClass('visited');
});

You can then go ahead and set a different style for links that have the ‘visited’ class.

The problem with this approach is that it will only work for links opened in a separate window or tab and not persist when you leave the current page, as all added classes will obviously be removed. There is probably a way to store a list of which links have been visited in a cookie, however each link would need a unique identifier… something for another time.

Update

It seems that the ‘:visited’ selector does work in some cases in Safari 5 but not sure of the circumstances, can anyone shed any light on this?


09
Apr 10

To SproutCore, or not to SproutCore…

I’ve been debating over the past week whether or not to use SproutCore for a large application I am working on. What follows are my initial thoughts on the framework, likes and dislikes.

A fight with what’s right

Right, I’m afraid I’m going to start with a negative in the hope that I can focus more on the positives for the rest of the post.

I have been an advocate of Web Standards in the running on SonicIQ over the past 10 years, with this has come the adoption of Progressive Enhancement using Unobtrusive Javascript. Now along come two cutting edge frameworks, SproutCore and Cappuccino who completely abandon this culture in search of a desktop-like feel to web apps.

Having been an early adopter of techniques like Unobtrusive Javascript and seeing the benefits they offer, I am reluctant to give the finger to those without Javascript, even if this is now a small minority. With the advent of HTML5 I suppose this becomes less of an issue as Javascript is one of the many standards under the whole HTML5 umbrella and is just expected to exist. I can’t help feeling a little dirty though having a page of just script tags.

Am I being too “precious” about Graceful Degradation, or is this still relevant with the arrival of HTML5?

Fat Client

Both SproutCore and Cappuccino opt for the “Fat Client” methodology, for anyone who has not heard of this (other than in the literal sense), this means that the client (browser) is made to do more of the grunt work usually accomplished by the server. This has a huge benefit of making the app feel much “snappier”, as common calculations, concatenations etc. are all done on the client-side, reducing the amount/size of calls to the server. Your server-side app acts more like a dumb data store, using REST to communicate data back and forth.

The downside to fat clients (I won’t do the obvious joke), is that there is a chance that your audience will see more than you want them too when visiting “View Source”. You obviously don’t want to give away Granddad’s age-old secret hangover cure in the Javascript source, however as long as you’re sensible and keep the business logic that is of any real value at the server-side, all should be fine.

Fat Framework

Unfortunately, in order to have the additional work handled by the client, you have to feed it more Javascript. The whole of SproutCore comes in at an impressive 500Kb uncompressed! That said, it will compress down to 100Kb when minified and gzipped.

Lets say you went with plain old jQuery as it’s smaller, and you’ll just add plugins for the bit’s you need. Well, by the time you include a chunk of jQueryUI when you want to be able to sort lists and drag stuff around… you’ve soon hit that 100Kb threshold.

So… is the size really an issue by the time it’s all been cached by the browser, images sprited, scripts concatenated into one file etc?

Alternatives

Cappuccino

One of the alternatives already mentioned is Cappuccino. To me the instant turn-off was Objective-J, it’s very clever and all that but do I really want to have to learn another language when I already have Javascript under my belt. Objective-J may have the benefit of easing portability to desktop apps, however I can’t see that this will ever be a flawless process.

UKIJS

Another lightweight alternative is UKIJS which aims to bring the core UI element of the aforementioned frameworks, without the kitchen sink that comes with it.

I’ve had a brief play with UKIJS and generally love the concept, however I can’t help but think it would be better built on top of jQuery instead of borrowing so much of the internals. Also as it is a young project, there are large gaps in the functionality, such as reordering of lists, custom cells in list view etc.

This is definitely one to watch as it seems like a great light-weight alternative to it’s bulkier competition.

Conclusion

I have only scratched the surface in my search for the best framework out of these options. My next job is to play with SproutCore a little more, to see if it caters for what I need.

Has anyone else had experience with these frameworks? What was the conclusion? Should we just abandon Unobtrusive Javascript when building web “Apps” and use it only for web “Sites”?


25
Mar 10

SproutCore Documentation / Hell…

After taking my first look at SproutCore, I couldn’t help but find the truncation of this documentation page title amusing…

Amusing naming of tab in Safari


15
Mar 10

Rails, can we please have a delete action by default.

I’ve just finished watching the latest Railscast… thanks Ryan, great as ever! One thing that bothers me is that we are still not able to delete items with the default CRUD setup when javascript is turned off.

Way back in 2006, I wrote an article called Simply RESTful… “The missing action”. I still believe that we should have a “delete” action that responds to GET requests by default in Rails, much like the “update” action has an “edit” form. Now before you say “that’s ridiculous Jamie”, I am not suggesting that we should be able to delete via a get request (that would be stupid!), the “delete” action would simply be a confirmation page with a form that posts to the “destroy” action. That way we can still use javascript to hijack the “delete” link and make it perform a “DELETE” request to the “destroy” action but we also have the benefit of being able to delete things without javascript.

Remember, the “delete” action is to “destroy”, what the “edit” action is to “update”. So in the case of a “products” resource, we would simply render the following form named “delete.html.erb”:

<h1>Delete product</h1>
<p>Are you sure you want to proceed?</p>
 
<% form_tag product_path(@product), :method => :delete do %>
  <div><%= submit_tag 'Confirm delete' %></div>
<% end %>
 
<p><%= link_to '&laquo; Back', products_path %></p>

What do you think?


14
Feb 10

Nokogiri for Cucumber steps that need to compare HTML attributes

I have found on numerous occasions that I need to look at HTML attributes when diffing tables etc. in Cucumber. My current need for this arrises as I have a gallery of thumbnails that all have alt tags who’s values I need to compare as there is not a text equivalent.

A feature statement like this:

Then I should see the following thumbnails
  | Mona Lisa  |
  | Sunflowers |

Could be achieved with the following step:

Then /^I should see the following thumbnails$/ do |table|
  nodes = Nokogiri::HTML(response.body).css('ul#gallery li img')
  table.diff!(nodes.map { |img| [img.attributes['alt'].to_s] })
end

07
Feb 10

Why I stopped using Pickle with Cucumber

…no, not because it leaves a bitter aftertaste, I’m talking about the Pickle step definitions for Cucumber.

I have lately been using Pickle when writing Cucumber features, however I have come to the conclusion that this is a bad idea. The reason being that when using Pickle, you create entries directly, whereas the whole point of Cucumber is that it is for high level integration testing.

What I do now, is to create any entries by filling out and submitting the relevant forms with a step definition, for example I may have the following:

Given an admin has created the following products
  | Name    | Variants                                  | Featured |
  | T-Shirt | Small: 10.99, Medium: 12.99, Large: 14.99 | Yes      |
  | Keyring | Default: 2.99                             | Yes      |

I would then write a step definition for this that would log in as the admin user, break this table appart and fill in the relevant forms.

I would go so far as to say that using factories at all in features is a bad idea and instead everything should happen via the user interface for better coverage. For any data that is known to exist when the app is deployed via ‘rake db:seed’, this can be loaded in the ‘env.rb’ file e.g.

load 'seeds.rb'

Update 11/2/2010: Sometimes this is simply not practical due to slowdown which is a shame, as noted by Amos in the comments.


06
Feb 10

Devise Rails Authentication Gem Rocks!

I’ve had a set of rather bespoke requirements for authentication on a recent project and thought I’d give Devise a go.

Devise uses Warden, which is an authentication solution build on Rack making it extremely flexible and usable across multiple frameworks e.g. Rails/Sinatra. Also, Devise is extremely modular meaning to can easily write custom “strategies” for specific behaviour.

I have used Clearance in the past which is great if you want an engine that will just work. Devise however is by far the most flexible and extensible solution that I have come across with the same ease of use as Clearance. The only thing that you don’t get with devise that you do with Clearance is the signup stage, however as this is normally custom on a per-app basis I can live with this.

One more thing to note is that Devise lets you have multiple auth systems in play e.g. one for users and one for admins.