3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【結合テストコード】date_selectから要素を選択する方法

Last updated at Posted at 2020-10-21

簡単な結合テストコードを書いていてドツボにハマったので備忘録的に残しておきます。間違っていたらご指摘頂けると幸いです。

<%= raw sprintf(
    form.date_select(
      :birthday,
      class:'select-birth',
      id:"birth-date",
      use_month_numbers: true,
      prompt:'--',
      start_year: 1930,
      end_year: (Time.now.year - 5),
      date_separator: '%s'),
    "<p> 年 </p>", "<p> 月 </p>") + "<p> 日 </p>" %>

このような年、月、日を選択するフォームで思うように要素を選択できかったので悩んでいたのですが、以下の記事が参考になりました。

使えるRSpec入門・その4「どんなブラウザ操作も自由自在!逆引きCapybara大辞典」

結論としてはブラウザで検証を行い指定したい要素をチェックすると、きちんと1つずつname属性が割り当てられていたので、そのまま記述し

select '1930',from: 'dear_person[birthday(1i)]'
  select '12',from: 'dear_person[birthday(2i)]'
  select '12',from: 'dear_person[birthday(3i)]'

こちらで無事パスしました。
完全に私のミスです。

3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?