0
我想刪除每行主題,它使我的天賦太冗長,有什麼方法可以從rspec代碼的每一行中刪除主題?
我的模型具有下面的代碼: -
形容「#clone_for_resubmit」做
let(:new_item) { @order_item1.clone_for_resubmit(:cart_group => @cart_group, :cloned_collections => { }, :order => @cart_group.order, :message => "this is just for testing purpose", :receiver => "[email protected]", :sender =>"[email protected]") }
subject{ new_item}
it "should clone an order_item" do
gift = FactoryGirl.create(:gift, :order_item_id => @order_item1.id, :user => @user)
subject.cart_group.should == @cart_group
subject.collection.name.should == @order_item1.collection.name
subject.collection.book.title.should == @order_item1.collection.book.title
subject.collection.user.should == @order_item1.collection.user
subject.collection.book.book_chapters.count.should == @order_item1.collection.book.book_chapters.count
subject.collection.book.book_chapters.last.chapter_title.should == @order_item1.collection.book.book_chapters.last.chapter_title
subject.collection.items.last.user_recipe.recipe.name.should == @order_item1.collection.items.last.user_recipe.recipe.name
subject.collection.book.book_chapters.last.items.last.user_recipe.recipe.name.should == @order_item1.collection.book.book_chapters.last.items.last.user_recipe.recipe.name
subject.gift.recipient_email.should == gift.recipient_email
subject.gift.message.should == "this is just for testing purpose"
subject.gift.receiver.should == "[email protected]"
subject.gift.sender.should == "[email protected]"
subject.payment.payment_amount.should == @order_item1.payment.payment_amount
subject.payment.order.should == @cart_group.order
end
末
嘿感謝您的回覆,有沒有辦法從每個塊中刪除@new_item?在「主題」的幫助下,我猜測再次在每個塊中編寫主題將使其變得冗長,應該怎樣寫這種規格而不重複變量/主題的最短路徑 –
'主題'需要一個參數讓您指定一個名稱,而不是'主題' - 所以你可以有像'subject(:item){new_item}; ..... item.cart_group.should == @cart_group ...#etc'。但是請記住,「最短的路」往往不是最可讀的方式! – omnikron
oww謝謝你這麼多omnikron的幫助:)這是我想知道的 –