3
나는 그것이 모두가 잘 작동 프로젝트에서
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
간단한 액션 쇼
def show
@category = Category.find(params[:id])
@products = ProductDecorator.decorate(@category.products)
end
및 테스트의 내 컨트롤러에서 RSpec에와 드레이퍼 보석 https://github.com/jcasimir/draper
을 사용하고
및 제품이 정상적으로 표시되지만 테스트에서 이러한 오류가 발생합니다.
Failure/Error: it { assigns(:products).should eq [@product1, @product2] }
expected: [#<Product ... >, #<Product ...>]
got: nil
(compared using ==)
도 내가 함께 ProductDecorator.decorate (@ category.products를) 대체 할 경우 단지 category.products @ - 오류없이 내가
def show
@category = Category.find(params[:id])
@products = ProductDecorator.decorate(@category.products)
puts @products.inspect
end
이
#<DecoratedEnumerableProxy of ProductDecorator for [#<Product ...>, #<Product ...>]>
모든있어 @products을 검사하는 경우
제안?
예,이 방법을 사용해 보았습니다.하지만 제품 배열이나 'ProductDecorator의 DecoratedEnumerableProxy'와 nil을 비교하는 차이점은 무엇입니까? –