From 1d42b1832ae42b5d9ca8d3facbb5751511b42c99 Mon Sep 17 00:00:00 2001 From: Tristan Dunn Date: Mon, 7 Jun 2010 11:46:01 -0400 Subject: [PATCH] Properly support pluralized words in generated step definitions. --- features/factory_girl_steps.feature | 9 +++++++++ features/step_definitions/database_steps.rb | 1 + lib/factory_girl/step_definitions.rb | 7 +++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/features/factory_girl_steps.feature b/features/factory_girl_steps.feature index b2bee39..59cf2aa 100644 --- a/features/factory_girl_steps.feature +++ b/features/factory_girl_steps.feature @@ -114,3 +114,12 @@ Feature: Use step definitions generated by factories Then I should find the following for the last user: | name | admin | | Mike | false | + + Scenario: Properly pluralize words + Given the following categories exist: + | name | + | Bed | + | Test Drive | + And 2 categories exist + And 2 categories exist with a name of "Future" + Then there should be 6 categories diff --git a/features/step_definitions/database_steps.rb b/features/step_definitions/database_steps.rb index 0bd2f37..c90ac7e 100644 --- a/features/step_definitions/database_steps.rb +++ b/features/step_definitions/database_steps.rb @@ -14,4 +14,5 @@ end Before do Post.delete_all User.delete_all + Category.delete_all end diff --git a/lib/factory_girl/step_definitions.rb b/lib/factory_girl/step_definitions.rb index 9afb0f4..1157f41 100644 --- a/lib/factory_girl/step_definitions.rb +++ b/lib/factory_girl/step_definitions.rb @@ -23,8 +23,7 @@ end World(FactoryGirlStepHelpers) Factory.factories.values.each do |factory| - # TODO: support irregular pluralizations - Given /^the following #{factory.human_name}s? exists?:$/ do |table| + Given /^the following (?:#{factory.human_name}|#{factory.human_name.pluralize}) exists?:$/ do |table| table.hashes.each do |human_hash| attributes = convert_human_hash_to_attribute_hash(human_hash, factory.associations) Factory.create(factory.factory_name, attributes) @@ -35,7 +34,7 @@ Factory.factories.values.each do |factory| Factory(factory.factory_name) end - Given /^(\d+) #{factory.human_name}s exist$/ do |count| + Given /^(\d+) #{factory.human_name.pluralize} exist$/ do |count| count.to_i.times { Factory(factory.factory_name) } end @@ -46,7 +45,7 @@ Factory.factories.values.each do |factory| Factory(factory.factory_name, column.name => value) end - Given /^(\d+) #{factory.human_name}s exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value| + Given /^(\d+) #{factory.human_name.pluralize} exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value| count.to_i.times { Factory(factory.factory_name, column.name => value) } end end