例えば、ページ内に
あいうえお
単語
かきくけこ
単語
とあった場合、capybaraで
expect(page).to have_content('単語')
とした場合、マッチしますがこの'単語'の数をテストすることは可能でしょうか?
自分の場合、ひとつの'単語'のみ含まれていてほしいというようにしたいです。
スタック・オーバーフローはプログラマーとプログラミングに熱心な人のためのQ&Aサイトです。すぐ登録できます。
登録してこのコミュニティに参加するexpect(page).to have_content('単語', count: 1)
でいかがでしょうか?
have_xxx には引数が渡せるようです。
capybara/matchers.rb at master · jnicklas/capybara
下記に一部を抜粋します。
# @option options [Integer] :count (nil) Number of times the text is expected to occur
# @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur
# @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur
# @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs