1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/lib/factory_girl/step_definitions.rb

33 lines
976 B
Ruby
Raw Normal View History

2009-09-15 15:47:47 -04:00
module FactoryGirlStepHelpers
def convert_ast_table_to_attribute_hash(table)
table.rows.inject({}) do |result, (human_key, value)|
key = human_key.downcase.gsub(' ', '_').to_sym
result.merge(key => value)
end
end
2009-09-15 15:54:21 -04:00
def convert_human_hash_to_attribute_hash(human_hash)
human_hash.inject({}) do |attribute_hash, (human_key, value)|
key = human_key.downcase.gsub(' ', '_').to_sym
attribute_hash.merge(key => value)
end
end
2009-09-15 15:47:47 -04:00
end
World(FactoryGirlStepHelpers)
Factory.factories.values.each do |factory|
Given "the following #{factory.human_name} exists:" do |table|
attributes = convert_ast_table_to_attribute_hash(table)
Factory.create(factory.factory_name, attributes)
end
2009-09-15 15:54:21 -04:00
Given "the following #{factory.human_name}s exist:" do |table|
table.hashes.each do |human_hash|
attributes = convert_human_hash_to_attribute_hash(human_hash)
Factory.create(factory.factory_name, attributes)
end
end
2009-09-15 15:47:47 -04:00
end