# -*- encoding : utf-8 -*- Dir[Rails.root.join('spec/support/factories/**/*.rb')].each { |r| require r } module FactoryHelpers # Maps a name to a path. Used by the # # When /^I go to (.+)$/ do |page_name| # # step definition in web_steps.rb # def factory_name_to(model_name) case model_name when /administrador(es)?/ :admin else # Tries to find the model based on the translations I18n.t('activerecord.models').each do |key, value| return key if model_name == value.downcase or model_name == value.downcase.pluralize end # If can't find throw an error raise "Can't find mapping from \"#{model_name}\" to a factory.\n" + "Now, go and add a mapping in #{__FILE__}" end end def factory_to(model_name) factory_name = factory_name_to(model_name) factory = FactoryGirl.factories.select { |factory| factory.name == factory_name } raise "Can't find factory with name \"#{factory_name}\".\n" if factory.empty? factory.first end end World(FactoryHelpers)