RSpec gives error 'trait not registered: name'

后端 未结 2 1877
北荒
北荒 2021-02-18 14:08

I tried to test my Rails 3 application on Windows with RSpec. I\'ve wrote tests and factories, but can\'t solve the issues which raise when I run RSpec on command line.

相关标签:
2条回答
  • 2021-02-18 14:22

    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"}
    
    0 讨论(0)
  • 2021-02-18 14:23

    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'
    
    0 讨论(0)
提交回复
热议问题