Ruby, Linux, Autotest, Rspec 2, Cucumber

Update: I’ve moved on to using Guard

Of the posts I’ve written this article about Rspec, Autotest, etc. has been one of the more visited. Time to update that ooold information.

If you don’t know what any of this is, the idea of Autotest is to get a test suite to run continuously in the background and provide ambient notifications about the failure/success status whenever a file is saved. You get feedback as soon as you break your test suite. The Linux part of this post involves getting Linux to pop up an on-screen display listing number of failed tests.

Cucumber is a BDD (Behavior-Driven Development) tool where you write out the features in plain language but then parse that natural language with regexps to pin tests behind it (called step definitions).

Rspec is a nice expressive test assertion library that can be used both in Cucumber feature step definitions and for traditional unit tests.

The process is much faster and cleaner now due to better gems and the convenience of Bundler. I’ll update with details about non-Rails projects.

The Gemfile section (note autotest-standalone and autotest-notification:

group :test do
  gem 'rspec'
  gem 'rspec-rails'
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'autotest-standalone'
  gem 'autotest-rails'
  gem 'autotest-notification'
end

Setup commands:

# install the gems of course
bundle install
# steps for Rails
rake generate rspec:install
rake generate cucumber:install
# complained if I didn't do this
rake db:generate
# Do some magic for the notifications plugin
an-install

Then to run the tests:

export AUTOFEATURE=true; autotest

It’s working for me on Ubuntu 12.04.

2 thoughts on “Ruby, Linux, Autotest, Rspec 2, Cucumber

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s