2013-08-27 59 views
0

我在我的specs中使用了shoulda_matchers。对于此测试未定义的方法`columns_hash'

it { should validate_uniqueness_of(:name).scoped_to(:role_id) } 

我得到这个错误:

Expected errors to include "has already been taken" when name is set to "arbitrary_string", got errors: ["name is already taken (\"arbitrary_string\")"] 

当我改变了测试:

it { should validate_uniqueness_of(:name).scoped_to(:role_id).with_message('is already taken') } 

我收到此错误:

NoMethodError: 
     undefined method `columns_hash' for Activity:Class 

我型号只有一个字段 - name

回答

2

Mongoid模型没有columns_hash类方法和shoulda-matchers使用此方法。

mongoid相应的方法是columns

我能够通过更换宝石shouldashoulda-matchersmongoid-rspec来解决这个问题。

+0

如果你有一个使用ActiveRecord和Mongoid的rails项目,该怎么办? – aag