SinatraベースのAPI用の一連のRSpecテストがあります。それらをリファクタリングして、少し単純にし、繰り返しを減らしたいと思います。
ルートのテストの例を次に示します。
describe 'post /sections with empty data' do
before do
params = {
:site_id => site.id,
:page_id => page.id,
}
post '/sections', params, @session
end
specify { last_response.status.should == 200 }
specify { json_response['id'].should_not be_nil }
specify { json_response['type'].should == default_section_type }
end
各テストは同じベースURLを使用し、同じセッションデータを使用します。唯一の違いは、パラメーターと応答の内容です。ルートごとに少なくとも4つのテスト(GET、POST、PUT、DELETE)があり、通常はそれ以上です。
これらのテストをより管理しやすくする方法はありますか?