【问题标题】:Why Does FactoryGirl Generate Factories in the 'test' Directory When I'm Using RSpec?为什么我使用 RSpec 时 FactoryGirl 会在“测试”目录中生成工厂?
【发布时间】:2014-08-12 02:06:24
【问题描述】:

当我使用以下方法生成模型时:

$ rails g model example

Rails 为模型生成一个工厂。目前它将工厂添加到test/factories,但是我需要它将工厂添加到spec/factories

我正在使用 RSpec,其他所有内容都生成到 spec/…

【问题讨论】:

  • 该命令行为我将工厂置于规范/工厂中。想知道有什么不同吗?可能有助于显示您的 Gemfile。
  • @DaveSchweisguth 好蜘蛛侠的感觉。当它应该在 :development, :test 中时,我会将它放在 :test 组中。如果您将其放在答案中,我将标记为正确。或者我可以做到。
  • 我不能写那个答案,因为如果 rspec-rails 仅在测试中 rails g model 根本不会生成工厂。您的 :development 小组中的成员可能比我多。

标签: ruby-on-rails ruby-on-rails-4 rspec generator factory-bot


【解决方案1】:

通常,这些文件的最终位置由文件 config/application.rb 中的指令确定:

class Application < Rails::Application
  config.generators do |g|
    ...

    g.fixture_replacement :factory_girl, dir: 'spec/factories'

    ...
  end

...

【讨论】:

  • 很好,不知道你可以在那里传递目录。
猜你喜欢
  • 1970-01-01
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多