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

Added alternate formatting for step definitions

This commit is contained in:
Joe Ferris 2009-09-15 17:58:23 -04:00
parent ba6cfea5c7
commit db6c46a101
3 changed files with 34 additions and 0 deletions

View file

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

View file

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

View file

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