Categories
Agile Ruby Software

Driving Selenium from the RSpec Story Runner (RBehave)

[Update] The story runner is now included in the 1.1 release of RSpec, so a lot of the hackery mentioned below is no longer required. See http://rspec.info/ for details.

Background

A while ago I cobbled together some code to drive Selenium from Exactor (which was the acceptance testing framework we were using at the time). That project was offshored shortly afterwards, and I’m pretty sure Selenium never actually got integrated into the build (sneaking a peek at the continuous integration server reveals that even the pre-Selenium acceptance test build hasn’t run successfully for months), but I was convinced of the value of Selenium for testing non-trivial web applications.

On my next project (the Web21C SDK portal) we used Selenium on Rails heavily for automated acceptance testing. This worked well, although the fact that the tests are deployed with the application limits what you can do – you can’t interrogate the database after a test, for example, or dynamically set up stubs for systems you interface with (unless you also deploy the stubs as part of the application, and drive them from the browser).

With Mojo there’s an additional complication: as well as being accessible through a browser, most functionality is also available as a RESTful API, using digest-based authentication. To keep our acceptance tests in one place, we wanted to be able to drive a browser using Selenium, alongside other tests which talked to the server directly. The obvious answer was to use Selenium Remote Control, and I also liked the look of RBehave, which has now been incorporated into RSpec (but not released yet).

The RSpec story runner

The story runner in the upcoming release of RSpec is an evolution of Dan North’s RBehave, which in turn is based on JBehave (from the same author). In the past couple of weeks, David Chelimsky has done some excellent work on extracting the text of stories from the code, leading to the plain text story runner.

Read on for the gory details of my solution to running Selenium tests from the story runner.

Categories
Apple Ruby

Ruby in Leopard: so close and yet…

I was quite excited to see the announcement of improved Ruby and Rails support in Leopard, and one of the first things I did after upgrading was to delete my MacPorts installations of Ruby and RubyGems, and try using the built-in ones instead.

For a while, all seemed well. The milk was cold, the food stayed fresh, my specs still passed, my Rails projects still worked, and even the light worked when you opened the door.

But then the trouble started.

Firstly I tried updating and installing gems while behind a firewall. The gem command completely ignored my http_proxy setting, and when I explicitly provided the proxy using -p, I got this error:

ERROR:  While executing gem ... (NoMethodError)
    undefined method `[]=' for #

I worked round this by downloading the gems manually and installing the local copies (despite this being a pain, especially when there are dependencies).

I then tried using gemsonrails to freeze some gems, and it got confused by the fact that Leopard stores built-in gems separately from user-installed ones. Thinking about it, if I’d successfully frozen the gem, it might have turned out to have been tweaked in some Mac-specific way and broken on other platforms.

Forgetting about that issue, I carried on with other work for a while, then found that autotest wouldn’t work, and mysteriously was trying to run something from /opt/local (where MacPorts install lived). Even after removing any gem-related scripts from /opt/local/bin, the problem persisted.

Oh well, looks like I’ll be re-installing everything using MacPorts. I’m not sure whether all these problems are intrinsic to the Ruby installation that comes with the system, or whether some are caused by lingering remains of my MacPorts installation – I’d be interested to hear how others got on.

[tags]ruby, rails, mac, 10.5, leopard[/tags]

Categories
Rails Software

Rails, SOAP and REST

From the list of new features coming in Rails 2.0:

It’ll probably come as no surprise that Rails has picked a side in the SOAP vs REST debate. Unless you absolutely have to use SOAP for integration purposes, we strongly discourage you from doing so.

Categories
Agile BT

Concurrent design and development – a better spin?

Another day, another argument discussion with a colleague over the common misapprehension that you can have a process with discrete requirements capture, design, development and test phases, yet somehow still claim to be agile. Once again, I tried (with limited success) to explain that you don’t need to do all your designing up front before you start writing code, and that starting to write code almost immediately isn’t ‘hacking’, provided that you are continuously paying attention to good design as you go.

In other words, agile developers do just as much designing as those still following waterfall methods, but we do it at the same time as writing the code.

Reflecting afterwards, I realised that I’ve been phrasing the message the wrong way. As anyone who really ‘gets’ test-driven (and particularly behaviour-driven) development knows, it’s not really about the testing, but about the design process. A waterfall ‘designer’ starts from an understanding of the problem and builds up some kind of model for a solution, which they then pass on to the implementors An agile developer does exactly the same, but the language they use for the model happens to be executable source code rather than documents or UML. This choice of modeling language has the rather large benefit of being testable, and once your design is finished, you’re done. No need for someone to try to interpret and implement it. No scope for misunderstandings between designer and developer. No danger that the design is incomplete, or that part of it turns out to be unworkable.

It’s not that we start writing code and design as we go along.

We are always designing – we just write the code as we go along.

[tags]agile, tdd, bdd[/tags]

Categories
Rants Software

Steven Fry’s call to arms

Steven Fry has written a detailed comparison of smartphones on his blog. It’s quite long, but very entertaining (as you would expect) and well worth a read.

As a ‘corporate software engineer’ myself, this in particular struck a chord:

Break free, all you corporate software engineers and designers: the excuse that you are under the rule of dullards, greedy share-price number crunchers and visually and ergonomically illiterate yahoos is not good enough. Persuade them. Otherwise we all get a digital environment that’s a vile as a 60s housing estate.

Amen to that.

Categories
Software

Search in Google Reader at last!

Google reader now has a search facility, which is nice. I can’t help wondering why it took so long though – I mean surely they have a little experience in the organisation of writing search tools?

[tags]google, reader, search[/tags]

Categories
Agile

Agile2007: Wednesday

As you may have noticed, I’m getting a little behind posting these. On the offchance that anyone’s actually reading, rest assured that I still have my scribbled notes, so they’ll be appearing here eventually.

Presenter First: TDD for Large, Complex GUIs

Scott Miller (Atomic Object)

I was torn between this session and the one on Ruby metaprogramming, but it wasn’t clear who that one was pitched at, so I decided not to risk sitting through another basic tutorial. Alkesh went to the Ruby one, and apparently it was pretty good (if I’d noticed that David Chelimsky was presenting, I probably would have gone along). Anyway, as we all know Alkesh doesn’t have a blog (actually that’s not strictly true), so you won’t be able to read about it :-)

Categories
General nonsense Ruby

Duck typing for dummies

def duck?
  respond_to? :quack
end
Categories
Agile

Agile2007: Tuesday

Keynote: Reaching New Heights: Learning to Adapt is Essential

Susan Ershler

I’m not quite sure what to make of this keynote. Susan’s talk about achieving her twin goals of success in business and climbing the highest peaks on each continent (culminating in Everest) was interesting and well-presented, but came across to me as a motivational speech for business leaders, slightly tweaked to include a few agile themes. I’d have preferred to hear something more concrete from a thought leader in agile development (after all, there are a fair few of them here!)

Categories
Agile

Agile2007: Monday

The first day of the conference didn’t get started until after lunch, so we took the opportunity to go up the Washington Monument in the morning (I’ve been posting some photos from the trip to Flickr, by the way).

Most of the slides from the conference are on the Agile2007 website, so I’m not going to go into great detail about any of the sessions here (not that I would have anyway!), but just mention the things I thought were interesting enough to specifically note down. This will probably mean that things are a bit jumbled, so sorry in advance.