1

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

1 に答える 1

1

これは DRY の問題ではありません。増分テストと成功応答を分離する必要があります

于 2013-01-13T14:47:53.423 に答える