我有许多可以正常工作的活动记录验证,例如:代码:belongs_to :topics
测试:it { should belong_to :topic }
但是我有一个 active_hash 关联和一个像这样的测试:
代码: belongs_to_active_hash :day
测试: pending { should belong_to_active_hash :day }
但测试失败:
未定义的方法if' for #<Shoulda::Matchers
...
我有许多可以正常工作的活动记录验证,例如:代码:belongs_to :topics
测试:it { should belong_to :topic }
但是我有一个 active_hash 关联和一个像这样的测试:
代码: belongs_to_active_hash :day
测试: pending { should belong_to_active_hash :day }
但测试失败:
未定义的方法if' for #<Shoulda::Matchers
...
应该不支持 ActiveHash 匹配器。您可以手动测试:
specify do
reflection = YourModel.reflect_on_association(:day)
options = {} # options you passed to belongs_to_active_hash
reflection.should_not be_nil
reflection.macro.should eq :belongs_to
reflection.options.should eq options
end
如果你经常使用它,你可以创建一个自定义匹配器。