2012-11-21 3 views
1

는 예를 고려 초기화되지 않습니다 : 내 RSpec에 테스트 만 :section 공장을 볼 수 있다는 것을 발견FactoryGirl는 공장

*# spec/factory/sections.rb* 

FactoryGirl.define do 

    factory :any_section do 
     (...) 
    end 


    factory :fake_section do 
     (...) 
    end 


    factory :section do 
     (...) 
    end 
end 

. 다른 모든 사람들은 마치 uninitialized constant FakeSection과 같은 오류를 던집니다.

왜 그럴까요?

답변

0

(즉 any_sectionAnySection이되고 fake_sectionFakeSection된다) 문제는 당신이 자신의 클래스를 지정하지 않는 것입니다, FactoryGirl가 any_sectionfake_section 공장이 표시되지 않는 일이 아니고, 따라서 이름을 추측된다.

문제가 단지 class 옵션을 사용하여 클래스는 Section로 지정 해결하려면 :

factory :any_section, :class => Section do 
    (...) 
end 


factory :fake_section, :class => Section do 
    (...) 
end 

this article를 참조하십시오.

+0

고맙습니다! –