0

Acts_as_treeを使用するヘルパーメソッドのテストを作成しようとしています。

ヘルパーメソッドは、子のカウントを使用します。

if category.children.size > 0

私のテストでは、親と子を作成しています。

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

しかし、私のテスト(およびテストで実行されたときのヘルパー)では、parent.child.sizeは0です。

ヘルパー仕様でacts_as_treeを使用できないという制限はありますか?どういうわけか含めることはできますか?それとも、どういうわけかそれをスタブする必要がありますか?

ありがとう!

4

1 に答える 1

1

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 }
于 2011-02-16T23:14:10.223 に答える