참고 : 비즈니스에는 많은 카탈로그가 있고 제품이 있고 카탈로그에는 많은 제품이 있습니다. 연결은 제대로 정의되어 있으며 애플리케이션 프런트 엔드에서 작업하고 있습니다. 하지만이 시험을 통과 할 수는 없습니다.Rails 팩토리 소녀 RSpec 중첩 된 리소스의 다수 관계 테스트
describe "GET 'show'" do
before do
@business = FactoryGirl.create(:business)
@catalog = FactoryGirl.create(:catalog, :business=>@business)
@product1 = FactoryGirl.create(:product, :business=>@business, :catalog=>@catalog)
@product2 = FactoryGirl.create(:product, :business=>@business, :catalog=>@catalog)
end
def do_show
get :show, :business_id=>@business.slug, :id=>@catalog.slug
end
it "should show products" do
@catalog.should_receive(:products).and_return([@product1, @product2])
do_show
end
end
을이 공장 (비즈니스 및 카탈로그 공장이 있습니다 : 당신은 내가이 시험을 시도하고
찾기 방법 중 일부에 @를 model.slug를 사용하여 저를 볼 수 있도록 내가 friendly_id를 사용하고) 다른 곳에서 정의하고 그들이 협회입니다
FactoryGirl.define do
sequence :name do |n|
"product#{n}"
end
sequence :description do |n|
"This is description #{n}"
end
factory :product do
name
description
business
catalog
end
end
을이 쇼의 조치 :
def show
@business = Business.find(params[:business_id])
@catalog = @business.catalogs.find(params[:id])
@products = @catalog.products.all
respond_with(@business, @catalog)
end
CatalogsController GET 'show' should show products
Failure/Error: @catalog.should_receive(:products).and_return([@product1, @product2])
(#<Catalog:0x000001016185d0>).products(any args)
expected: 1 time
received: 0 times
# ./spec/controllers/catalogs_controller_spec.rb:36:in `block (3 levels) in <top (required)>'
또한,이 코드 블록은 또한 비즈니스 모델을 찾기 방법을받지 못한 것으로 표시됩니다 : 123,414,하지만이 오류를 얻고있다
Business.should_receive(:find).with(@business.slug).and_return(@business)
어떤 오류 :
체크 아웃 여기 any_instance.should_receive에 RSpec에 문서
에 Business.should_receive, 같은 예상 된 1 시간, 0 번 받았습니다? –