RSpec gives error 'trait not registered: name'

纵饮孤独 提交于 2019-12-05 00:01:03

I know this is an old question, but in case anyone else ends up here when searching "Trait not registered":

When using a dependent attribute like how email depends on name in the :club factory from the question, you need to wrap the attribute in curly braces so it gets lazy evaluated:

email {"#{name}@example.com"}

It's a FactoryGirl error, and it seems you're using (at spec/features/sign_in_spec.rb:11) something like :

FactoryGirl.create :user, :name

This will only work if you registered a trait called name for the Factory user, more on traits here

Note that if you just want to override the name of the created user, the syntax is

FactoryGirl.create :user, name: 'THE NAME'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!