我正在使用Capybara 1.1.2对Ruby on Rails 3.0.11进行验收测试,并尝试在表单中选择两个复选框。
以下是复选框的视图代码(使用haml 3.1.3和simple_form 2.0.4):
= f.input :countries,
:collection => MusicTeaser.teaser_countries,
:as => :check_boxes
该集合如下所示:
[["AT", "at"], ["CH", "ch"], ["DE", "de"], ["ZA", "za"]]
生成的HTML:
<div class="input check_boxes optional">
<label class="check_boxes optional control-label">Countries</label>
<label class="checkbox">
<input class="check_boxes optional" id="music_teaser_countries_at" name="music_teaser[countries][]" type="checkbox" value="at">AT
</label>
<label class="checkbox">
<input class="check_boxes optional" id="music_teaser_countries_ch" name="music_teaser[countries][]" type="checkbox" value="ch">CH
</label>
<label class="checkbox">
<input class="check_boxes optional" id="music_teaser_countries_de" name="music_teaser[countries][]" type="checkbox" value="de" checked="">DE
</label>
<label class="checkbox">
<input class="check_boxes optional" id="music_teaser_countries_za" name="music_teaser[countries][]" type="checkbox" value="za">ZA
</label>
<input name="music_teaser[countries][]" type="hidden" value="">
</div>
选择它们的代码看起来像这样(非常简单):
check 'music_teaser_countries_de'
check 'music_teaser_countries_za'
我预计,在提交时,countries
param将如下所示:
params[:music_teaser][:countries] = ["de", "za"]
但它看起来像这样:
params[:music_teaser][:countries] = ["deza"]
因此,当选择多个复选框时,似乎Capybara做错了。想法?