LoginSignup
20
14

More than 5 years have passed since last update.

エラーページが表示されることの Feature spec

Posted at

今までこんな感じに書いてました。

scenario '存在しないユーザーはエラー' do
  expect {
    visit '/users/99999'
  }.to raise_error(ActiveRecord::RecordNotFound)
end

Controller specならraise_errorでいいのですが、Feature specなのでこう書きたい。

scenario '存在しないユーザーはエラー' do
  visit '/users/99999'
  expect(page.status_code).to eq 404
  expect(page).to have_content('ページがありません。')
end

実はこう設定変更するだけでOKでした。

config/environments/test.rb
config.action_dispatch.show_exceptions = true
20
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
14