由Capybara以不同于实际应用程序发送的Formtastic复选框参数

时间:2011-03-18 18:55:59

标签: ruby-on-rails cucumber capybara formtastic

以下formtastic表格复选框字段集:

<%= semantic_form_for @store do |f| %>
  <%= f.inputs do %>
    <%= f.input :services, :as => :check_boxes, :collection => Service.all %>  
  <% end -%>
<% end -%>

正在使用Capybara向Cucumber测试发送错误的参数:使测试失败,而实际的应用程序发送正确的应用程序,处理正常:

#cucumber steps using the boiler_plate capybara web_steps.rb:
Given a "Mail Order" service
...(steps for rest of the form)...
When I check "Mail Order" 
And I press "Create Store"
Then I should see "Store was successfully created."
And I should see "Mail Order"

#params sent by cucumber
"store"=>{"services"=>["[\"4d8247ed7f5bfd2275000004\"]"]

#params sent by app on manual test
"store"=>{"services"=>["4d8247ed7f5bfd2275000004"]}

虽然html表单本身在两种情况下都以相同的方式呈现:

<input id="store_services_4d8247ed7f5bfd2275000004" name="store[services][]" type="checkbox" value="4d8247ed7f5bfd2275000004" />

在请求参数构建期间的某处似乎,当Cucumber / Capybara提交时,该字段的表单键/值对会被不同地解析。

其他人遇到过这个?

1 个答案:

答案 0 :(得分:1)

回答我自己的问题:

得到了Capybara的作者Jonas Nicklas的指针,导致我this rack-test patch which hasn't been committed yet

现在我只是使用补丁所在的分叉和分支:

gem 'rack-test', :git => 'https://github.com/econsultancy/rack-test.git', :branch => 'econsultancy-20110119'

这就是诀窍。我想这个补丁很快就会合并,因为它是几个月前提交的。