@Mike Mazurの回答で注意すべき点は、コントローラーが#destroy
アクションでリダイレクトを実行した場合、Capybaraのドライバーでdeleteメソッドを呼び出しても、実際にはリダイレクトに従わないことです。代わりにresponse
、リダイレクトメッセージ、つまりbody == <html><body>You are being <a href=\"http://www.example.com/model_names\">redirected</a>.</body></html>
とを入力するだけstatus_code == 302
です。
したがって、通常のカピバラで期待するようにすべてを入力するにclick_button 'Delete Model'
は、リダイレクトを手動でたどる必要があります。これを行う1つの(リファクタリングされていないRSpecフレーバーの)方法:
Capybara.current_session.driver.delete controller_path(model_instance)
Capybara.current_session.driver.response.should be_redirect
visit Capybara.current_session.driver.response.location