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

**URL:** <https://www.ruby-forum.com/t/a-nice-general-purpose-step-definition-for-adding-finding-activerecord-records/161163>\
**Category:** RSpec\
**Created:** [February 24, 2009, 1:57am UTC](https://www.ruby-forum.com/t/a-nice-general-purpose-step-definition-for-adding-finding-activerecord-records/161163 "2009-02-24T01:57:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [February 24, 2009, 1:57am UTC](https://www.ruby-forum.com/t/a-nice-general-purpose-step-definition-for-adding-finding-activerecord-records/161163/1 "2009-02-24T01:57:27Z")

</div>

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
