Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active September 14, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/a585c8015b1272f49d11 to your computer and use it in GitHub Desktop.
Save YumaInaura/a585c8015b1272f49d11 to your computer and use it in GitHub Desktop.
Capybara + rspec で selected の状態を判定する : Rails ref: http://qiita.com/Yinaura/items/b9fb268142f4d75f84c8
expect(page).to have_select('book[id]', selected: 'ソフィーの世界')
<select id="book" name="book[id]">
<option>我輩は猫である</option>
<option>ソフィーの世界</option>
<option>ガリバー旅行記</option>
</select>
require 'spec_helper'
feature '/books', type: :feature do
before do
visit book_path
select 'ソフィーの世界', from: 'book[id]' #いちど選択状態にする
end
scenario "要素が選択状態になっている" do
expect(page).to have_select('book[id]', selected: 'ソフィーの世界') # 選択状態を判定する
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment