Skip to content

Commit

Permalink
Properly support pluralized words in generated step definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Jun 7, 2010
1 parent 389ec8f commit 1d42b18
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions features/factory_girl_steps.feature
Expand Up @@ -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
1 change: 1 addition & 0 deletions features/step_definitions/database_steps.rb
Expand Up @@ -14,4 +14,5 @@
Before do
Post.delete_all
User.delete_all
Category.delete_all
end
7 changes: 3 additions & 4 deletions lib/factory_girl/step_definitions.rb
Expand Up @@ -23,8 +23,7 @@ def convert_human_hash_to_attribute_hash(human_hash, associations = [])
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)
Expand All @@ -35,7 +34,7 @@ def convert_human_hash_to_attribute_hash(human_hash, associations = [])
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

Expand All @@ -46,7 +45,7 @@ def convert_human_hash_to_attribute_hash(human_hash, associations = [])
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
Expand Down

0 comments on commit 1d42b18

Please sign in to comment.