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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B56c79aacc04f148f4205e0ff308b39a?d=identicon&s=25 Erik Pukinskis (Guest)
on 2009-02-24 01:57
(Received via mailing list)
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
This topic is locked and can not be replied to.