diff --git a/features/factory_girl_steps.feature b/features/factory_girl_steps.feature index d849ad6..39f55b5 100644 --- a/features/factory_girl_steps.feature +++ b/features/factory_girl_steps.feature @@ -8,6 +8,24 @@ Feature: Use step definitions generated by factories | title | body | | a fun title | here is the content | + Scenario: create a post without a table and verify its attributes + Given a post exists with a title of "a fun title" + Then I should find the following for the last post: + | title | + | a fun title | + + Scenario: flexible English when creating posts + Given an post exists with an title of "a fun title" + Then I should find the following for the last post: + | title | + | a fun title | + + Scenario: create a post with an underscore in an attribute name + Given a post exists with an author ID of "5" + Then I should find the following for the last post: + | author_id | + | 5 | + Scenario: create several posts Given the following posts exist: | Title | Body | diff --git a/features/support/factories.rb b/features/support/factories.rb index da38f89..30594ce 100644 --- a/features/support/factories.rb +++ b/features/support/factories.rb @@ -26,6 +26,9 @@ class Post < ActiveRecord::Base belongs_to :author, :class_name => 'User' end +class NonActiveRecord +end + Factory.define :user do |f| end @@ -33,4 +36,8 @@ Factory.define :post do |f| f.association :author, :factory => :user end +# This is here to ensure that factory step definitions don't raise for a non-AR factory +Factory.define :non_active_record do |f| +end + require 'factory_girl/step_definitions' diff --git a/lib/factory_girl/step_definitions.rb b/lib/factory_girl/step_definitions.rb index b04e1bf..72a82b1 100644 --- a/lib/factory_girl/step_definitions.rb +++ b/lib/factory_girl/step_definitions.rb @@ -29,5 +29,14 @@ Factory.factories.values.each do |factory| Factory.create(factory.factory_name, attributes) end 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 + end + end end