私はrspecとdrapergemを使用していますhttps://github.com/jcasimir/draper
私のコントローラーでは、それは単純なアクションショーです
def show
@category = Category.find(params[:id])
@products = ProductDecorator.decorate(@category.products)
end
とテスト
describe "#show" do
before { @category = Factory :category }
before do
@product1 = Factory :product, category: @category
@product2 = Factory :product, category: @category
end
before { get :show, id: @category.id }
it { should respond_with :success }
it { assigns(:products).should eq [@product1, @product2] }
end
プロジェクトではすべて正常に動作し、製品は正常に表示されますが、テストではそのようなエラーが発生します
Failure/Error: it { assigns(:products).should eq [@product1, @product2] }
expected: [#<Product ... >, #<Product ...>]
got: nil
(compared using ==)
また、ProductDecorator.decorate(@ category.products)を@ category.productsだけに置き換えても、エラーは発生しません
@productsを調べたら
def show
@category = Category.find(params[:id])
@products = ProductDecorator.decorate(@category.products)
puts @products.inspect
end
取得しました
#<DecoratedEnumerableProxy of ProductDecorator for [#<Product ...>, #<Product ...>]>
助言がありますか?