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

Properly support pluralized words in generated step definitions.

This commit is contained in:
Tristan Dunn 2010-06-07 11:46:01 -04:00
parent 389ec8f295
commit 1d42b1832a
3 changed files with 13 additions and 4 deletions

View file

@ -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

View file

@ -14,4 +14,5 @@ end
Before do
Post.delete_all
User.delete_all
Category.delete_all
end

View file

@ -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