A nice general purpose step definition for adding/finding activerecord records


#1

I thought other people might be interested in these step definitions.
They allow you to write steps like:

Given the following “turkeys” exist:
|name |size |intelligence|
|marko |big |dumb |
|mello |small |smart |

Or,

Then the following “turkeys” should exist:

peace,
Erik

Then /^the following “(.*)” should exist:$/ do |table, data|
data.hashes.each do |hash|
table.classify.constantize.find(:all, :conditions =>
hash).should_not be_empty
end
end

Given /^the following “(.*)” exist:$/ do |table, data|
table.classify.constantize.create!(data.hashes)
end

Erik