保険の申込など10画面ぐらいあるウィザード形式の申し込みフォームなどのテストをする時、セッションなどの情報を共有する時に使った方法。
肝はcontextは普通のclassなのでdefでメソッドが定義できるのでそこに共通処理をまとめる点。
context '発注する時' do
def step1
visit '/order/new'
end
def step1_input
fill_in 'name', with:"qiita"
fill_in 'address', with:"tokyo"
end
def step2
step1
step1_input
click_button 'next'
end
def step3
step2
click_button 'order'
end
it "オーダーページが表示される" do
step1
#...
end
it "注文が完了する" do
step3
#...
end
end