テストメソッドで for ループを実行しても (概念的に) 大丈夫ですか?
さまざまな入力が正しい値を返すかどうかを判断するために、さまざまなパラメーター値をコントローラーにテストしたいと思います。
test "logged in user - add something - 0 qty" do
@app = Factory.create(:app)
(0..5).each do |t|
@qty = t
login(:user)
get :add. :id => @app.id, :qty => @qty
assert_nil(flash[:error])
assert_response :redirect
assert_redirect_to :controller => :apps, :action => :show, :id => @app.id
if @qty = 0
assert_equal(Invite.all.count, @qty + 1)
else
assert_something .........
end
end
そんな感じ。