Question: Rails::Generator is not creating factory in spec folder

Question

Rails::Generator is not creating factory in spec folder

Answers 1
Added at 2017-01-02 20:01
Tags
Question

I am trying to generate a new factory inside a module and I basically required

require 'rails/generators'

and I am calling the command below. Notice that it creates the file inside the test folder.

Rails::Generators.invoke 'factory_girl:model', ["Audit"]

-- create_table("audit", {:id=>:integer})
   -> 0.0085s
      create  test/factories/audit.rb

When I try to generate the factory in the terminal, it creates the factory inside the spec folder:

vo@so:~/Desktop/ruby-pos/api$ rails generate factory_girl:model 'Audit'
      create  spec/factories/audits.rb

My problem is: I basically want to create the factory inside the spec folder when I run Rails::Generators.invoke 'factory_girl:model', ["Audit"].

I have been stuck in this problem for a few hours and that's why I am here :) Any ideas?

Answers
nr: #1 dodano: 2017-01-08 19:01

If you didn't specify directory for factories in your application.rb try to add this. Must help.

config.generators do |g|
  g.test_framework :rspec
  g.fixture_replacement :factory_girl, dir: 'spec/factories'
end
Source Show
◀ Wstecz