File: fixture_replacement_config.feature

package info (click to toggle)
ruby-factory-bot-rails 6.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ruby: 635; makefile: 6; sh: 4
file content (131 lines) | stat: -rw-r--r-- 5,936 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Feature:
  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.

  Background:
    Given I create a new rails application
    And I add "factory_bot_rails" from this project as a dependency

  Scenario: Using Factory Bot and Factory Bot Rails with Test Unit generates a factory file and does not generate a fixture file
    And I run `bundle install --verbose` 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:
      | test/factories/users.rb |
    And the following files should not exist:
      | test/fixtures/users.yml |

  Scenario: Using Factory Bot and Factory Bot Rails with RSpec should generate a factory file
    When I add "rspec-rails" as a dependency
    And I configure the factories as:
      """
      config.generators do |g|
        g.test_framework :rspec, fixture: true
        g.fixture_replacement :factory_bot
      end
      """
    And I run `bundle install --verbose` 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.rb |
    And the following files should not exist:
      | spec/fixtures/users.yml |

  Scenario: Using Factory Bot and Factory Bot Rails with RSpec and suffix configuration should generate a factory file with suffix
    When I add "rspec-rails" as a dependency
    And I configure the factories as:
      """
      config.generators do |g|
        g.test_framework :rspec, fixture: true
        g.fixture_replacement :factory_bot, suffix: 'factory'
      end
      """
    And I run `bundle install --verbose` 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 |
    And the following files should not exist:
      | spec/fixtures/users.yml |

  Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using RSpec
    When I add "rspec-rails" as a dependency
    And I configure the factories directory as "custom/dir"
    And I run `bundle install --verbose` 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 not exist:
      | test/factories/users.rb |
      | spec/factories/users.rb |
    But the following files should exist:
      | custom/dir/users.rb |

  Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using Test::Unit
    When I configure the factories directory as "custom/dir"
    And I run `bundle install --verbose` 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 |
    But the following files should exist:
      | custom/dir/users.rb |

  Scenario: Using Factory Bot Rails with MiniTest should generate a factory file
    When I run `bundle install --verbose` 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:
      | test/factories/users.rb |
    But the following files should not exist:
      | spec/fixtures/users.yml |

  Scenario: Using Factory Bot Rails with MiniTest and a custom directory should generate a factory file
    When I configure the factories directory as "custom/dir"
    And I run `bundle install --verbose` 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:
      | custom/dir/users.rb |
    But the following files should not exist:
      | spec/fixtures/users.yml |

  Scenario: Disable Factory Bot generator
    When I configure the factories as:
      """
      config.generators do |g|
        g.factory_bot false
      end
      """
    And I run `bundle install --verbose` 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 |

  Scenario: Use a suffix with the Factory Bot generator
    When I add "rspec-rails" as a dependency
    When I configure the factories as:
      """
      config.generators do |g|
        g.factory_bot suffix: 'suffix'
      end
      """
    And I run `bundle install --verbose` 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 |

  Scenario: Use a filename_proc with the Factory Bot generator
    When I add "rspec-rails" as a dependency
    When I configure the factories as:
      """
      config.generators do |g|
        g.factory_bot filename_proc: Proc.new { |tb| "prefix_#{tb.singularize}_suffix" }
      end
      """
    And I run `bundle install --verbose` 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 |