Skip to content

Instantly share code, notes, and snippets.

@sleistner
Created February 7, 2011 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleistner/815101 to your computer and use it in GitHub Desktop.
Save sleistner/815101 to your computer and use it in GitHub Desktop.
factory_girl cucumber step definitions using mongoid
FactoryGirl.factories.values.each do |factory|
if factory.build_class.respond_to?(:fields)
factory.build_class.fields.map(&:first).each do |field|
human_field_name = field.downcase.gsub('_', ' ')
Given /^an? #{factory.human_name} exists with an? #{human_field_name} of "([^"]*)"$/i do |value|
Factory(factory.name, field => value)
end
Given /^(\d+) #{factory.human_name.pluralize} exist with an? #{human_field_name} of "([^"]*)"$/i do |count, value|
count.to_i.times { Factory(factory.name, field => value) }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment