LoginSignup
0

More than 5 years have passed since last update.

Capybaraのfeature specでraise_errorでテストしたらinternal server error

Last updated at Posted at 2017-10-31

この記事について

表題の通り

状況

1.Railsを使っている
2.context 'ほにゃらら', js: true doとjavascriptを動くようにした
3.Internal Server Errorが出る

こちらのコメントを見て、試しにjs: truejs: falseにしたら404とか拾ってくれた
https://stackoverflow.com/questions/15950677/where-do-i-see-the-reason-of-a-internal-server-error-when-running-rails-reques#comment22731368_15950677

context 'かくかくしかじか', js: true do
  scenario 'あれこれそれこれ' do
    # javascript使ったテスト
  end
  scenario 'ほげほげうまうま', js: false do
    expect do
      visit user_path(1_000_000) # 存在しないユーザ見に行くとか
    end.to raise_error(ActiveRecord::RecordNotFound)
  end
end

これで普通に拾えた
むしろみんなこのエラーにならないんだろうか?

追記

raise_error以外に、js: falseした方がいい場面としてturbolinksが有効な時にファイルのダウンロードをテストする時もjavascriptは切る必要がある

click_on 'test.ppt'
# js: trueでturbolinksが有効だとtest.pptがダウンロードされるのを待たずに次へ行く
expect(page.response_headers['Content-Type']).to eq('application/vnd.ms-powerpoint')

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
0