2011-07-11 23:11:06 -04:00
|
|
|
Feature:
|
|
|
|
In order to easily generate factory files instead of fixture files when generating models
|
2014-05-26 23:39:51 -04:00
|
|
|
As a user of Rails and Factory Girl
|
2011-07-11 23:11:06 -04:00
|
|
|
I would like to use factory_girl_rails generators.
|
|
|
|
|
2012-12-19 14:46:21 -05:00
|
|
|
Background:
|
|
|
|
Given I successfully run `bundle exec rails new testapp`
|
2011-07-11 23:11:06 -04:00
|
|
|
And I cd to "testapp"
|
|
|
|
And I add "factory_girl_rails" from this project as a dependency
|
2012-12-19 14:46:21 -05:00
|
|
|
|
2014-07-25 19:10:08 -04:00
|
|
|
Scenario: The factory_girl_rails generators create a factory file for each model if there is not a factories.rb file
|
2012-12-21 11:08:37 -05:00
|
|
|
When I run `bundle install` with a clean environment
|
2014-10-30 08:58:52 -04:00
|
|
|
And I run `bundle exec rails generate model User name:string age:integer` with a clean environment
|
2014-08-07 19:15:39 -04:00
|
|
|
And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment
|
2012-02-26 13:58:48 -05:00
|
|
|
Then the output should contain "test/factories/users.rb"
|
|
|
|
And the output should contain "test/factories/namespaced_users.rb"
|
2014-10-30 08:58:52 -04:00
|
|
|
And the file "test/factories/users.rb" should contain exactly:
|
|
|
|
"""
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user do
|
|
|
|
name "MyString"
|
|
|
|
age 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
"""
|
2014-10-23 18:48:47 -04:00
|
|
|
And the file "test/factories/namespaced_users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do"
|
2012-11-29 05:46:29 -05:00
|
|
|
|
2015-03-14 21:59:59 -04:00
|
|
|
Scenario: The factory_girl_rails generators add a factory in the correct spot
|
|
|
|
When I run `bundle install` with a clean environment
|
|
|
|
And I write to "test/factories.rb" with:
|
|
|
|
"""
|
|
|
|
FactoryGirl.define do
|
|
|
|
end
|
|
|
|
"""
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
|
|
|
Then the file "test/factories.rb" should contain exactly:
|
|
|
|
"""
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user do
|
|
|
|
name "MyString"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
"""
|
|
|
|
|
2014-07-25 19:10:08 -04:00
|
|
|
Scenario: The factory_girl_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory
|
2012-12-21 11:08:37 -05:00
|
|
|
When I run `bundle install` with a clean environment
|
2014-07-25 19:10:08 -04:00
|
|
|
And I write to "test/factories.rb" with:
|
|
|
|
"""
|
|
|
|
FactoryGirl.define do
|
|
|
|
end
|
|
|
|
"""
|
2014-08-07 19:15:39 -04:00
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2014-07-25 19:10:08 -04:00
|
|
|
Then the file "test/factories.rb" should contain "factory :user do"
|