FactoryGirl trouble
Asked Answered
D

1

6

I have a class that is defined in the module.

module Mod
  class Zed
   include DataMapper::Resource
  end
end

For testing, I define factory.

#/factories/zed.rb
FactoryGirl.define do
  factory :zed do
   #code 
  end
end

But when I start testing I get an error.

describe 'Zed' do
  it "should have ..." do
    FactoryGirl.create(:zed)
  end
end

Error:

 Failure/Error: FactoryGirl.create(:zed)
 NameError:
   uninitialized constant Zed

How to test a class that is included in the module? Thanks.

Disenable answered 27/7, 2012 at 8:23 Comment(0)
H
11

You should specify class when defining a factory like this:

FactoryGirl.define do
  factory :zed, class: Mod::Zed do
   #code 
  end
end
Hedda answered 27/7, 2012 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.