LoginSignup
0
1

More than 1 year has passed since last update.

rspec date_field の値のテストが出来ない

Posted at

rspec のテストのとき date_field のフォームうまくテストできなかった

開発環境

ruby 2.6.5
Ruby on Rails 5.2.5
rspec-rails (5.0.2)

本題

rspecのスクリプト
fill_in "task[deadline]", with: "2019-11-11"
expect(page).to have_content "2019-11-11"

日付の入力欄に date_field を使っている箇所があるんだけど
そこのテストが上のコードでは上手くが出来ない

細かく見てみると

"2019-11-11"

と入力している部分がエラー時には

201911-11- 

と入力されてしまっている

調べたら

上の記事で同じような質問があった

再度

fill_in "task[deadline]", with: "002019-11-11"

と書き直す

確認の項目も

expect(page).to have_content "2019-11-11"

と変更

再度テスト
しかし再びエラー

エラーメッセージは

 expected to find text "002019-11-11" in "Task was successfully created

どうやら 002019-11-11 と入力しても
内部的にはそうなっていないみたいなので

 expect(page).to have_content "2019-11-11"

と書き直す

するとうまくいった

0
1
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
0
1