Pluralisations in features
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
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
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
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
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
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)
AASM is a/the state machine plugin, which you can now use as a gem. To do this you need to do 2 things
- Install the GEM
- Tell your app about AASM
Getting started with Cucumber
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
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.