Capybara 发送的 Formtastic 复选框参数与实际应用程序发送的格式不同
以下格式表单复选框字段集:
<%= semantic_form_for @store do |f| %>
<%= f.inputs do %>
<%= f.input :services, :as => :check_boxes, :collection => Service.all %>
<% end -%>
<% end -%>
在使用 Capybara 的 Cucumber 测试上为 :services 发送错误参数,导致测试失败,而实际应用程序发送正确的参数,处理得很好:
#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 提交时,该字段的表单键/值对的解析方式有所不同。
还有其他人遇到过这个吗?
The following formtastic form checkbox field set:
<%= semantic_form_for @store do |f| %>
<%= f.inputs do %>
<%= f.input :services, :as => :check_boxes, :collection => Service.all %>
<% end -%>
<% end -%>
is sending bad params for :services on a Cucumber test using Capybara, making the test fail, while the actual app sends the correct ones, which gets processed fine:
#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"]}
Though the html form itself is rendered the same way in both cases:
<input id="store_services_4d8247ed7f5bfd2275000004" name="store[services][]" type="checkbox" value="4d8247ed7f5bfd2275000004" />
Seems like somewhere during the request params-building, the form key/value pairs for that field get parsed differently when submitted by Cucumber/Capybara.
Anyone else come across this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答我自己的问题:
从 Capybara 的作者 Jonas Nicklas 那里得到了一个指针,它引导我到 这个机架- 尚未提交的测试补丁
现在我只是使用补丁所在的分支和分支:
这就可以了。我想这个补丁很快就会被合并,因为它是几个月前提交的。
Answering my own question:
Got a pointer from Capybara's author, Jonas Nicklas, that led me to this rack-test patch which hasn't been committed yet
For now I'm just using the fork and branch where the patch lives:
And that does the trick. I imagine this patch will be merged in very soon though, as it was submitted a couple of months ago.