Ruby on rails 带acts_as_树的Rspec:助手看不到子级
尝试为使用acts_as_树的助手方法编写测试 助手方法使用子对象的计数:Ruby on rails 带acts_as_树的Rspec:助手看不到子级,ruby-on-rails,rspec,acts-as-tree,Ruby On Rails,Rspec,Acts As Tree,尝试为使用acts_as_树的助手方法编写测试 助手方法使用子对象的计数: if category.children.size > 0 在我的测试中,我创建了一个父级和子级: parent = Factory.create(:category) child = Factory.create(:category, :parent_id => parent.id) 但在我的测试中(以及由测试运行时在助手中),parent.child.size为0 我的助手规范不能使用acts_as_
if category.children.size > 0
在我的测试中,我创建了一个父级和子级:
parent = Factory.create(:category)
child = Factory.create(:category, :parent_id => parent.id)
但在我的测试中(以及由测试运行时在助手中),parent.child.size为0
我的助手规范不能使用acts_as_树有什么限制吗?我能把它包括在内吗?还是我应该用某种方式来阻止它
谢谢 RSpec的
stub\u chain
可以处理需要在对象上存根方法调用链的情况。助手规范与视图规范的语法略有不同:
# helper
helper.stub_chain(:category,:children,:size,:>).with(0) { true }
# view
view.stub_chain(:category,:children,:size,:>).with(0) { true }