diff --git a/features/factory_girl_steps.feature b/features/factory_girl_steps.feature index 1988348..37eced3 100644 --- a/features/factory_girl_steps.feature +++ b/features/factory_girl_steps.feature @@ -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 | diff --git a/features/support/factories.rb b/features/support/factories.rb index 30594ce..c8e445e 100644 --- a/features/support/factories.rb +++ b/features/support/factories.rb @@ -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 diff --git a/lib/factory_girl/step_definitions.rb b/lib/factory_girl/step_definitions.rb index c2a876d..620d6a9 100644 --- a/lib/factory_girl/step_definitions.rb +++ b/lib/factory_girl/step_definitions.rb @@ -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