Fixes for step definitions involving factories with underscores

This commit is contained in:
Joe Ferris 2009-09-15 18:11:16 -04:00
parent adce9df6c9
commit da51a4e48d
3 changed files with 29 additions and 2 deletions

View File

@ -74,3 +74,25 @@ Feature: Use step definitions generated by factories
And I should find the following for the last user:
| name |
| John |
Scenario: create instances of a factory with an underscore in its name
Given an admin user exists with a name of "John"
Then I should find the following for the last user:
| name | admin |
| John | true |
Scenario: use true values when creating instances
Given the following user exists:
| name | admin |
| Bill | true |
Then I should find the following for the last user:
| name | admin |
| Bill | true |
Scenario: use false values when creating instances
Given the following user exists:
| name | admin |
| Mike | false |
Then I should find the following for the last user:
| name | admin |
| Mike | false |

View File

@ -13,6 +13,7 @@ class CreateSchema < ActiveRecord::Migration
create_table :users, :force => true do |t|
t.string :name
t.boolean :admin, :default => false, :null => false
end
end
end
@ -32,6 +33,10 @@ end
Factory.define :user do |f|
end
Factory.define :admin_user, :parent => :user do |f|
f.admin true
end
Factory.define :post do |f|
f.association :author, :factory => :user
end

View File

@ -42,11 +42,11 @@ Factory.factories.values.each do |factory|
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)
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|
count.to_i.times { Factory(factory.human_name, column.name => value) }
count.to_i.times { Factory(factory.factory_name, column.name => value) }
end
end
end