From 76fde36f72dd0930434948cdf25162f9c8323a57 Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Thu, 16 Jul 2009 08:19:43 -0400 Subject: [PATCH] more powerful (Tool Time grunt) Factory Girl steps for Cucumber --- features/step_definitions/factory_girl_steps.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/features/step_definitions/factory_girl_steps.rb b/features/step_definitions/factory_girl_steps.rb index 6337f66..6806d56 100644 --- a/features/step_definitions/factory_girl_steps.rb +++ b/features/step_definitions/factory_girl_steps.rb @@ -1,5 +1,29 @@ +Given /^the following (.*) exists?:$/ do |factory, table| + factory = factory.singularize.gsub(' ','_') + table.hashes.each do |attributes| + Factory(factory, attributes) + end +end + Factory.factories.each do |name, factory| - Given /^an? #{name} exists with an? (.*) of "([^"]*)"$/ do |attr, value| - Factory(name, attr.gsub(' ', '_') => value) + if factory.build_class.respond_to?(:columns) + factory.build_class.columns.each do |column| + Given %{^an? #{name.to_s.humanize.downcase} exists with an? #{column.name.humanize.downcase} of "([^"]*)"$} do |value| + Factory(name, column.name => value) + end + end + end + + Given /^an? #{name} exists$/ do + Factory(name) + end + + Given /^(\d+) #{name.to_s.humanize.downcase.pluralize} exist with an? ([^"]*) of "([^"]*)"$/ do |count, attr, value| + count.to_i.times { Factory(name, attr.gsub(' ', '_') => value) } + end + + Given %r{^(\d+) #{name.to_s.humanize.downcase.pluralize} exist$} do |count| + count.to_i.times { Factory(name) } end end + -- libgit2 0.21.2