我在这个优秀的 Rails 教程的最后一章,我遇到了这段代码:
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