More step definitions

This commit is contained in:
Joe Ferris 2009-09-15 18:06:24 -04:00
parent db6c46a101
commit adce9df6c9
2 changed files with 27 additions and 0 deletions

View File

@ -59,3 +59,18 @@ Feature: Use step definitions generated by factories
| title | author_id |
| a title | 123 |
And there should be 1 user
Scenario: create a user without attributes
Given a user exists
Then there should be 1 user
Scenario: create several users without attributes
Given 3 users exist
Then there should be 3 users
Scenario: create several users with one attribute
Given 3 users exist with a name of "John"
Then there should be 3 users
And I should find the following for the last user:
| name |
| John |

View File

@ -30,12 +30,24 @@ Factory.factories.values.each do |factory|
end
end
Given /^an? #{factory.human_name} exists$/ do
Factory(factory.factory_name)
end
Given /^(\d+) #{factory.human_name}s exist$/ do |count|
count.to_i.times { Factory(factory.human_name) }
end
if factory.build_class.respond_to?(:columns)
factory.build_class.columns.each do |column|
human_column_name = column.name.downcase.gsub('_', ' ')
Given /^an? #{factory.human_name} exists with an? #{human_column_name} of "([^"]*)"$/i do |value|
Factory(factory.human_name, column.name => value)
end
Given /^(\d+) #{factory.human_name}s exist with an? #{human_column_name} of "([^"]*)"$/i do |count, value|
count.to_i.times { Factory(factory.human_name, column.name => value) }
end
end
end
end