Skip to content
foeken edited this page Sep 13, 2010 · 3 revisions

Setting up for building objects

The custom_steps directory contains a file called: required_model_attributes.rb. This file contains a sample configuration
for your application.

# You may specify the attribute names of your datetime attributes here

# EXAMPLE:
# set_datetime_attributes "valid_from" => :to_date, "start" => :to_time

# You need to specify the minimal set of required attributes for each of your classes
# if you want the steps to be able to automatically build them.

# EXAMPLE:
# set_required_attributes_for("user",           :username => "Test", 
#                                               :password => "123" )

The first section deals with what attributes can be parsed by Chronic (A Natural Language Date parser). Some of the steps
allow you to say:

Given an address with valid from 'next year' exists

For this to work you must specify which attributes can be dates and which can be times. Do that with the first part.

The second part deals with required attributes. The previous example can only succeed if the Address object has no required fields (except for possibly the valid from field). In most cases this won’t be true. That’s why we can define required attributes. Simple register the class name with a hash of attributes and you are good to go. You can override each the attributes in the steps.

Adding more specific steps

Most applications will need a subset of steps that apply only to that app. When you ran the generator a directory called “custom_steps” was created. To add custom steps simple add a file containing them.

File: custom.rb


steps_for(:custom) do
  1. See the Rspec documentation to build steps
    end

All the files in the custom_steps directory will be automatically included into any specced story that uses the webrat_helper.rb file.

Clone this wiki locally