1
我對this excellent Rails tutorial最後一章,我已經臨到這個代碼:有沒有辦法縮短這個RSpec示例來停止代碼重複?
describe "creating a relationship with Ajax" do
it "should increment the Relationship count" do
expect do
xhr :post, :create, relationship: { followed_id: other_user.id }
end.to change(Relationship, :count).by(1)
end
it "should respond with success" do
xhr :post, :create, relationship: { followed_id: other_user.id }
response.should be_success
end
end
我想知道是否有任何辦法可以阻止重複,類似下面的代碼(這不會工作,因爲它只會創建2個測試)?
it "should increment relationships count" do
expect do
xhr :post, :create, relationship: { followed_id: other_user.id }
response.should be_success
end.to change(Relationship, :count).by(1)
end
現在看看它,我覺得我只是尷尬!想要仔細檢查一下。謝謝! –