[rspec-users] A nice general purpose step definition for adding/finding activerecord records

Erik Pukinskis erikpukinskis at gmail.com
Mon Feb 23 19:10:47 EST 2009


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


More information about the rspec-users mailing list