私はこの優れた 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