Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带acts_as_树的Rspec:助手看不到子级_Ruby On Rails_Rspec_Acts As Tree - Fatal编程技术网

Ruby on rails 带acts_as_树的Rspec:助手看不到子级

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_

尝试为使用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 }