2011-09-08 12:30:26 -04:00
|
|
|
Feature:
|
2016-12-02 10:25:09 -05:00
|
|
|
In order to not have to manually configure Factory Bot as the Rails testing fixture replacement by using the --fixture-replacement=factory_bot option
|
|
|
|
I would like the Factory Bot Rails gem to configure Factory Bot as the fixture replacement.
|
2011-09-08 12:30:26 -04:00
|
|
|
|
|
|
|
Background:
|
2020-03-29 11:51:41 -04:00
|
|
|
Given I create a new rails application
|
2016-12-02 10:25:09 -05:00
|
|
|
And I add "factory_bot_rails" from this project as a dependency
|
2011-09-08 12:30:26 -04:00
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot and Factory Bot Rails with Test Unit generates a factory file and does not generate a fixture file
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2011-09-08 12:30:26 -04:00
|
|
|
Then the following files should exist:
|
|
|
|
| test/factories/users.rb |
|
|
|
|
And the following files should not exist:
|
|
|
|
| test/fixtures/users.yml |
|
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot and Factory Bot Rails with RSpec should generate a factory file
|
2012-12-19 14:46:21 -05:00
|
|
|
When I add "rspec-rails" as a dependency
|
2013-02-05 09:04:10 -05:00
|
|
|
And I configure the factories as:
|
|
|
|
"""
|
|
|
|
config.generators do |g|
|
|
|
|
g.test_framework :rspec, fixture: true
|
2016-12-02 10:25:09 -05:00
|
|
|
g.fixture_replacement :factory_bot
|
2013-02-05 09:04:10 -05:00
|
|
|
end
|
|
|
|
"""
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle install` with a clean environment
|
2012-12-20 11:54:27 -05:00
|
|
|
Then the output should contain "rspec-rails"
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2011-09-08 12:30:26 -04:00
|
|
|
Then the following files should exist:
|
|
|
|
| spec/factories/users.rb |
|
2015-02-26 19:36:06 -05:00
|
|
|
And the following files should not exist:
|
|
|
|
| spec/fixtures/users.yml |
|
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot and Factory Bot Rails with RSpec and suffix configuration should generate a factory file with suffix
|
2015-02-26 19:36:06 -05:00
|
|
|
When I add "rspec-rails" as a dependency
|
|
|
|
And I configure the factories as:
|
|
|
|
"""
|
|
|
|
config.generators do |g|
|
|
|
|
g.test_framework :rspec, fixture: true
|
2016-12-02 10:25:09 -05:00
|
|
|
g.fixture_replacement :factory_bot, suffix: 'factory'
|
2015-02-26 19:36:06 -05:00
|
|
|
end
|
|
|
|
"""
|
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
Then the output should contain "rspec-rails"
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
|
|
|
Then the following files should exist:
|
|
|
|
| spec/factories/users_factory.rb |
|
2011-09-08 12:30:26 -04:00
|
|
|
And the following files should not exist:
|
|
|
|
| spec/fixtures/users.yml |
|
2012-12-07 11:48:05 -05:00
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using RSpec
|
2012-12-07 11:48:05 -05:00
|
|
|
When I add "rspec-rails" as a dependency
|
|
|
|
And I configure the factories directory as "custom/dir"
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle install` with a clean environment
|
2012-12-20 11:54:27 -05:00
|
|
|
Then the output should contain "rspec-rails"
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2012-12-07 11:48:05 -05:00
|
|
|
Then the following files should not exist:
|
|
|
|
| test/factories/users.rb |
|
|
|
|
| spec/factories/users.rb |
|
|
|
|
But the following files should exist:
|
|
|
|
| custom/dir/users.rb |
|
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using Test::Unit
|
2012-12-10 11:29:57 -05:00
|
|
|
When I configure the factories directory as "custom/dir"
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2012-12-10 11:29:57 -05:00
|
|
|
Then the following files should not exist:
|
|
|
|
| test/factories/users.rb |
|
|
|
|
| spec/factories/users.rb |
|
|
|
|
But the following files should exist:
|
|
|
|
| custom/dir/users.rb |
|
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot Rails with MiniTest should generate a factory file
|
2014-05-26 23:39:51 -04:00
|
|
|
When I run `bundle install` with a clean environment
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2012-12-10 11:29:57 -05:00
|
|
|
Then the following files should exist:
|
|
|
|
| test/factories/users.rb |
|
|
|
|
But the following files should not exist:
|
|
|
|
| spec/fixtures/users.yml |
|
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Using Factory Bot Rails with MiniTest and a custom directory should generate a factory file
|
2012-12-10 11:29:57 -05:00
|
|
|
When I configure the factories directory as "custom/dir"
|
2012-12-21 11:08:37 -05:00
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
2012-12-10 11:29:57 -05:00
|
|
|
Then the following files should exist:
|
|
|
|
| custom/dir/users.rb |
|
|
|
|
But the following files should not exist:
|
|
|
|
| spec/fixtures/users.yml |
|
2013-03-08 15:36:00 -05:00
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Disable Factory Bot generator
|
2013-03-08 15:36:00 -05:00
|
|
|
When I configure the factories as:
|
|
|
|
"""
|
|
|
|
config.generators do |g|
|
2016-12-02 10:25:09 -05:00
|
|
|
g.factory_bot false
|
2013-03-08 15:36:00 -05:00
|
|
|
end
|
|
|
|
"""
|
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
|
|
|
Then the following files should not exist:
|
|
|
|
| test/factories/users.rb |
|
|
|
|
| spec/factories/users.rb |
|
2014-06-28 13:32:06 -04:00
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Use a suffix with the Factory Bot generator
|
2014-06-28 13:32:06 -04:00
|
|
|
When I add "rspec-rails" as a dependency
|
|
|
|
When I configure the factories as:
|
|
|
|
"""
|
|
|
|
config.generators do |g|
|
2016-12-02 10:25:09 -05:00
|
|
|
g.factory_bot suffix: 'suffix'
|
2014-06-28 13:32:06 -04:00
|
|
|
end
|
|
|
|
"""
|
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
|
|
|
Then the following files should exist:
|
|
|
|
| spec/factories/users_suffix.rb |
|
|
|
|
Then the following files should not exist:
|
|
|
|
| spec/factories/users.rb |
|
2014-09-02 10:08:54 -04:00
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
Scenario: Use a filename_proc with the Factory Bot generator
|
2014-09-02 10:08:54 -04:00
|
|
|
When I add "rspec-rails" as a dependency
|
|
|
|
When I configure the factories as:
|
|
|
|
"""
|
|
|
|
config.generators do |g|
|
2016-12-02 10:25:09 -05:00
|
|
|
g.factory_bot filename_proc: Proc.new { |tb| "prefix_#{tb.singularize}_suffix" }
|
2014-09-02 10:08:54 -04:00
|
|
|
end
|
|
|
|
"""
|
|
|
|
And I run `bundle install` with a clean environment
|
|
|
|
And I run `bundle exec rails generate model User name:string` with a clean environment
|
|
|
|
Then the following files should exist:
|
|
|
|
| spec/factories/prefix_user_suffix.rb |
|
|
|
|
Then the following files should not exist:
|
|
|
|
| spec/factories/users.rb |
|