我正在this excellent Rails tutorial的最后一章,我已经看到了这段代码:
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
答案 0 :(得分:1)
这不是干旱问题。你应该分开递增测试&成功回应