CristiAllan CristiAllan - 6 months ago 47
Ruby Question

Factory not registered error

I'm having a problem with Factory Girl gem:

With the lines in my spec_helper.rb code:

require 'factory_girl_rails'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end


I have the error:

ArgumentError:
Factory not registered: products


Ps: the file
spec/factories/products.rb
already exists

If I comment these lines, the error changes to:

NoMethodError: undefined method `create_list'


The method create_list I used in my file
products_controller_spec.rb
:

describe "GET #index" do
let(:my_products){ create_list(:products, 10) }


spec/factories/products.rb

FactoryGirl.define do
factory :product do
name "MyString"
description "MyString"
price "10.5"
maker "MyString"
end
end


What I'm doing wrong here?

Answer

The factory name is product. Try:

let(:my_products) { create_list(:product, 10) }

Comments