1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00
thoughtbot--factory_bot_rails/features/generators.feature
yuuji.yaginuma e6509920a6 Use compatible sqlite3 version in test application
Currently, the `sqlite3` in `Gemfile` generated by `rails new` is not
compatible with Rails.

To solve this issue, modified it to use compatible `sqlite3` using
template.
Ref: https://github.com/rails/rails/issues/35161
2019-02-06 09:18:41 -05:00

68 lines
2.6 KiB
Gherkin

Feature:
In order to easily generate factory files instead of fixture files when generating models
As a user of Rails and Factory Bot
I would like to use factory_bot_rails generators.
Background:
Given I successfully run `bundle exec rails new testapp -m ../../features/support/rails_template`
And I cd to "testapp"
And I add "factory_bot_rails" from this project as a dependency
And I run `bundle install` with a clean environment
Scenario: The factory_bot_rails generators create a factory file for each model if there is not a factories.rb file
When I run `bundle exec rails generate model User name:string age:integer` with a clean environment
And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment
Then the output should contain "test/factories/users.rb"
And the output should contain "test/factories/namespaced/users.rb"
And the file "test/factories/users.rb" should contain exactly:
"""
FactoryBot.define do
factory :user do
name { "MyString" }
age { 1 }
end
end
"""
And the file "test/factories/namespaced/users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do"
Scenario: The factory_bot_rails generators add a factory in the correct spot
When I write to "test/factories.rb" with:
"""
FactoryBot.define do
end
"""
And I run `bundle exec rails generate model User name:string` with a clean environment
And I run `bundle exec rails generate model Robot name:string` with a clean environment
Then the file "test/factories.rb" should contain exactly:
"""
FactoryBot.define do
factory :robot do
name { "MyString" }
end
factory :user do
name { "MyString" }
end
end
"""
Scenario: The factory_bot_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory
When I write to "test/factories.rb" with:
"""
FactoryBot.define do
end
"""
And I run `bundle exec rails generate model User name:string` with a clean environment
Then the file "test/factories/users.rb" should not contain "factory :user do"
Scenario: The factory_bot_rails generators use a custom template
When I write to "lib/templates/factory_bot/model/factories.erb" with:
"""
<%= "Custom factory definition" %>
"""
And I run `bundle exec rails generate model User` with a clean environment
Then the file "test/factories/users.rb" should contain exactly:
"""
Custom factory definition
"""