Commit 76fde36f72dd0930434948cdf25162f9c8323a57

Authored by Dan Croak
1 parent fe19b696

more powerful (Tool Time grunt) Factory Girl steps for Cucumber

Showing 1 changed file with 26 additions and 2 deletions   Show diff stats
features/step_definitions/factory_girl_steps.rb
  1 +Given /^the following (.*) exists?:$/ do |factory, table|
  2 + factory = factory.singularize.gsub(' ','_')
  3 + table.hashes.each do |attributes|
  4 + Factory(factory, attributes)
  5 + end
  6 +end
  7 +
1 Factory.factories.each do |name, factory| 8 Factory.factories.each do |name, factory|
2 - Given /^an? #{name} exists with an? (.*) of "([^"]*)"$/ do |attr, value|  
3 - Factory(name, attr.gsub(' ', '_') => value) 9 + if factory.build_class.respond_to?(:columns)
  10 + factory.build_class.columns.each do |column|
  11 + Given %{^an? #{name.to_s.humanize.downcase} exists with an? #{column.name.humanize.downcase} of "([^"]*)"$} do |value|
  12 + Factory(name, column.name => value)
  13 + end
  14 + end
  15 + end
  16 +
  17 + Given /^an? #{name} exists$/ do
  18 + Factory(name)
  19 + end
  20 +
  21 + Given /^(\d+) #{name.to_s.humanize.downcase.pluralize} exist with an? ([^"]*) of "([^"]*)"$/ do |count, attr, value|
  22 + count.to_i.times { Factory(name, attr.gsub(' ', '_') => value) }
  23 + end
  24 +
  25 + Given %r{^(\d+) #{name.to_s.humanize.downcase.pluralize} exist$} do |count|
  26 + count.to_i.times { Factory(name) }
4 end 27 end
5 end 28 end
  29 +