开发者

Rspec with acts_as_tree: Helper does not see children

开发者 https://www.devze.com 2023-02-11 15:58 出处:网络
Trying to write a test for a helper method that uses acts_as_tree开发者_开发知识库. Helper method uses a count for children:

Trying to write a test for a helper method that uses acts_as_tree开发者_开发知识库.

Helper method uses a count for children:

if category.children.size > 0

In my test, I'm creating a parent and child:

parent = Factory.create(:category)
child = Factory.create(:category, :parent_id => parent.id)

But in my test (and in my helper when run by the test), parent.child.size is 0

Is there some limitation that my helper spec can't use acts_as_tree? Can I include it somehow? Or should I be stubbing that somehow?

Thanks!


RSpec's stub_chain can deal with situations where you need to stub a chain of method calls on an object. The syntax is slightly different in helper specs vs. view specs:

# helper
helper.stub_chain(:category,:children,:size,:>).with(0) { true }

# view
view.stub_chain(:category,:children,:size,:>).with(0) { true }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号