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:
parent
ba6cfea5c7
commit
db6c46a101
3 changed files with 34 additions and 0 deletions
|
@ -8,6 +8,24 @@ Feature: Use step definitions generated by factories
|
||||||
| title | body |
|
| title | body |
|
||||||
| a fun title | here is the content |
|
| 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
|
Scenario: create several posts
|
||||||
Given the following posts exist:
|
Given the following posts exist:
|
||||||
| Title | Body |
|
| Title | Body |
|
||||||
|
|
|
@ -26,6 +26,9 @@ class Post < ActiveRecord::Base
|
||||||
belongs_to :author, :class_name => 'User'
|
belongs_to :author, :class_name => 'User'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class NonActiveRecord
|
||||||
|
end
|
||||||
|
|
||||||
Factory.define :user do |f|
|
Factory.define :user do |f|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,4 +36,8 @@ Factory.define :post do |f|
|
||||||
f.association :author, :factory => :user
|
f.association :author, :factory => :user
|
||||||
end
|
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'
|
require 'factory_girl/step_definitions'
|
||||||
|
|
|
@ -29,5 +29,14 @@ Factory.factories.values.each do |factory|
|
||||||
Factory.create(factory.factory_name, attributes)
|
Factory.create(factory.factory_name, attributes)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue