2
1

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 5 years have passed since last update.

rspec multipleなselect boxをテストする

2
Last updated at Posted at 2017-02-23

multipleなselect boxのテストはどうやるのかという話
例えばこんな複数選択可能なセレクトボックスがあったとして
複数選択についての検証をどうするか

= select_tag 'hoge_form', options_for_select(@form.selectables), multiple: true

セレクトボックス内の候補がちゃんと入っているかを検証したい場合は
have_selectの場合は配列で指定してあげればOK

given(:menu1) { 'ラーメン' }
given(:menu2) { 'カレー' }
scenario '選択の対象がセレクトボックス内にあること' do
  expect(page).to have_select('hoge_form', options: [menu1, menu2])
end

セレクトボックス内で複数の項目が選択されていることを検証する場合も
配列で指定してあげればチェックができる

scenario '選択されていること' do
  expect(page).to have_select('hoge_form', selected: [menu1, menu2])
end
2
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?