Pluralisations in features

Posted by Andrew Premdas Wed, 29 Oct 2008 16:46:00 GMT

Been a bit of a dummy in this one. Basically each step definition is a regular expression so if we have

When /^I add (\d+) products to the cart$/ do |n|

we can improve this to make allow both

When I add 1 product to the cart
When I add 2 products to the cart

Features Controllers and HTTP_REFERER

Posted by Andrew Premdas Wed, 29 Oct 2008 08:11:00 GMT

Had a problem with a feature failing. Was getting an error

When I add a product to the cart                     # features/steps/cart_steps.rb:11
      Cannot redirect to nil! (ActionController::ActionControllerError)
      /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1044:in `redirect_to'

Problem testing for empty div

Posted by Andrew Premdas Wed, 29 Oct 2008 07:07:00 GMT

Assert_Select is the main Rails tool for testing HTML output. RSpec wraps this function with its have_tag and with_tag methods. Using these methods effectively is key to writing features. However Assert_Select has some problems which caught me out recently.

Paths in features

Posted by Andrew Premdas Thu, 16 Oct 2008 15:30:34 GMT

Been thinking about specifying paths in stories and steps, and the brittleness they can introduce to tests. This was prompted by a bug in rspecs 'render_template' matcher.

Webrat Visits and Redirects

Posted by Andrew Premdas Wed, 15 Oct 2008 17:18:33 GMT

Depressing how long it took me to find out that the visits method in webrat follows all redirects. This means that having a story like

When  I visit /products/1
Then  I should be redirected to the home page

is nonsense as you cannot detect the redirect. In fact all webrats methods follow redirects

Cucumber Webrat and Debugging Features

Posted by Andrew Premdas Sun, 12 Oct 2008 15:56:19 GMT

Debugging with Cucumber

Simple as putting a debugger statement in any steps file.

Note also that you can run just one feature at a time with cucumber using -l. See cucumber -h

AASM installation (using AASM gem in your application)

Posted by Andrew Premdas Thu, 09 Oct 2008 08:29:46 GMT

AASM is a/the state machine plugin, which you can now use as a gem. To do this you need to do 2 things

  1. Install the GEM
  2. Tell your app about AASM

Getting started with Cucumber

Posted by Andrew Premdas Wed, 08 Oct 2008 13:56:58 GMT

Cucumber is the new runner for Rspec plain text stories. It has a number of improvements that make it essential, and it will soon become the default runner for rspec. To get started we need to do a few things

Ammend a GIT commit

Posted by Andrew Premdas Wed, 08 Oct 2008 13:34:46 GMT

If you've forgotten something from a commit you can add it to the previous commit using the --amend parameter. This is most useful to keep your GIT repo tidy.